en:pfw:dht22-msp430g2553-noforth
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:pfw:dht22-msp430g2553-noforth [2025-04-26 21:12] – neuste Version eingespielt. mka | en:pfw:dht22-msp430g2553-noforth [2025-06-27 11:57] (current) – [Sorce Code] mka | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== Read DHT22 data using noForth on TI's Launchpad. | ||
| + | |||
| + | [[en: | ||
| + | ==== Pseudocode ==== | ||
| + | |||
| + | < | ||
| + | Function: Pio ( -- ) \ set port I/O function. SDA --> P1.0 | ||
| + | Function: wakeup ( -- ) \ notify sensor to prepare the data | ||
| + | Function: @data ( -- sun moon hum tmp chk chksum ) \ get sensor data | ||
| + | get response time of sensor, store in register ' | ||
| + | get startpulse duration, store in register ' | ||
| + | 40 loop | ||
| + | read bit using ' | ||
| + | | ||
| + | 08 loop | ||
| + | | ||
| + | calculate chksum | ||
| + | Function: (dht22) | ||
| + | Function: | ||
| + | Function: | ||
| + | n loop dht22 | ||
| + | </ | ||
| + | |||
| + | ==== Sorce Code ==== | ||
| + | |||
| + | < | ||
| \ Read DHT22 data. (bit bang) | \ Read DHT22 data. (bit bang) | ||
| \ TI MSP430G2553 Launchpad with noForth mv 2553 240101 | \ TI MSP430G2553 Launchpad with noForth mv 2553 240101 | ||
| + | \ M.Kalus 20250627 | ||
| (* | (* | ||
| Line 28: | Line 55: | ||
| 026 P1SEL Port Select | 026 P1SEL Port Select | ||
| 041 P1SEL2 | 041 P1SEL2 | ||
| - | 027 P1REN | + | 027 P1REN |
| *) | *) | ||
| Line 40: | Line 67: | ||
| code p1H #1 021 & .b bis next end-code \ set lines | code p1H #1 021 & .b bis next end-code \ set lines | ||
| - | code p1L #1 021 & .b bic next end-code | + | code p1L #1 021 & .b bic next end-code |
| - | code p6H 40 # 021 & .b bis next end-code | + | code p6H 40 # 021 & .b bis next end-code |
| - | code p6L 40 # 021 & .b bic next end-code | + | code p6L 40 # 021 & .b bic next end-code |
| Line 197: | Line 224: | ||
| freeze | freeze | ||
| ( finis) | ( finis) | ||
| + | </ | ||
| + | |||
| + | ==== Numerical representation of the measured values ==== | ||
| + | Note((This is already included in the source code.)) | ||
| + | |||
| + | |||
| + | === Humidity === | ||
| + | |||
| + | The first 16 bits coming from the DHT22 are the relative humidity in tenths of a percent. They can be processed directly with the 16-bit noForth and correspond to a positive integer. Rounded to whole digits for display purposes. | ||
| + | Here is an excerpt from the noforth source code: | ||
| + | |||
| + | < | ||
| + | : .hum ( hum -- ) 10 / . ." %rel" space ; | ||
| + | </ | ||
| + | |||
| + | === Temperature === | ||
| + | |||
| + | The next 16 bits are the temperature in tenths of a degree Celsius. Temperatures from zero degrees and higher can be processed directly using the 16-bit noForth; they correspond to a positive integer. | ||
| + | |||
| + | Temperatures below zero degrees are represented by the DHT22 as follows: The MSB of the 16-bits is set, but otherwise the temperature is specified as a positive integer. This number format //does not correspond// | ||
| + | < | ||
| + | : .tmp ( tmp -- ) | ||
| + | dup hx 8000 and hx 8000 = \ check MSB | ||
| + | if [char] - | ||
| + | else [char] + | ||
| + | then emit | ||
| + | hx 7fff and ( tmp -- +tmp ) \ reset MSB | ||
| + | 10 /mod 3 .r [char] . emit . \ --> TTT.T | ||
| + | [char] f decemit | ||
| + | space | ||
| + | ; | ||
| + | </ | ||
| + | |||
| + | |||
en/pfw/dht22-msp430g2553-noforth.1745694753.txt.gz · Last modified: 2025-04-26 21:12 by mka