From d1bbcc86d8655e55094e71e2ffdf8feebec725e6 Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Sat, 1 Mar 2025 10:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SHT30=E5=87=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=90=8E=E9=87=8D=E6=96=B0=E4=B8=8A=E7=94=B5=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=88=9D=E5=A7=8B=E5=8C=96IIC1=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8CSHT30IIC=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=94=B10xFFFF=E6=94=B9=E4=B8=BA0xFF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Inc/anemometer_dev.h | 2 +- App/Src/anemometer_dev.c | 15 ++++++++++++++- Drivers/Sht3x/sht30.c | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) 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; }