2025-07-07 10:27 PM
I am trying to interface DHT22 sensor with STM32F411RE board. When initially I interfaced I was able to see data (i.e., Temp and Humidity) I am giving 3.3v power supply, data pin connected to PA0 ground and set clock frequency to 50MHZ using Internal oscillator. But when now I am trying to check values, I am not able to get values I haven't change anything in code still I am facing this issue. The code is stuck in while loop of DHT22_response function where it is waiting for pin to be low. I have attached coding file please can anyone help me regarding this??
2025-07-08 3:34 AM
Hello @Reva1605,
Have you tried connecting a pull-up resistor to the data line? Without it, the DHT11 may not be able to pull the line HIGH.
Best regards,
2025-07-08 4:48 AM
Yes tried connecting pull-up resistor of value 4.7k still not working
2025-07-08 5:36 AM - edited 2025-07-08 5:37 AM
So, to understand correctly, you created a project and added the functions to interface with the DHT22 sensor. Initially, it worked, but after rebuilding and testing the project again, it got stuck in the DHT22_response
function? Have you tried supplying 5V to the sensor or using a different GPIO pin instead of the wakeup pin PA0?
2025-07-08 6:46 AM
Welcome to the forum.
Please see How to write your question to maximize your chances to find a solution for best results.
In particular, please describe:
2025-07-08 8:49 PM
I have tried supplying 5v to sensor. I haven't tried using different GPIO pin I will try that once.
2025-07-08 9:03 PM
As mentioned, I am using STM32F411RE board and interfacing DHT22 sensor. So previously I was testing dht22 sensor with 3.3v power supply I was giving me correct values of humidity and temperature but now when I am trying get values it is stuck in DHT22_response () .
About setup it is just simple connection between stm32 board and dht22 sensor.
2025-07-08 11:00 PM - edited 2025-07-08 11:02 PM
The following worked here with a DHT11:
int main(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = DHT11_DAT_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(DHT11_DAT_PORT, &GPIO_InitStruct);
HAL_GPIO_WritePin( DHT11_DAT_PORT, DHT11_DAT_PIN, GPIO_PIN_SET);
delay_us(1000*1000); // wait after power on
for(;;) {
HAL_GPIO_WritePin( DHT11_DAT_PORT, DHT11_DAT_PIN, GPIO_PIN_RESET);
delay_us(20*1000); // wait >18ms
HAL_GPIO_WritePin( DHT11_DAT_PORT, DHT11_DAT_PIN, GPIO_PIN_SET);
ReadDHT11();
delay_us(2*1000*1000); // wait 2s for next reading
}
}
Differences:
- the pin is never pushed high
- the pin is read while in output mode
- give it time to start-up after power-on
hth
KnarfB
2025-07-08 11:02 PM
I am using DHT22 so will it work with my sensor?
2025-07-08 11:23 PM
The translated english data sheets show pretty much the same diagrams, copied from the chinese originals. There are some differences in electrical and environmental conditions: Overview | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System
As theres are quite old parts, there are dozends of tutorials around...
hth
KnarfB