diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c index f911ebe..65e94b0 100644 --- a/App/Src/anemometer_dev.c +++ b/App/Src/anemometer_dev.c @@ -977,21 +977,22 @@ void tem_hum_update_task(void const * argument) float backupTemperature; // 开机先采集一次大气压温湿度 - { + uint8_t hp203_ret = get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure); + uint8_t sht30_ret = get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity); + // 采集HP203B传感器数据(大气压) - if(get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure) == FALSE) + if(hp203_ret == FALSE) { g_error_log.temp_error_HP203B = 1; /// 错误处理 } // 采集SHT30传感器数据(温湿度) - if(get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity) == FALSE) + if(sht30_ret == FALSE) { g_error_log.temp_error_SHT30 = 1; /// 错误处理 g_stMcs_Para.temperature = backupTemperature; } - } while(1) { @@ -1001,8 +1002,10 @@ void tem_hum_update_task(void const * argument) // 温湿度大气压更新 if (time_s_temp_humi >= g_usrConfigInfo.temp_hum_update_time) { + hp203_ret = get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure); + sht30_ret = get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity); // 采集HP203B传感器数据(大气压) - if(get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure) == FALSE) + if(hp203_ret == FALSE) { g_error_log.temp_error_HP203B = 1; /// 错误处理 @@ -1013,7 +1016,7 @@ void tem_hum_update_task(void const * argument) g_error_log.temp_error_HP203B = 0; } // 采集SHT30传感器数据(温湿度) - if(get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity) == FALSE) + if(sht30_ret == FALSE) { g_error_log.temp_error_SHT30 = 1; /// 错误处理 diff --git a/Core/Src/main.c b/Core/Src/main.c index 4364c1f..b78caa8 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -171,7 +171,6 @@ void Flash_EnableReadProtection(void) term_printf("Version 1.0.0 Build: %s %s\r\n",__DATE__,__TIME__); HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED); sht30_init(); - hp203_set_mode(); /* USER CODE END 2 */ diff --git a/Drivers/HP203B/hp203b.c b/Drivers/HP203B/hp203b.c index 880a2f0..57508b3 100644 --- a/Drivers/HP203B/hp203b.c +++ b/Drivers/HP203B/hp203b.c @@ -41,10 +41,12 @@ BOOL Hp203bReadPressure(float *press) Hp203b_Pressure <<= 8; Hp203b_Pressure |= Hp203bPressure_Temp[2]; - Hp203b_Pressure = Hp203b_Pressure / 100; - if(Hp203b_Pressure<300||Hp203b_Pressure>1200) + *press = (float)Hp203b_Pressure / 100.0f; + if(*press < 300 || *press > 1200) + { + *press = 0; return FALSE; - *press = Hp203b_Pressure; + } return TRUE; } @@ -58,21 +60,27 @@ BOOL Hp203bReadPressure(float *press) *****************************/ BOOL Hp203bReadTempture(float *press) { - long Hp203b_tempture = 0; + uint32_t Hp203b_tempture = 0; uint8_t Hp203bPressure_Temp[3] = {0}; uint8_t read_command[1] = {0x32}; HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff); HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff); - - Hp203b_tempture = Hp203bPressure_Temp[0]; - Hp203b_tempture <<= 8; - Hp203b_tempture |= Hp203bPressure_Temp[1]; - Hp203b_tempture <<= 8; + Hp203b_tempture = (Hp203bPressure_Temp[0] & 0x0F)<<16; + Hp203b_tempture |= Hp203bPressure_Temp[1]<<8; Hp203b_tempture |= Hp203bPressure_Temp[2]; - Hp203b_tempture = Hp203b_tempture / 100; - *press = Hp203b_tempture; + if((Hp203b_tempture>>19) & 1){ + Hp203b_tempture = (((~Hp203b_tempture) + 1) & 0xFFFFF); + *press = -(float)Hp203b_tempture / 100.0f; + } + else{ + *press = (float)Hp203b_tempture / 100.0f; + } + if(*press<-50||*press>95){ + *press = 0; + return FALSE; + } return TRUE; } @@ -86,25 +94,22 @@ BOOL Hp203bReadTempture(float *press) *****************************/ #define COLLECT_HB203_DATA_NUM 10 BOOL get_HP203_data(float* tempdata, float* press) -{ +{ int ret; - uint8_t temp_error_time, press_error_time = 0; // ѹǿ U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00}; for(int i=0; i= COLLECT_HB203_DATA_NUM) - { - goto error_return; - } - U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM - press_error_time, FILTER_DATA_TYPE_FLOAT); + + U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT); if(tmp_press.fValue < 300) { // return FALSE; @@ -119,24 +124,22 @@ BOOL get_HP203_data(float* tempdata, float* press) U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00}; for(int i=0; i= COLLECT_HB203_DATA_NUM) - { - goto error_return; - } - U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM - temp_error_time, FILTER_DATA_TYPE_FLOAT); - if(tmp_tempture.fValue < -40) + + U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT); + if(tmp_tempture.fValue < -50) { // return FALSE; goto error_return; } - if(tmp_tempture.fValue > 85) + if(tmp_tempture.fValue > 95) { // return FALSE; goto error_return; diff --git a/Drivers/Sht3x/sht30.c b/Drivers/Sht3x/sht30.c index 189fb88..f33a8d8 100644 --- a/Drivers/Sht3x/sht30.c +++ b/Drivers/Sht3x/sht30.c @@ -146,7 +146,7 @@ BOOL get_temp_humi_data(float* temdata, float* humidata) // // AssertError((tmp_temdata.fValue >= -40) && (tmp_temdata.fValue <= 85), return FALSE, "sht30¶ֵУʧ"); // AssertError((tmp_humidata.fValue >= 0) && (tmp_humidata.fValue <= 100), return FALSE, "sht30ʪֵУʧ"); - if(tmp_temdata.fValue < -40) + if(tmp_temdata.fValue < -50) { // tmp_temdata.fValue = -40; // term_printf("sht30¶ֵУʧ"); diff --git a/EWARM/micro_climate.ewd b/EWARM/micro_climate.ewd index 2e5c4d3..c567dea 100644 --- a/EWARM/micro_climate.ewd +++ b/EWARM/micro_climate.ewd @@ -84,7 +84,7 @@