求助贴,我的DHT11无法接受复位信号
在接受DHT11返回代码部分时一直为高电平 所以超时了
试过换成5v电压,没用
注意到初始信号为低电平,初始化为高电平然后delay了200ms后再继续执行也没用
感谢各位师傅交流与解答[抱拳][抱拳]
DHT11代码
#include "stm32f10x.h" // Device header
#includeDelay.h#include "LCD.h"
//向DHT11发送信号
void DHT11_Rst(void){
// ST7735_ShowNum(99 - 32, 32, GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12), 1);
GPIO_ResetBits(GPIOB, GPIO_Pin_12);
// ST7735_ShowNum(99 - 32, 0, GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12), 1);
Delay_ms(20);
GPIO_SetBits(GPIOB, GPIO_Pin_12);
// ST7735_ShowNum(99 - 32, 16, GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12), 1);
Delay_us(30);
}
//返回0正常 1为低电平响应超时 2为高电平响应超时
uint8_t DHT11_Check(void){
uint16_t retry = 0;
for(int i = 0; i < 100; i ++){
if( GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == 0){
Delay_us(1);
retry++;
ST7735_ShowNum(99 - 32, 0, retry, 3);
}
else{
break;
}
}
if(retry == 100){ //超时
return 1;
}
retry = 0;
for(int i = 0; i < 100; i ++){
if( GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == 1){
Delay_us(1);
retry++;
ST7735_ShowNum(99 - 32 - 16, 0, retry, 3);
}
else{
break;
}
}
if(retry == 100){ //超时
return 2;
}
return 0;
}
uint8_t DHT11_ReadBit(void){
while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == 0); //等待第一段结束
Delay_us(40);
if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == 0){
return 0;
}
else{
return 1;
}
}
uint8_t DHT11_ReadByte(void){
uint8_t data;
for(int i = 0; i < 8; i++){
data <<= 1;
data |= DHT11_ReadBit();
}
return data;
}
void DHT11_ReadData(uint8_t data[5]){
for(int i = 0; i [removed]