diff --git a/App/Inc/anemometer_dev.h b/App/Inc/anemometer_dev.h
index b66fd56..dd40f8f 100644
--- a/App/Inc/anemometer_dev.h
+++ b/App/Inc/anemometer_dev.h
@@ -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; /* 保留 */
diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c
index 33f66d8..f5259f2 100644
--- a/App/Src/anemometer_dev.c
+++ b/App/Src/anemometer_dev.c
@@ -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;
}
diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c
index 7f57e69..5ee9e32 100644
--- a/Core/Src/freertos.c
+++ b/Core/Src/freertos.c
@@ -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)
{
diff --git a/Core/Src/main.c b/Core/Src/main.c
index 3c1f1cd..956ae80 100644
--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -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) */
diff --git a/Drivers/Tmp117/tmp117.c b/Drivers/Tmp117/tmp117.c
new file mode 100644
index 0000000..55e0969
--- /dev/null
+++ b/Drivers/Tmp117/tmp117.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;
+}
+
diff --git a/Drivers/Tmp117/tmp117.h b/Drivers/Tmp117/tmp117.h
new file mode 100644
index 0000000..7111240
--- /dev/null
+++ b/Drivers/Tmp117/tmp117.h
@@ -0,0 +1,27 @@
+#ifndef __TMP117_H_
+#define __TMP117_H_
+
+#include "comm_types.h"
+#include "main.h"
+
+#define TMP117_ADDR 0x48 //A0GND
+//#define TMP117_ADDR 0x49 //A0V+
+//#define TMP117_ADDR 0x4A //A0SDA
+//#define TMP117_ADDR 0x4B //A0SCL
+
+#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_
+
+
+
+
diff --git a/EWARM/micro_climate.ewp b/EWARM/micro_climate.ewp
index 4e95e6e..6518386 100644
--- a/EWARM/micro_climate.ewp
+++ b/EWARM/micro_climate.ewp
@@ -374,6 +374,7 @@
$PROJ_DIR$\..\tools
$PROJ_DIR$\..\App\Inc
$PROJ_DIR$\..\Drivers\HP203B
+ $PROJ_DIR$\..\Drivers\Tmp117