EmbDev.net

Forum: ARM programming with GCC/GNU tools DHT22 Sensor readings unrealisitc with STM32F407 uC


von Bernhard Ebner (Guest)


Attached files:

Rate this post
0 useful
not useful
First of all i want to say hello

I have a problem with my DHT22 temperature and humidity sensor. The 
start signal is fine, the sensor response signal is fine, the bits that 
the sensor sends me are fine my problem is how can i read out the data 
that the sensor sends me because my values are 2700 for humidity and 
between 4500 and 5800 for temperature. As you will see in the attatched 
file, i hope it works this is my first post, i have tried it using a for 
loop and after the sensor pulls the data line to 0 for the 50us low 
voltage that comes before every bit, i will put the datasheet down 
below, i wait until the data line gets pulled high and because a 0 will 
be 26-28us high i wait for 40us and if it is still high i will write a 1 
otherwise i will write a 0 in the variable.

Data Sheet:
https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf

A bit more information about the protocol:
https://www.waveshare.com/wiki/DHT22_Temperature-Humidity_Sensor

I will also put the code in here in case my attatched file doesnt work:

I am using CodeBlocks to write my code
#include "SmartcontrolOS.h"
#include "Apps.h"
#include "CMSIS.h"
void Temperature_Humidity(ui32 dt){

    static bool ini_OK = false;


     LCD__write(_,"%2.0f",wf(dd));

      if(!ini_OK) Scheduler__wait(_,3*sec); // start signal block
      DO__write_open_drain(_,PA4,1);
      DO__write_open_drain(_,PA4,0);
      Scheduler__wait(_,10*ms);
      DO__write_open_drain(_,PA4,1);
      Scheduler__wait(_,40*us);
      DI__read(_,PA4);



Scheduler__wait(_,40*us);            //check sensor reply block

if(DI__read(_,PA4) == 0)  Scheduler__wait(_,90*us);


while(DI__read(_,PA4) == 0);


ui8 sum = 0;
ui8 temp1 = 0, temp2 = 0;
ui8 feucht1 = 0, feucht2 = 0;
int i;


for(i = 39; i >= 0; i = i - 1)  //read data block
  {

  while(DI__read(_,PA4) != 1);

  Scheduler__wait(_,40*us);

    if(DI__read(_,PA4) == 1)
     {
       if     (i >= 32) feucht1 |= 1 << (i - 32);
       else if(i >= 24) feucht2 |= 1 << (i - 24);
       else if(i >= 16) temp1   |= 1 << (i - 16);
       else if(i >= 8)  temp2   |= 1 << (i-8);
       else             sum     |= 1 << i;
     }

  while(DI__read(_,PA4) == 0);

  }



 ui16 Temperature = 0, RH = 0;

 RH = (feucht1 << 8) | feucht2;

 Temperature = (temp1 << 8) | temp2;




LCD__write(_,"%8.1f\n%8.1f   %5.0f",wf(RH/10.0f),wf(Temperature/10.0f),wf(sum));



Scheduler__wait(_,3*sec);
ini_OK = true;
}


  void CPE_App__Wetterstation_T_RH(){

   Resources__ExBoard_init(_,"");

   while(1){
     const ui32 dt = 1*ms;
    Scheduler__wait(_,dt);



   Temperature_Humidity(dt);


   }

  }

von Bernhard E. (maymes)


Rate this post
0 useful
not useful
>      LCD__write(_,"%2.0f",wf(dd));

I just realised this line, ignore it i tried something.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig