en:pfw:dht22-rp2040-nofortht
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:pfw:dht22-rp2040-nofortht [2025-06-27 17:09] – willem | en:pfw:dht22-rp2040-nofortht [2025-06-29 13:25] (current) – willem | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| < | < | ||
| - | (* DHT22 sensor, using PIO: 480 bytes | + | (* DHT22 sensor, using PIO: 424 bytes |
| - | | + | |
| 40-bits pulse stream 32-bits data & 8-bits checksum | 40-bits pulse stream 32-bits data & 8-bits checksum | ||
| Line 15: | Line 15: | ||
| clean-pio | clean-pio | ||
| 0 0 {pio \ Use state machine-0 on PIO-0 | 0 0 {pio \ Use state machine-0 on PIO-0 | ||
| - | 160000 =freq \ On 4 * 40 kHz frequency (6.25 Ás ticks) | + | 160000 =freq \ On 4 * 40 kHz frequency (6.25 µs ticks) |
| 05 1 =out-pins | 05 1 =out-pins | ||
| 05 1 =set-pins | 05 1 =set-pins | ||
| Line 32: | Line 32: | ||
| 31 [] 0 pins set, | 31 [] 0 pins set, | ||
| y--? until, | y--? until, | ||
| - | 6 [] 1 pins set, \ 44 Ás start pulse high | + | 6 [] 1 pins set, \ 44 µs start pulse high |
| - | 6 [] 0 pindirs set, \ Now input, wait 44 Ás, skip response low | + | 6 [] 0 pindirs set, \ Now input, wait 44 µs, skip response low |
| - | 6 [] high 0 pin wait, \ Wait for response high 44 Ás | + | 6 [] high 0 pin wait, \ Wait for response high 44 µs |
| - | 31 y set, \ Now read the 32-bits answer 6.25 Ás | + | 31 y set, \ Now read the 32-bits answer 6.25 µs |
| begin, | begin, | ||
| low 0 pin wait, | low 0 pin wait, | ||
| - | 5 [] high 0 pin wait, \ Wait for high bit 37.5 Ás | + | 5 [] high 0 pin wait, \ Wait for high bit 37.5 µs |
| - | 1 pins in, \ Shift in low or high bit 6.25 Ás ( autopush | + | 1 pins in, \ Shift in low or high bit 6.25 µs (autopush) |
| - | y--? until, | + | y--? until, |
| - | 7 y set, \ Read 8-bit checksum 6.25 Ás | + | 7 y set, \ Read 8-bit checksum 6.25 µs |
| begin, | begin, | ||
| low 0 pin wait, | low 0 pin wait, | ||
| - | 5 [] high 0 pin wait, \ Wait for high bit 37.5 Ás | + | 5 [] high 0 pin wait, \ Wait for high bit 37.5 µs |
| - | 1 pins in, \ Shift in checksum bit 6.25 Ás | + | 1 pins in, \ Shift in checksum bit 6.25 µs |
| - | y--? until, | + | y--? until, |
| - | push, \ Result 8-bits to fifo 6.25 Ás | + | push, \ Result 8-bits to fifo 6.25 µs |
| wrap | wrap | ||
| 0 =exec \ Start with wait loop | 0 =exec \ Start with wait loop | ||
| pio} | pio} | ||
| - | v: pios also extra | ||
| : READ) ( -- data chk ) | : READ) ( -- data chk ) | ||
| one> 0 exec-opc | one> 0 exec-opc | ||
| - | begin 0 rx-depth 1- until \ Stack minimal two deep? | + | begin 0 rx-depth 1- until \ Fifo minimal two deep? |
| 0 rxf> | 0 rxf> | ||
| Line 68: | Line 67: | ||
| : CHKS ( data -- chks ) \ Calculate checksum | : CHKS ( data -- chks ) \ Calculate checksum | ||
| h-h b-b + swap \ Split & calc. checksum | h-h b-b + swap \ Split & calc. checksum | ||
| - | b-b + + | + | b-b + + |
| : READ ( -- t h ) | : READ ( -- t h ) | ||
| 0 begin | 0 begin | ||
| - | >r dup chks \ save & split reading | + | over chks <> while \ Checksum not ok? |
| - | r> <> while | + | |
| drop 1+ \ Drop reading, count retries | drop 1+ \ Drop reading, count retries | ||
| dup 1- ? | dup 1- ? | ||
en/pfw/dht22-rp2040-nofortht.1751036957.txt.gz · Last modified: 2025-06-27 17:09 by willem