User Tools

Site Tools


en:pfw:dht22-rp2040-nofortht

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:dht22-rp2040-nofortht [2025-06-27 17:09] willemen:pfw:dht22-rp2040-nofortht [2025-06-29 13:25] (current) willem
Line 2: Line 2:
  
 <code> <code>
-(* DHT22 sensor, using PIO: 480 bytes +(* DHT22 sensor, using PIO: 424 bytes 
-   Willem Ouwerkerk 20250627+   Willem Ouwerkerk, 20250629
  
     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  decimal      \ Empty code space, start at zero clean-pio  decimal      \ Empty code space, start at zero
 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      \ GPIO 5 for OUT & SET     05 1 =out-pins      \ GPIO 5 for OUT & SET
     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,                  \ This contains the sensor data         begin,                  \ This contains the sensor data
             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,             \ Count all 32 bits 6.25 Ás+        y--? until,             \ Count all 32 bits 6.25 µs
-        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,             \ Count 8 bits 6.25 Ás +        y--? until,             \ Count 8 bits 6.25 µs 
-        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             \ Start new measurement     one> 0 exec-opc             \ Start new measurement
-    begin  0 rx-depth 1- until  \ Stack minimal two deep?+    begin  0 rx-depth 1- until  \ Fifo minimal two deep?
     0 rxf>   0 rxf> ;           \ 32-bits data & 8-bits checksum     0 rxf>   0 rxf> ;           \ 32-bits data & 8-bits checksum
  
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 +  +  hx FF and ;+    b-b +  +  b-b drop ;
  
 : READ  ( -- t h ) : READ  ( -- t h )
     0  begin   read)        \ Read sensor     0  begin   read)        \ Read sensor
-        >r  dup chks        \ save & split reading +    over chks <> while      Checksum not ok?
-    r> <> while             Not ok?+
         drop  1+            \ Drop reading, count retries         drop  1+            \ Drop reading, count retries
         dup 1- ?abort       \ More then one retry, abort         dup 1- ?abort       \ More then one retry, abort
en/pfw/dht22-rp2040-nofortht.1751036957.txt.gz · Last modified: 2025-06-27 17:09 by willem