在网上找的 SHT20 的程序,我只修改了端口 由PB6、PB7也成了 PB10、PB11
可运行后,读出的值为128.多,温湿度的值都不变。
好像接不接传感器都显示128.多 的值!
请各位大神指教一下,那里有问题?谢谢
.h 的设置,我只改了前3行
#define SHT2x_I2C_PORT GPIOB
#define SHT2x_SCL_PIN GPIO_Pin_10 //6
#define SHT2x_SDA_PIN GPIO_Pin_11 //7
#define SHT2x_SCL_HIGH() GPIO_SetBits(SHT2x_I2C_PORT, SHT2x_SCL_PIN)
#define SHT2x_SCL_LOW() GPIO_ResetBits(SHT2x_I2C_PORT, SHT2x_SCL_PIN)
#define SHT2x_SDA_HIGH() GPIO_SetBits(SHT2x_I2C_PORT, SHT2x_SDA_PIN)
#define SHT2x_SDA_LOW() GPIO_ResetBits(SHT2x_I2C_PORT, SHT2x_SDA_PIN)
#define SHT2x_SCL_STATE() GPIO_ReadInputDataBit(SHT2x_I2C_PORT, SHT2x_SCL_PIN)
#define SHT2x_SDA_STATE() GPIO_ReadInputDataBit(SHT2x_I2C_PORT, SHT2x_SDA_PI
.c 初始化函数,我只加了 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);这一句
void SHT2x_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
GPIO_InitStructure.GPIO_Pin = SHT2x_SCL_PIN | SHT2x_SDA_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(SHT2x_I2C_PORT, &GPIO_InitStructure);
SHT2x_SCL_HIGH();
SHT2x_SDA_HIGH();
SHT2x_Delay(80);
SHT2x_SoftReset();
}
|