rs-dht-pio/src/dht.pio

38 lines
1.2 KiB
Text
Raw Normal View History

2023-09-09 19:41:19 +00:00
.define bit_to_recv 32
2023-09-08 21:09:15 +00:00
.program dht
; Clock must be set for 1µs per instruction
2023-09-09 20:21:55 +00:00
set pindirs, 1 ; set pin as output
set pins, 1 ; set pin to high
2023-09-08 21:09:15 +00:00
pull block ; Wait for start
set x, 31 ; set x register with 31 (for 31 * 32 µS)
set pins, 0 ; set pin to low
2023-10-10 20:02:35 +00:00
loop_init_low: ; wait 992 µs
2023-09-08 21:09:15 +00:00
jmp x-- loop_init_low [31]
2023-09-21 16:46:22 +00:00
set pins, 1 [19] ; set pin to high (for 20µS)
set pindirs, 0 ; set pin as input
2023-09-08 21:09:15 +00:00
wait 0 pin 0 ; Wait for low
wait 1 pin 0 ; wait for high
2023-09-09 19:41:19 +00:00
set y, 4 ; set the number of byte to receive - 1
init_loop_data:
set x, 7 ; Set number bit to receive - 1
2023-09-21 16:46:22 +00:00
loop_data:
2023-09-09 19:41:19 +00:00
wait 0 pin 0 ; Wait for low
wait 1 pin 0 ; wait for high
2023-09-21 16:46:22 +00:00
2023-09-09 19:41:19 +00:00
nop [29] ; wait for ~ 30 µS
2023-09-21 16:46:22 +00:00
nop [9] ; wait for ~ 10 µS
2023-09-09 19:41:19 +00:00
in pins, 1 ; read the pin state and store bit value
2023-09-21 16:46:22 +00:00
jmp x--, loop_data ; Loop while there are bits left to read
2023-09-09 19:41:19 +00:00
2023-09-21 16:46:22 +00:00
push iffull noblock ; Push data if full
2023-09-09 19:41:19 +00:00
jmp y--, init_loop_data
push ; Push the last bytes