增加HP203B负温度判断逻辑
This commit is contained in:
parent
5f0b0ae9ea
commit
7091edb970
|
@ -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;
|
||||
/// 错误处理
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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; i++){
|
||||
hp203_set_mode();
|
||||
ret = Hp203bReadPressure(&collect_pressure[i].fValue);
|
||||
if(ret == FALSE)
|
||||
{
|
||||
press_error_time++;
|
||||
goto error_return;
|
||||
}
|
||||
osDelay(1);
|
||||
}
|
||||
if(press_error_time >= 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; i++){
|
||||
hp203_set_mode();
|
||||
ret = Hp203bReadTempture(&collect_tempture[i].fValue);
|
||||
if(ret == FALSE)
|
||||
{
|
||||
temp_error_time++;
|
||||
goto error_return;
|
||||
}
|
||||
osDelay(1);
|
||||
}
|
||||
if(temp_error_time >= 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;
|
||||
|
|
|
@ -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温度值校验失败");
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
</option>
|
||||
<option>
|
||||
<name>OCDynDriverList</name>
|
||||
<state>CMSISDAP_ID</state>
|
||||
<state>STLINK_ID</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>OCLastSavedByProductVersion</name>
|
||||
|
|
Loading…
Reference in New Issue