diff --git a/App/Inc/anemometer_dev.h b/App/Inc/anemometer_dev.h index 13107e5..a0d385a 100644 --- a/App/Inc/anemometer_dev.h +++ b/App/Inc/anemometer_dev.h @@ -42,7 +42,7 @@ // 温度探头版本,SHT30=1,TMP117=2 #define SHT30_SENSOR 1 #define TMP117_SENSOR 2 -#define TEMP_SENSOR TMP117_SENSOR +#define TEMP_SENSOR SHT30_SENSOR ///已将DISTANCE写入配置文件,在结构体g_stConfigInfo.transducer_distace中 diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c index ea43e7d..ced44cf 100644 --- a/App/Src/anemometer_dev.c +++ b/App/Src/anemometer_dev.c @@ -1099,9 +1099,22 @@ static void getTempHumiPress(void) // SHT30出问题 if(sht30_ret == FALSE) { + //错误处理 + //关电重启,第一次进入错误判断,此时此时错误标志位为0,关电并置位错误标志位; + //再进入错误标志位检测到错误标志位后开电 + //下一次监测如果SHT30恢复,则正常运行,如果没有恢复,电继续开着,保证温度传感器正常运行 + if(g_error_log.temp_error_SHT30 == 0) + { + HAL_GPIO_WritePin(GPIOB, GPIO_SHT_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_I2C_DeInit(&hi2c1); + }else + { + HAL_GPIO_WritePin(GPIOB, GPIO_SHT_PWR_EN_Pin, GPIO_PIN_SET); + MX_I2C1_Init(); + sht30_init(); + } //置错误标志位 g_error_log.temp_error_SHT30 = 1; - //错误处理 #if TEMP_SENSOR == SHT30_SENSOR g_stMcs_Para.temperature = backupTemperature1; #endif /*TEMP_SENSOR == SHT30_SENSOR*/ diff --git a/Drivers/Sht3x/sht30.c b/Drivers/Sht3x/sht30.c index f33a8d8..23bd38a 100644 --- a/Drivers/Sht3x/sht30.c +++ b/Drivers/Sht3x/sht30.c @@ -33,7 +33,7 @@ static u_int8_t i2c_write_cmd(u_int8_t addr,u_int16_t cmd) cmd_buff[0] = cmd>>8; cmd_buff[1] = cmd; - u_int8_t ret = HAL_I2C_Master_Transmit(&hi2c1,addr,cmd_buff,2,0xffff); + u_int8_t ret = HAL_I2C_Master_Transmit(&hi2c1,addr,cmd_buff,2,0xff); return ret; } @@ -101,7 +101,7 @@ u_int8_t sht30_collect_data(stTempHumiSensor stSensorDev, float *temp, float *hu i2c_write_cmd(stSensorDev.i2c_reg_addr,stSensorDev.cmd_read_data); - if(HAL_I2C_Master_Receive(&hi2c1,stSensorDev.i2c_reg_addr,read_buff,6,0xffff) != HAL_OK){ + if(HAL_I2C_Master_Receive(&hi2c1,stSensorDev.i2c_reg_addr,read_buff,6,0xff) != HAL_OK){ return HAL_ERROR; }