添加新的温度探头
This commit is contained in:
parent
075d293173
commit
34c91c3099
|
@ -35,9 +35,13 @@
|
|||
#define DRIVE_FREQ_MHz ((float32_t)0.2)
|
||||
|
||||
// 驱动方波个数 实际个数 DRIVE_NUM+1
|
||||
|
||||
#define DRIVE_NUM 2
|
||||
|
||||
// 温度探头版本,SHT30=1,TMP117=2
|
||||
#define SHT30_SENSOR 1
|
||||
#define TMP117_SENSOR 2
|
||||
#define TEMP_SENSOR TMP117_SENSOR
|
||||
|
||||
|
||||
///已将DISTANCE写入配置文件,在结构体g_stConfigInfo.transducer_distace中
|
||||
// 传播距离 风速计算公式中的L参数
|
||||
|
@ -140,7 +144,7 @@ typedef struct _error_log{
|
|||
uint16_t tof_error_WE:1; /* 接受东西信号(tofy,tofx<0)很小 */
|
||||
uint16_t temp_error_SHT30:1; /* SHT30错误日志(温湿度) */
|
||||
uint16_t temp_error_HP203B:1; /* HP203B错误日志(大气压) */
|
||||
uint16_t error_4:1; /* 保留 */
|
||||
uint16_t temp_error_TMP117:1; /* TMP117错误日志(温度) */
|
||||
uint16_t error_5:1; /* 保留 */
|
||||
uint16_t error_6:1; /* 保留 */
|
||||
uint16_t error_7:1; /* 保留 */
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "fdacoefs.h"
|
||||
#include "sht30.h"
|
||||
#include "hp203b.h"
|
||||
#include "tmp117.h"
|
||||
#include "FIR.h"
|
||||
#include "LowPassFilter.h"
|
||||
#include "encrypt.h"
|
||||
|
@ -1063,35 +1064,76 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction)
|
|||
win_10min.index = (win_10min.index + 1) % g_usrConfigInfo.speed_average_time;//更新索引
|
||||
}
|
||||
|
||||
//采集温度,湿度,大气压
|
||||
static void getTempHumiPress(void)
|
||||
{
|
||||
//采集备用温度与大气压
|
||||
float backupTemperature1;
|
||||
float backupTemperature2;
|
||||
uint8_t hp203_ret = get_HP203_data(&backupTemperature1, &g_stMcs_Para.pressure);
|
||||
uint8_t sht30_ret = get_temp_humi_data(&backupTemperature2, &g_stMcs_Para.humidity);
|
||||
#if TEMP_SENSOR == SHT30_SENSOR
|
||||
g_stMcs_Para.temperature = backupTemperature2;
|
||||
#endif /*TEMP_SENSOR == SHT30_SENSOR*/
|
||||
|
||||
#if TEMP_SENSOR == TMP117_SENSOR
|
||||
uint8_t tmp117_ret = TMP117_Get_Temp(&g_stMcs_Para.temperature);
|
||||
|
||||
// TMP117出问题
|
||||
if(tmp117_ret != HAL_OK)
|
||||
{
|
||||
//置错误标志位
|
||||
g_error_log.temp_error_TMP117 = 1;
|
||||
//使用备用温度
|
||||
g_stMcs_Para.temperature = backupTemperature1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//恢复错误标志位
|
||||
g_error_log.temp_error_TMP117 = 0;
|
||||
}
|
||||
#endif /*TEMP_SENSOR == TMP117_SENSOR*/
|
||||
|
||||
// SHT30出问题
|
||||
if(sht30_ret == FALSE)
|
||||
{
|
||||
//置错误标志位
|
||||
g_error_log.temp_error_SHT30 = 1;
|
||||
//错误处理
|
||||
#if TEMP_SENSOR == SHT30_SENSOR
|
||||
g_stMcs_Para.temperature = backupTemperature1;
|
||||
#endif /*TEMP_SENSOR == SHT30_SENSOR*/
|
||||
}
|
||||
else
|
||||
{
|
||||
//恢复错误标志位
|
||||
g_error_log.temp_error_SHT30 = 0;
|
||||
}
|
||||
|
||||
//HP203B出问题
|
||||
if(hp203_ret == FALSE)
|
||||
{
|
||||
//置错误标志位
|
||||
g_error_log.temp_error_HP203B = 1;
|
||||
//错误处理
|
||||
}
|
||||
else
|
||||
{
|
||||
//恢复错误标志位
|
||||
g_error_log.temp_error_HP203B = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void tem_hum_update_task(void const * argument)
|
||||
{
|
||||
uint8_t tem_hun_check_flag = JudgeEncrypt();
|
||||
|
||||
uint16_t time_s_temp_humi = 0;//1秒计时,温湿度更新
|
||||
|
||||
float backupTemperature;
|
||||
uint8_t hp203_ret;
|
||||
uint8_t sht30_ret;
|
||||
// 开机先采集一次大气压温湿度
|
||||
if(tem_hun_check_flag)
|
||||
{
|
||||
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(hp203_ret == FALSE)
|
||||
{
|
||||
g_error_log.temp_error_HP203B = 1;
|
||||
/// 错误处理
|
||||
}
|
||||
// 采集SHT30传感器数据(温湿度)
|
||||
if(sht30_ret == FALSE)
|
||||
{
|
||||
g_error_log.temp_error_SHT30 = 1;
|
||||
/// 错误处理
|
||||
g_stMcs_Para.temperature = backupTemperature;
|
||||
//采集温湿度与大气压
|
||||
getTempHumiPress();
|
||||
}
|
||||
|
||||
while(1)
|
||||
|
@ -1102,31 +1144,7 @@ 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(hp203_ret == FALSE)
|
||||
{
|
||||
g_error_log.temp_error_HP203B = 1;
|
||||
/// 错误处理
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没出问题清除错误日志
|
||||
g_error_log.temp_error_HP203B = 0;
|
||||
}
|
||||
// 采集SHT30传感器数据(温湿度)
|
||||
if(sht30_ret == FALSE)
|
||||
{
|
||||
g_error_log.temp_error_SHT30 = 1;
|
||||
/// 错误处理
|
||||
g_stMcs_Para.temperature = backupTemperature;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没出问题清除错误日志
|
||||
g_error_log.temp_error_SHT30 = 0;
|
||||
}
|
||||
getTempHumiPress();
|
||||
// 计时重置
|
||||
time_s_temp_humi = 0;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ void task_shell_term_main_loop(void const * argument);
|
|||
#include "frt_protocol.h"
|
||||
#include "inflash.h"
|
||||
#include "hp203b.h"
|
||||
#include "tmp117.h"
|
||||
#include "encrypt.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
|
@ -201,7 +202,7 @@ void LEDTask(void const * argument)
|
|||
time_s_1Hour ++;
|
||||
if(LED_Check_flag)
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOC,GPIO_LED_CTRL_Pin);
|
||||
HAL_GPIO_TogglePin(GPIOC,GPIO_LED_CTRL_Pin);
|
||||
// 一天重启
|
||||
if (time_s_1Hour >= 3600)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "uart_dev.h"
|
||||
#include "sht30.h"
|
||||
#include "hp203b.h"
|
||||
#include "tmp117.h"
|
||||
|
||||
#include "inflash.h"
|
||||
/* USER CODE END Includes */
|
||||
|
@ -172,6 +173,7 @@ 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();
|
||||
TMP117_Init();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Call init function for freertos objects (in cmsis_os2.c) */
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#include "tmp117.h"
|
||||
#include "i2c.h"
|
||||
|
||||
|
||||
// 初始化温度传感器(连续转换模式,64次平均)
|
||||
HAL_StatusTypeDef TMP117_Init(void)
|
||||
{
|
||||
// 配置值:连续转换模式 + AVG=64 (0x00A0)
|
||||
uint8_t config_data[2] = {0x00, 0xA0}; // 高字节在前
|
||||
return HAL_I2C_Mem_Write(&hi2c1, TMP117_ADDR << 1, TMP117_CONFIG_REG,
|
||||
I2C_MEMADD_SIZE_8BIT, config_data, 2, 100);
|
||||
}
|
||||
|
||||
// 从寄存器读取双字节数据
|
||||
HAL_StatusTypeDef TMP117_Read(uint8_t reg, uint8_t *buffer) {
|
||||
return HAL_I2C_Mem_Read(&hi2c1, TMP117_ADDR << 1, reg,
|
||||
I2C_MEMADD_SIZE_8BIT, buffer, 2, 100);
|
||||
}
|
||||
|
||||
// 获取温度值(单位:℃)
|
||||
HAL_StatusTypeDef TMP117_Get_Temp(float *temp)
|
||||
{
|
||||
uint8_t raw_data[2] = {0};
|
||||
int16_t temp_raw;
|
||||
|
||||
if (HAL_OK == TMP117_Read(TMP117_TEMP_REG, raw_data)) {
|
||||
temp_raw = (raw_data[0] << 8) | raw_data[1];
|
||||
*temp = temp_raw * 0.0078125f;
|
||||
}
|
||||
else
|
||||
{
|
||||
*temp = 0;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
if(*temp <= -60)
|
||||
{
|
||||
*temp = -60;
|
||||
}
|
||||
if(*temp >= 150)
|
||||
{
|
||||
*temp = 150;
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef __TMP117_H_
|
||||
#define __TMP117_H_
|
||||
|
||||
#include "comm_types.h"
|
||||
#include "main.h"
|
||||
|
||||
#define TMP117_ADDR 0x48 //A0接GND
|
||||
//#define TMP117_ADDR 0x49 //A0接V+
|
||||
//#define TMP117_ADDR 0x4A //A0接SDA
|
||||
//#define TMP117_ADDR 0x4B //A0接SCL
|
||||
|
||||
#define TMP117_TEMP_REG 0x00 //温度寄存器
|
||||
#define TMP117_CONFIG_REG 0x01 //配置寄存器
|
||||
#define TMP117_TLOW_REG 0x02 //温度高报警寄存器
|
||||
#define TMP117_THIGH_REG 0x03 //温度低报警寄存器
|
||||
|
||||
|
||||
|
||||
HAL_StatusTypeDef TMP117_Init(void);
|
||||
HAL_StatusTypeDef TMP117_Read(uint8_t reg, uint8_t *buffer);
|
||||
HAL_StatusTypeDef TMP117_Get_Temp(float *temp);
|
||||
|
||||
#endif __TMP117_H_
|
||||
|
||||
|
||||
|
||||
|
|
@ -374,6 +374,7 @@
|
|||
<state>$PROJ_DIR$\..\tools</state>
|
||||
<state>$PROJ_DIR$\..\App\Inc</state>
|
||||
<state>$PROJ_DIR$\..\Drivers\HP203B</state>
|
||||
<state>$PROJ_DIR$\..\Drivers\Tmp117</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCStdIncCheck</name>
|
||||
|
@ -1485,6 +1486,7 @@
|
|||
<state>$PROJ_DIR$\..\tools</state>
|
||||
<state>$PROJ_DIR$\..\App\Inc</state>
|
||||
<state>$PROJ_DIR$\..\Drivers\HP203B</state>
|
||||
<state>$PROJ_DIR$\..\Drivers\Tmp117</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCStdIncCheck</name>
|
||||
|
@ -2482,6 +2484,15 @@
|
|||
<name>$PROJ_DIR$\..\Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart_ex.c</name>
|
||||
</file>
|
||||
</group>
|
||||
<group>
|
||||
<name>tmp117</name>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\Tmp117\tmp117.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\Tmp117\tmp117.h</name>
|
||||
</file>
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<name>Middlewares</name>
|
||||
|
|
|
@ -3111,6 +3111,15 @@
|
|||
<name>$PROJ_DIR$\..\Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart_ex.c</name>
|
||||
</file>
|
||||
</group>
|
||||
<group>
|
||||
<name>tmp117</name>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\Tmp117\tmp117.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\Tmp117\tmp117.h</name>
|
||||
</file>
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<name>Middlewares</name>
|
||||
|
|
Loading…
Reference in New Issue