0
\$\begingroup\$

I am trying to read the sensor data from the DHT21(AM2301) temperature and humidity sensor. According to the spec, the process of reading data is below:

MCU sends start signal - Sensor sends acknowledge signal - Sensor sends 40-bit data.

I am observing the data line through a scope. Start signals are okay, but sensor sends 64-bit data. Is there any possibility that causes the sensor to send 64-bit data instead of 40-bit data? If I do the calculations according to the first 40-bit, I get parity error. Here is the example output data:

0xFE - 0x80 - 0xFE - 0xDA - 0x59 - 0xFF - 0xFF - 0xFF

I also attached the scope view.

enter image description here

\$\endgroup\$
1
\$\begingroup\$

Looks like it's working perfectly to me, apart from sending some undocumented zero bits after the end of the parity byte.

First of all, you've misinterpreted the spec - a long pulse is a "1" and a short one is a "0". That gives the first 16 bits as 0x019E and the second 16 bits as 0x011A. Converting those to decimal and dividing by ten as per the datasheet gives a humidity of 41.4% and a temperature of 28.2 degrees Centigrade, which sound quite feasible.

Finally, the parity byte is 0xBA, which is exactly what you get if you add 0x01, 0x9E, 0x01 and 0x1A together. I've just no idea why they use the term "parity" when most would call that a checksum.

\$\endgroup\$
  • \$\begingroup\$ The scope view and the example data were get from different moments. My calculations were not applying the checksum when I did it from the scope. Now you did it from a low resolution image and its true :) I still don't know why my software gets in to parity error and sensor gives additional 3 bytes. I will double check my software by comparing the same input from the scope view and my debug view. Thank you so much! \$\endgroup\$ – abdullah cinar Feb 6 '17 at 19:46
0
\$\begingroup\$

make sure you had adhered to the timing specification for the data received as seen in the document page 7

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.