cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read the data from the DHT11 temperature sensor

HZ
Associate II

I have written the following bare-metal code to get readings from the DHT11 sensor on my stm32 G071RB board:

I have attached my main.c file below.

 

When I try to debug my code, the execution halts at - while ((DHT11_PORT->IDR & GPIO_PIN_12) != 0); in the sensor response function, suggesting that the sensor has not pulled the bus low to respond to the start signal sent by MCU.....(IDR12 in the IDR register remains high)

This can mean that the sensor is not detected by the MCU after sending the start signal or the sensor is not able to send the data.

 

I have checked the RCC configuration and Timer 6 delay configuration code. It does seem to work accurately and can be confirmed using a simple LED blink code for numerous seconds...

could someone provide any suggestions to solve this problem?

I have tried using different dht11 sensors, which suggests that the problem has got to be with the code.....

3 REPLIES 3

@HZ wrote:

suggesting that the sensor has not pulled the bus low 


How have you tested whether that suggestion is true?

eg, have you used an oscilloscope to see what's actually happening on the wire?

 

There have been posts about reading DHT11 before - try a search ...

As soon as I set the the gpio pin as output in debug - DHT11_PORT->MODER &= ~(1<<25), the ID12 in IDR register  turns from 0 to 1, but ODR remains 0. Following this after setting DHT11_PORT->BSRR |= GPIO_PIN_12; the ODR12 turns from 0 to 1 and IDR12 remains 1.....

 

I do not have much knowledge on this behaviour...

so to send start signal from mcu, I have done it by setting OD10 for 40 us...

I believe the sensor response can then be noted in the IDR register when the sensor pulls the bus low (pulls ID12 from 1 to 0) which of course doesn't happen...

 

I am not sure if my assessment is right, and would like some advise on how to proceed further.

 

I have tried to look for similar issues online but most of them work with HAL, and not similar to the problem I am facing...


@HZ wrote:

I have tried to look for similar issues online but most of them work with HAL, 


Then start with that.

Once you have a working reference, then you can start working on making a register-level version of it.