Merge pull request #275 from DavidLin1577/patch-1
Fixed bug in l610_tencent_firmware
This commit is contained in:
@@ -9,10 +9,10 @@ int result;
|
|||||||
|
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Init_BH1750
|
* 函数名称: Init_BH1750
|
||||||
* ˵ <EFBFBD><EFBFBD>: д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>BH1750
|
* 说 明: 写命令初始化BH1750
|
||||||
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <20><>
|
* 参 数: 无
|
||||||
* <EFBFBD><EFBFBD> <20><> ֵ: <20><>
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_BH1750(void)
|
void Init_BH1750(void)
|
||||||
{
|
{
|
||||||
@@ -21,10 +21,10 @@ void Init_BH1750(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Start_BH1750
|
* 函数名称: Start_BH1750
|
||||||
* ˵ <EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD>BH1750
|
* 说 明: 启动BH1750
|
||||||
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <20><>
|
* 参 数: 无
|
||||||
* <EFBFBD><EFBFBD> <20><> ֵ: <20><>
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Start_BH1750(void)
|
void Start_BH1750(void)
|
||||||
{
|
{
|
||||||
@@ -35,19 +35,19 @@ void Start_BH1750(void)
|
|||||||
|
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Convert_BH1750
|
* 函数名称: Convert_BH1750
|
||||||
* ˵ <EFBFBD><EFBFBD>: <20><>ֵת<D6B5><D7AA>
|
* 说 明: 数值转换
|
||||||
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <20><>
|
* 参 数: 无
|
||||||
* <EFBFBD><EFBFBD> <20><> ֵ: <20><>ǿֵ
|
* 返 回 值: 光强值
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
float Convert_BH1750(void)
|
float Convert_BH1750(void)
|
||||||
{
|
{
|
||||||
Start_BH1750();
|
Start_BH1750();
|
||||||
HAL_Delay(180);
|
HAL_Delay(180);
|
||||||
HAL_I2C_Master_Receive(&hi2c1, BH1750_Addr+1,BUF,2,0xff);
|
HAL_I2C_Master_Receive(&hi2c1, BH1750_Addr+1,BUF,2,0xff);
|
||||||
result=BUF[0];
|
result=BUF[0];
|
||||||
result=(result<<8)+BUF[1]; //<EFBFBD>ϳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
result=(result<<8)+BUF[1]; //合成数据,即光照数据
|
||||||
result_lx=(float)(result/1.2);
|
result_lx=(float)(result/1.2);
|
||||||
return result_lx;
|
return result_lx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
#ifndef __BH1750_H__
|
#ifndef __BH1750_H__
|
||||||
#define __BH1750_H__
|
#define __BH1750_H__
|
||||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> ----------------------------------------------------------------*/
|
/* 包含头文件 ----------------------------------------------------------------*/
|
||||||
#include "stm32l4xx_hal.h"
|
#include "stm32l4xx_hal.h"
|
||||||
|
|
||||||
/* <EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD> ------------------------------------------------------------------*/
|
/* 类型定义 ------------------------------------------------------------------*/
|
||||||
/* <EFBFBD>궨<EFBFBD><EFBFBD> --------------------------------------------------------------------*/
|
/* 宏定义 --------------------------------------------------------------------*/
|
||||||
#define I2C_OWN_ADDRESS 0x0A
|
#define I2C_OWN_ADDRESS 0x0A
|
||||||
|
|
||||||
#define BH1750_Addr 0x46
|
#define BH1750_Addr 0x46
|
||||||
#define BH1750_ON 0x01
|
#define BH1750_ON 0x01
|
||||||
@@ -15,25 +15,21 @@
|
|||||||
|
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: BH1750_Data_TypeDef
|
* 函数名称: BH1750_Data_TypeDef
|
||||||
* ˵ <EFBFBD><EFBFBD>: BH1750<EFBFBD>ṹ<EFBFBD><EFBFBD>
|
* 说 明: BH1750结构体
|
||||||
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <20><>
|
* 参 数: 无
|
||||||
* <EFBFBD><EFBFBD> <20><> ֵ: <20><>
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char Lux[5]; //<2F><>ǿ
|
char Lux[5]; //光强
|
||||||
}BH1750_Data_TypeDef;
|
}BH1750_Data_TypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
void Init_BH1750(void); //IO初始化,
|
||||||
void Init_BH1750(void); //IO<49><4F>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
void Start_BH1750(void); //上电,设置清除数据寄存器
|
||||||
void Start_BH1750(void); //<2F>ϵ磬<CFB5><E7A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD>
|
//void Read_BH1750(void); //连续的读取内部寄存器数据
|
||||||
//void Read_BH1750(void); //<2F><><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>ȡ<EFBFBD>ڲ<EFBFBD><DAB2>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
float Convert_BH1750(void);
|
float Convert_BH1750(void);
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __BH1750_H__ */
|
||||||
|
|
||||||
|
@@ -39,16 +39,16 @@ void Start_BH1750(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
float Convert_BH1750(void)
|
float Convert_BH1750(void)
|
||||||
{
|
{
|
||||||
float result_lx;
|
float result_lx;
|
||||||
uint8_t BUF[2];
|
uint8_t BUF[2];
|
||||||
int result;
|
int result;
|
||||||
Start_BH1750();
|
Start_BH1750();
|
||||||
HAL_Delay(180);
|
HAL_Delay(180);
|
||||||
HAL_I2C_Master_Receive(&hi2c1, BH1750_Addr+1,BUF,2,0xff);
|
HAL_I2C_Master_Receive(&hi2c1, BH1750_Addr+1,BUF,2,0xff);
|
||||||
result=BUF[0];
|
result=BUF[0];
|
||||||
result=(result<<8)+BUF[1]; //Synthetic Digital Illumination Intensity Data
|
result=(result<<8)+BUF[1]; //Synthetic Digital Illumination Intensity Data
|
||||||
result_lx=(float)(result/1.2);
|
result_lx=(float)(result/1.2);
|
||||||
return result_lx;
|
return result_lx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -59,10 +59,9 @@ float Convert_BH1750(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void SHT30_reset(void)
|
void SHT30_reset(void)
|
||||||
{
|
{
|
||||||
uint8_t SHT3X_Resetcommand_Buffer[2]={0x30,0xA2}; //soft reset
|
uint8_t SHT3X_Resetcommand_Buffer[2]={0x30,0xA2}; //soft reset
|
||||||
HAL_I2C_Master_Transmit(&hi2c1,SHT30_Addr<<1,SHT3X_Resetcommand_Buffer,2,0x10);
|
HAL_I2C_Master_Transmit(&hi2c1,SHT30_Addr<<1,SHT3X_Resetcommand_Buffer,2,0x10);
|
||||||
HAL_Delay(15);
|
HAL_Delay(15);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -73,18 +72,17 @@ void SHT30_reset(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_SHT30(void)
|
void Init_SHT30(void)
|
||||||
{
|
{
|
||||||
uint8_t SHT3X_Modecommand_Buffer[2]={0x22,0x36}; //periodic mode commands
|
uint8_t SHT3X_Modecommand_Buffer[2]={0x22,0x36}; //periodic mode commands
|
||||||
HAL_I2C_Master_Transmit(&hi2c1,SHT30_Addr<<1,SHT3X_Modecommand_Buffer,2,0x10); //send periodic mode commands
|
HAL_I2C_Master_Transmit(&hi2c1,SHT30_Addr<<1,SHT3X_Modecommand_Buffer,2,0x10); //send periodic mode commands
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: SHT3x_CheckCrc
|
* 函数名称: SHT3x_CheckCrc
|
||||||
* 说 明: 检查数据正确性
|
* 说 明: 检查数据正确性
|
||||||
* 参 数: data:读取到的数据
|
* 参 数: data:读取到的数据
|
||||||
nbrOfBytes:需要校验的数量
|
nbrOfBytes:需要校验的数量
|
||||||
checksum:读取到的校对比验值
|
checksum:读取到的校对比验值
|
||||||
* 返 回 值: 校验结果,0-成功 1-失败
|
* 返 回 值: 校验结果,0-成功 1-失败
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
uint8_t SHT3x_CheckCrc(char data[], char nbrOfBytes, char checksum)
|
uint8_t SHT3x_CheckCrc(char data[], char nbrOfBytes, char checksum)
|
||||||
{
|
{
|
||||||
@@ -105,10 +103,9 @@ uint8_t SHT3x_CheckCrc(char data[], char nbrOfBytes, char checksum)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(crc != checksum)
|
if(crc != checksum)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -120,7 +117,7 @@ uint8_t SHT3x_CheckCrc(char data[], char nbrOfBytes, char checksum)
|
|||||||
float SHT3x_CalcTemperatureC(unsigned short u16sT)
|
float SHT3x_CalcTemperatureC(unsigned short u16sT)
|
||||||
{
|
{
|
||||||
|
|
||||||
float temperatureC = 0; // variable for result
|
float temperatureC = 0; // variable for result
|
||||||
|
|
||||||
u16sT &= ~0x0003; // clear bits [1..0] (status bits)
|
u16sT &= ~0x0003; // clear bits [1..0] (status bits)
|
||||||
//-- calculate temperature [℃] --
|
//-- calculate temperature [℃] --
|
||||||
@@ -139,7 +136,7 @@ float SHT3x_CalcTemperatureC(unsigned short u16sT)
|
|||||||
float SHT3x_CalcRH(unsigned short u16sRH)
|
float SHT3x_CalcRH(unsigned short u16sRH)
|
||||||
{
|
{
|
||||||
|
|
||||||
float humidityRH = 0; // variable for result
|
float humidityRH = 0; // variable for result
|
||||||
|
|
||||||
u16sRH &= ~0x0003; // clear bits [1..0] (status bits)
|
u16sRH &= ~0x0003; // clear bits [1..0] (status bits)
|
||||||
//-- calculate relative humidity [%RH] --
|
//-- calculate relative humidity [%RH] --
|
||||||
@@ -157,49 +154,47 @@ float SHT3x_CalcRH(unsigned short u16sRH)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_Motor(void)
|
void Init_Motor(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
IA1_Motor_GPIO_CLK_ENABLE();
|
IA1_Motor_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_RESET);
|
||||||
E53_IA1_Data.MotorMode=0;
|
E53_IA1_Data.MotorMode=0;
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = IA1_Motor_Pin;
|
GPIO_InitStruct.Pin = IA1_Motor_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(IA1_Motor_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(IA1_Motor_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void motor_control(char mode){
|
void motor_control(char mode){
|
||||||
if(mode==1)
|
if(mode==1)
|
||||||
{
|
{
|
||||||
E53_IA1_Data.MotorMode=1;
|
E53_IA1_Data.MotorMode=1;
|
||||||
HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
else if(mode==0)
|
else if(mode==0)
|
||||||
{
|
{
|
||||||
E53_IA1_Data.MotorMode=0;
|
E53_IA1_Data.MotorMode=0;
|
||||||
HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void light_control(char mode){
|
void light_control(char mode){
|
||||||
if(mode==1)
|
if(mode==1)
|
||||||
{
|
{
|
||||||
E53_IA1_Data.LightMode=1;
|
E53_IA1_Data.LightMode=1;
|
||||||
HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
else if(mode==0)
|
else if(mode==0)
|
||||||
{
|
{
|
||||||
E53_IA1_Data.LightMode=0;
|
E53_IA1_Data.LightMode=0;
|
||||||
HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -210,20 +205,20 @@ void light_control(char mode){
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_Light(void)
|
void Init_Light(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
IA1_Light_GPIO_CLK_ENABLE();
|
IA1_Light_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_RESET);
|
||||||
E53_IA1_Data.LightMode=0;
|
E53_IA1_Data.LightMode=0;
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = IA1_Light_Pin;
|
GPIO_InitStruct.Pin = IA1_Light_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(IA1_Light_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(IA1_Light_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: Init_E53_IA1
|
* 函数名称: Init_E53_IA1
|
||||||
@@ -234,7 +229,7 @@ void Init_Light(void)
|
|||||||
void Init_E53_IA1(void)
|
void Init_E53_IA1(void)
|
||||||
{
|
{
|
||||||
//printf("E53_sensor_board init!\n");
|
//printf("E53_sensor_board init!\n");
|
||||||
MX_I2C1_Init();
|
MX_I2C1_Init();
|
||||||
Init_BH1750();
|
Init_BH1750();
|
||||||
Init_SHT30();
|
Init_SHT30();
|
||||||
Init_Motor();
|
Init_Motor();
|
||||||
@@ -254,7 +249,7 @@ void E53_IA1_Read_Data(void)
|
|||||||
char data[3]; //data array for checksum verification
|
char data[3]; //data array for checksum verification
|
||||||
unsigned short tmp = 0;
|
unsigned short tmp = 0;
|
||||||
uint16_t dat;
|
uint16_t dat;
|
||||||
uint8_t SHT3X_Fetchcommand_Bbuffer[2]={0xE0,0x00}; //read the measurement results
|
uint8_t SHT3X_Fetchcommand_Bbuffer[2]={0xE0,0x00}; //read the measurement results
|
||||||
uint8_t SHT3X_Data_Buffer[6]; //byte 0,1 is temperature byte 4,5 is humidity
|
uint8_t SHT3X_Data_Buffer[6]; //byte 0,1 is temperature byte 4,5 is humidity
|
||||||
|
|
||||||
E53_IA1_Data.Lux=Convert_BH1750(); //Read bh1750 sensor data
|
E53_IA1_Data.Lux=Convert_BH1750(); //Read bh1750 sensor data
|
||||||
@@ -289,4 +284,3 @@ void E53_IA1_Read_Data(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,19 +15,19 @@
|
|||||||
/* E53_IA1传感器数据类型定义 ------------------------------------------------------------*/
|
/* E53_IA1传感器数据类型定义 ------------------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float Lux; //光照强度
|
float Lux; //光照强度
|
||||||
float Humidity; //湿度
|
float Humidity; //湿度
|
||||||
float Temperature; //温度
|
float Temperature; //温度
|
||||||
char MotorMode;
|
char MotorMode;
|
||||||
char LightMode;
|
char LightMode;
|
||||||
} E53_IA1_Data_TypeDef;
|
} E53_IA1_Data_TypeDef;
|
||||||
|
|
||||||
extern E53_IA1_Data_TypeDef E53_IA1_Data;
|
extern E53_IA1_Data_TypeDef E53_IA1_Data;
|
||||||
|
|
||||||
/* 寄存器宏定义 --------------------------------------------------------------------*/
|
/* 寄存器宏定义 --------------------------------------------------------------------*/
|
||||||
#define I2C_OWN_ADDRESS 0x0A
|
#define I2C_OWN_ADDRESS 0x0A
|
||||||
|
|
||||||
#define SHT30_Addr 0x44
|
#define SHT30_Addr 0x44
|
||||||
|
|
||||||
#define BH1750_Addr 0x46
|
#define BH1750_Addr 0x46
|
||||||
#define BH1750_ON 0x01
|
#define BH1750_ON 0x01
|
||||||
@@ -38,9 +38,5 @@ extern E53_IA1_Data_TypeDef E53_IA1_Data;
|
|||||||
void Init_E53_IA1(void);
|
void Init_E53_IA1(void);
|
||||||
void E53_IA1_Read_Data(void);
|
void E53_IA1_Read_Data(void);
|
||||||
|
|
||||||
#endif
|
#endif /* __E53_IA1_H__ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,52 +15,52 @@ TIM_HandleTypeDef htim16;
|
|||||||
/* TIM16 init function */
|
/* TIM16 init function */
|
||||||
void MX_TIM16_Init(void)
|
void MX_TIM16_Init(void)
|
||||||
{
|
{
|
||||||
TIM_OC_InitTypeDef sConfigOC;
|
TIM_OC_InitTypeDef sConfigOC;
|
||||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
|
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
|
||||||
|
|
||||||
htim16.Instance = TIM16;
|
htim16.Instance = TIM16;
|
||||||
htim16.Init.Prescaler = 79;
|
htim16.Init.Prescaler = 79;
|
||||||
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim16.Init.Period = 999;
|
htim16.Init.Period = 999;
|
||||||
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim16.Init.RepetitionCounter = 0;
|
htim16.Init.RepetitionCounter = 0;
|
||||||
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
|
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&htim16) != HAL_OK)
|
if (HAL_TIM_PWM_Init(&htim16) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
sConfigOC.Pulse = 499;
|
sConfigOC.Pulse = 499;
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||||
sBreakDeadTimeConfig.DeadTime = 0;
|
sBreakDeadTimeConfig.DeadTime = 0;
|
||||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||||
sBreakDeadTimeConfig.BreakFilter = 0;
|
sBreakDeadTimeConfig.BreakFilter = 0;
|
||||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)
|
if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_TIM_MspPostInit(&htim16);
|
HAL_TIM_MspPostInit(&htim16);
|
||||||
|
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -72,17 +72,17 @@ void MX_TIM16_Init(void)
|
|||||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(tim_baseHandle->Instance==TIM16)
|
if(tim_baseHandle->Instance==TIM16)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM16_MspInit 0 */
|
/* USER CODE BEGIN TIM16_MspInit 0 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspInit 0 */
|
/* USER CODE END TIM16_MspInit 0 */
|
||||||
/* TIM16 clock enable */
|
/* TIM16 clock enable */
|
||||||
__HAL_RCC_TIM16_CLK_ENABLE();
|
__HAL_RCC_TIM16_CLK_ENABLE();
|
||||||
/* USER CODE BEGIN TIM16_MspInit 1 */
|
/* USER CODE BEGIN TIM16_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspInit 1 */
|
/* USER CODE END TIM16_MspInit 1 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -94,27 +94,27 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
|||||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
if(timHandle->Instance==TIM16)
|
if(timHandle->Instance==TIM16)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM16_MspPostInit 0 */
|
/* USER CODE BEGIN TIM16_MspPostInit 0 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspPostInit 0 */
|
/* USER CODE END TIM16_MspPostInit 0 */
|
||||||
|
|
||||||
/**TIM16 GPIO Configuration
|
/**TIM16 GPIO Configuration
|
||||||
PB8 ------> TIM16_CH1
|
PB8 ------> TIM16_CH1
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = SF1_Beep_Pin;
|
GPIO_InitStruct.Pin = SF1_Beep_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
|
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
|
||||||
HAL_GPIO_Init(SF1_Beep_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(SF1_Beep_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM16_MspPostInit 1 */
|
/* USER CODE BEGIN TIM16_MspPostInit 1 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspPostInit 1 */
|
/* USER CODE END TIM16_MspPostInit 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,43 +126,43 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void MX_ADC1_Init(void)
|
void MX_ADC1_Init(void)
|
||||||
{
|
{
|
||||||
ADC_ChannelConfTypeDef sConfig;
|
ADC_ChannelConfTypeDef sConfig;
|
||||||
|
|
||||||
/**Common config
|
/**Common config
|
||||||
*/
|
*/
|
||||||
hadc1.Instance = ADC1;
|
hadc1.Instance = ADC1;
|
||||||
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
||||||
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
||||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||||
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||||
hadc1.Init.LowPowerAutoWait = DISABLE;
|
hadc1.Init.LowPowerAutoWait = DISABLE;
|
||||||
hadc1.Init.ContinuousConvMode = DISABLE;
|
hadc1.Init.ContinuousConvMode = DISABLE;
|
||||||
hadc1.Init.NbrOfConversion = 1;
|
hadc1.Init.NbrOfConversion = 1;
|
||||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||||
hadc1.Init.NbrOfDiscConversion = 1;
|
hadc1.Init.NbrOfDiscConversion = 1;
|
||||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||||
hadc1.Init.DMAContinuousRequests = DISABLE;
|
hadc1.Init.DMAContinuousRequests = DISABLE;
|
||||||
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||||
hadc1.Init.OversamplingMode = DISABLE;
|
hadc1.Init.OversamplingMode = DISABLE;
|
||||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Configure Regular Channel
|
/**Configure Regular Channel
|
||||||
*/
|
*/
|
||||||
sConfig.Channel = ADC_CHANNEL_3;
|
sConfig.Channel = ADC_CHANNEL_3;
|
||||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||||
sConfig.Offset = 0;
|
sConfig.Offset = 0;
|
||||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,26 +175,26 @@ void MX_ADC1_Init(void)
|
|||||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
if(adcHandle->Instance==ADC1)
|
if(adcHandle->Instance==ADC1)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspInit 0 */
|
/* USER CODE END ADC1_MspInit 0 */
|
||||||
/* ADC1 clock enable */
|
/* ADC1 clock enable */
|
||||||
__HAL_RCC_ADC_CLK_ENABLE();
|
__HAL_RCC_ADC_CLK_ENABLE();
|
||||||
|
|
||||||
/**ADC1 GPIO Configuration
|
/**ADC1 GPIO Configuration
|
||||||
PC2 ------> ADC1_IN3
|
PC2 ------> ADC1_IN3
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspInit 1 */
|
/* USER CODE END ADC1_MspInit 1 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,20 +206,20 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_Beep(void)
|
void Init_Beep(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
SF1_Beep_GPIO_CLK_ENABLE();
|
SF1_Beep_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(SF1_Beep_GPIO_Port, SF1_Beep_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(SF1_Beep_GPIO_Port, SF1_Beep_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = SF1_Beep_Pin;
|
GPIO_InitStruct.Pin = SF1_Beep_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(SF1_Beep_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(SF1_Beep_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -230,20 +230,20 @@ void Init_Beep(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_LED(void)
|
void Init_LED(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
SF1_LED_GPIO_CLK_ENABLE();
|
SF1_LED_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(SF1_LED_GPIO_Port, SF1_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(SF1_LED_GPIO_Port, SF1_LED_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = SF1_LED_Pin;
|
GPIO_InitStruct.Pin = SF1_LED_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(SF1_LED_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(SF1_LED_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: Init_E53_SF1
|
* 函数名称: Init_E53_SF1
|
||||||
@@ -253,10 +253,10 @@ void Init_LED(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_E53_SF1(void)
|
void Init_E53_SF1(void)
|
||||||
{
|
{
|
||||||
MX_ADC1_Init();
|
MX_ADC1_Init();
|
||||||
Init_Beep();
|
Init_Beep();
|
||||||
Init_LED();
|
Init_LED();
|
||||||
MX_TIM16_Init();
|
MX_TIM16_Init();
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: E53_SF1_Read_Data
|
* 函数名称: E53_SF1_Read_Data
|
||||||
@@ -266,37 +266,37 @@ void Init_E53_SF1(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void E53_SF1_Read_Data(void)
|
void E53_SF1_Read_Data(void)
|
||||||
{
|
{
|
||||||
HAL_ADC_Start(&hadc1);
|
HAL_ADC_Start(&hadc1);
|
||||||
HAL_ADC_PollForConversion(&hadc1, 50);
|
HAL_ADC_PollForConversion(&hadc1, 50);
|
||||||
E53_SF1_Data.Smoke_Value = HAL_ADC_GetValue(&hadc1);
|
E53_SF1_Data.Smoke_Value = HAL_ADC_GetValue(&hadc1);
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: E53SF1_LED_StatusSet
|
* 函数名称: E53SF1_LED_StatusSet
|
||||||
* 说 明: E53SF1开发板上的LED灯的亮灭控制
|
* 说 明: E53SF1开发板上的LED灯的亮灭控制
|
||||||
* 参 数: status,LED灯的状态
|
* 参 数: status,LED灯的状态
|
||||||
* 非1,关灯
|
* 非1,关灯
|
||||||
* 1,开灯
|
* 1,开灯
|
||||||
* 返 回 值: 无
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
void E53SF1_LED_StatusSet(E53SF1_Status_ENUM status)
|
void E53SF1_LED_StatusSet(E53SF1_Status_ENUM status)
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(SF1_LED_GPIO_Port, SF1_LED_Pin, status != ON ? GPIO_PIN_RESET : GPIO_PIN_SET );
|
HAL_GPIO_WritePin(SF1_LED_GPIO_Port, SF1_LED_Pin, status != ON ? GPIO_PIN_RESET : GPIO_PIN_SET );
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: E53SF1_BEEP
|
* 函数名称: E53SF1_BEEP
|
||||||
* 说 明: E53SF1蜂鸣器报警与否
|
* 说 明: E53SF1蜂鸣器报警与否
|
||||||
* 参 数: status,LED_ENUM枚举的数据
|
* 参 数: status,LED_ENUM枚举的数据
|
||||||
* LED_OFF,关灯
|
* LED_OFF,关灯
|
||||||
* LED_ON,开灯
|
* LED_ON,开灯
|
||||||
* 返 回 值: 无
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
void E53SF1_Beep(E53SF1_Status_ENUM status)
|
void E53SF1_Beep(E53SF1_Status_ENUM status)
|
||||||
{
|
{
|
||||||
if(status == ON)
|
if(status == ON)
|
||||||
HAL_TIM_PWM_Start(&htim16,TIM_CHANNEL_1);
|
HAL_TIM_PWM_Start(&htim16,TIM_CHANNEL_1);
|
||||||
if(status == OFF)
|
if(status == OFF)
|
||||||
HAL_TIM_PWM_Stop(&htim16,TIM_CHANNEL_1);
|
HAL_TIM_PWM_Stop(&htim16,TIM_CHANNEL_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -20,19 +20,19 @@ extern TIM_HandleTypeDef htim16;
|
|||||||
/* E53_SF1传感器数据类型定义 ------------------------------------------------------------*/
|
/* E53_SF1传感器数据类型定义 ------------------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int Smoke_Value;
|
int Smoke_Value;
|
||||||
} E53_SF1_Data_TypeDef;
|
} E53_SF1_Data_TypeDef;
|
||||||
|
|
||||||
extern E53_SF1_Data_TypeDef E53_SF1_Data;
|
extern E53_SF1_Data_TypeDef E53_SF1_Data;
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 名 称: GasStatus_ENUM
|
* 名 称: E53SF1_Status_ENUM
|
||||||
* 说 明:枚举状态结构体
|
* 说 明:枚举状态结构体
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
OFF = 0,
|
OFF = 0,
|
||||||
ON
|
ON
|
||||||
} E53SF1_Status_ENUM;
|
} E53SF1_Status_ENUM;
|
||||||
|
|
||||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||||
@@ -41,9 +41,5 @@ void E53_SF1_Read_Data(void);
|
|||||||
void E53SF1_LED_StatusSet(E53SF1_Status_ENUM status);
|
void E53SF1_LED_StatusSet(E53SF1_Status_ENUM status);
|
||||||
void E53SF1_Beep(E53SF1_Status_ENUM status);
|
void E53SF1_Beep(E53SF1_Status_ENUM status);
|
||||||
|
|
||||||
#endif
|
#endif /* __E53_SF1_H__ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,52 +19,52 @@ TIM_HandleTypeDef htim16;
|
|||||||
/* TIM16 init function */
|
/* TIM16 init function */
|
||||||
void MX_TIM16_Init(void)
|
void MX_TIM16_Init(void)
|
||||||
{
|
{
|
||||||
TIM_OC_InitTypeDef sConfigOC;
|
TIM_OC_InitTypeDef sConfigOC;
|
||||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
|
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
|
||||||
|
|
||||||
htim16.Instance = TIM16;
|
htim16.Instance = TIM16;
|
||||||
htim16.Init.Prescaler = 79;
|
htim16.Init.Prescaler = 79;
|
||||||
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim16.Init.Period = 999;
|
htim16.Init.Period = 999;
|
||||||
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim16.Init.RepetitionCounter = 0;
|
htim16.Init.RepetitionCounter = 0;
|
||||||
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
|
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&htim16) != HAL_OK)
|
if (HAL_TIM_PWM_Init(&htim16) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
sConfigOC.Pulse = 499;
|
sConfigOC.Pulse = 499;
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||||
sBreakDeadTimeConfig.DeadTime = 0;
|
sBreakDeadTimeConfig.DeadTime = 0;
|
||||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||||
sBreakDeadTimeConfig.BreakFilter = 0;
|
sBreakDeadTimeConfig.BreakFilter = 0;
|
||||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)
|
if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_TIM_MspPostInit(&htim16);
|
HAL_TIM_MspPostInit(&htim16);
|
||||||
|
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -76,16 +76,16 @@ void MX_TIM16_Init(void)
|
|||||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(tim_baseHandle->Instance==TIM16)
|
if(tim_baseHandle->Instance==TIM16)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM16_MspInit 0 */
|
/* USER CODE BEGIN TIM16_MspInit 0 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspInit 0 */
|
/* USER CODE END TIM16_MspInit 0 */
|
||||||
/* TIM16 clock enable */
|
/* TIM16 clock enable */
|
||||||
__HAL_RCC_TIM16_CLK_ENABLE();
|
__HAL_RCC_TIM16_CLK_ENABLE();
|
||||||
/* USER CODE BEGIN TIM16_MspInit 1 */
|
/* USER CODE BEGIN TIM16_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspInit 1 */
|
/* USER CODE END TIM16_MspInit 1 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,26 +98,25 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
|||||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
if(timHandle->Instance==TIM16)
|
if(timHandle->Instance==TIM16)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM16_MspPostInit 0 */
|
/* USER CODE BEGIN TIM16_MspPostInit 0 */
|
||||||
|
|
||||||
/* USER CODE END TIM16_MspPostInit 0 */
|
/* USER CODE END TIM16_MspPostInit 0 */
|
||||||
|
|
||||||
/**TIM16 GPIO Configuration
|
/**TIM16 GPIO Configuration
|
||||||
PB8 ------> TIM16_CH1
|
PB8 ------> TIM16_CH1
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = ST1_Beep_Pin;
|
GPIO_InitStruct.Pin = ST1_Beep_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
|
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
|
||||||
HAL_GPIO_Init(ST1_Beep_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(ST1_Beep_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM16_MspPostInit 1 */
|
/* USER CODE BEGIN TIM16_MspPostInit 1 */
|
||||||
|
/* USER CODE END TIM16_MspPostInit 1 */
|
||||||
/* USER CODE END TIM16_MspPostInit 1 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -130,20 +129,20 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_Beep(void)
|
void Init_Beep(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
ST1_Beep_GPIO_CLK_ENABLE();
|
ST1_Beep_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(ST1_Beep_GPIO_Port, ST1_Beep_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(ST1_Beep_GPIO_Port, ST1_Beep_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = ST1_Beep_Pin;
|
GPIO_InitStruct.Pin = ST1_Beep_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(ST1_Beep_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(ST1_Beep_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -154,20 +153,20 @@ void Init_Beep(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_LED(void)
|
void Init_LED(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
ST1_LED_GPIO_CLK_ENABLE();
|
ST1_LED_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(ST1_LED_GPIO_Port, ST1_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(ST1_LED_GPIO_Port, ST1_LED_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = ST1_LED_Pin;
|
GPIO_InitStruct.Pin = ST1_LED_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(ST1_LED_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(ST1_LED_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: Init_GPS_POW
|
* 函数名称: Init_GPS_POW
|
||||||
@@ -177,20 +176,20 @@ void Init_LED(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_GPS_POW(void)
|
void Init_GPS_POW(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
ST1_GPS_POW_GPIO_CLK_ENABLE();
|
ST1_GPS_POW_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(ST1_GPS_POW_GPIO_Port, ST1_GPS_POW_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(ST1_GPS_POW_GPIO_Port, ST1_GPS_POW_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = ST1_GPS_POW_Pin;
|
GPIO_InitStruct.Pin = ST1_GPS_POW_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(ST1_GPS_POW_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(ST1_GPS_POW_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: GPS_Init
|
* 函数名称: GPS_Init
|
||||||
@@ -200,10 +199,10 @@ void Init_GPS_POW(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void GPS_Init(void)
|
void GPS_Init(void)
|
||||||
{
|
{
|
||||||
MX_USART3_UART_Init(); //初始化串口
|
MX_USART3_UART_Init(); //初始化串口
|
||||||
HAL_UART_Transmit(&huart3, "$CCMSG,GGA,1,0,*19\r\n", 20, 200);
|
HAL_UART_Transmit(&huart3, "$CCMSG,GGA,1,0,*19\r\n", 20, 200);
|
||||||
HAL_UART_Transmit(&huart3, "$CCMSG,GSA,1,0,*0D\r\n", 20, 200);
|
HAL_UART_Transmit(&huart3, "$CCMSG,GSA,1,0,*0D\r\n", 20, 200);
|
||||||
HAL_UART_Transmit(&huart3, "$CCMSG,GSV,1,0,*1A\r\n", 20, 200);
|
HAL_UART_Transmit(&huart3, "$CCMSG,GSV,1,0,*1A\r\n", 20, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -214,121 +213,121 @@ void GPS_Init(void)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void Init_E53_ST1(void)
|
void Init_E53_ST1(void)
|
||||||
{
|
{
|
||||||
GPS_Init();
|
GPS_Init();
|
||||||
Init_Beep();
|
Init_Beep();
|
||||||
Init_LED();
|
Init_LED();
|
||||||
Init_GPS_POW();
|
Init_GPS_POW();
|
||||||
MX_TIM16_Init();
|
MX_TIM16_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************\
|
/***************************************************\
|
||||||
* 函数名称: NMEA_Comma_Pos
|
* 函数名称: NMEA_Comma_Pos
|
||||||
* 函数功能:从buf里面得到第cx个逗号所在的位置
|
* 函数功能:从buf里面得到第cx个逗号所在的位置
|
||||||
* 输入值:
|
* 输入值:
|
||||||
* 返回值:0~0xFE,代表逗号所在位置的便宜
|
* 返回值:0~0xFE,代表逗号所在位置偏移
|
||||||
* 0xFF,代表不存在第cx个逗号
|
* 0xFF,代表不存在第cx个逗号
|
||||||
\***************************************************/
|
\***************************************************/
|
||||||
|
|
||||||
uint8_t NMEA_Comma_Pos(uint8_t *buf,uint8_t cx)
|
uint8_t NMEA_Comma_Pos(uint8_t *buf,uint8_t cx)
|
||||||
{
|
{
|
||||||
uint8_t *p = buf;
|
uint8_t *p = buf;
|
||||||
while(cx)
|
while(cx)
|
||||||
{
|
{
|
||||||
if(*buf=='*'||*buf<' '||*buf>'z')return 0xFF;
|
if(*buf=='*'||*buf<' '||*buf>'z')return 0xFF;
|
||||||
if(*buf==',')cx--;
|
if(*buf==',')cx--;
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
return buf-p;
|
return buf-p;
|
||||||
}
|
}
|
||||||
/***************************************************\
|
/***************************************************\
|
||||||
* 函数名称: NMEA_Pow
|
* 函数名称: NMEA_Pow
|
||||||
* 函数功能:返回m的n次方值
|
* 函数功能:返回m的n次方值
|
||||||
* 输入值:底数m和指数n
|
* 输入值:底数m和指数n
|
||||||
* 返回值:m^n
|
* 返回值:m^n
|
||||||
\***************************************************/
|
\***************************************************/
|
||||||
uint32_t NMEA_Pow(uint8_t m,uint8_t n)
|
uint32_t NMEA_Pow(uint8_t m,uint8_t n)
|
||||||
{
|
{
|
||||||
uint32_t result = 1;
|
uint32_t result = 1;
|
||||||
while(n--)result *= m;
|
while(n--)result *= m;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/***************************************************\
|
/***************************************************\
|
||||||
* 函数名称: NMEA_Str2num
|
* 函数名称: NMEA_Str2num
|
||||||
* 函数功能:str数字转换为(int)数字,以','或者'*'结束
|
* 函数功能:str数字转换为(int)数字,以','或者'*'结束
|
||||||
* 输入值:buf,数字存储区
|
* 输入值:buf,数字存储区
|
||||||
* dx,小数点位数,返回给调用函数
|
* dx,小数点位数,返回给调用函数
|
||||||
* 返回值:转换后的数值
|
* 返回值:转换后的数值
|
||||||
\***************************************************/
|
\***************************************************/
|
||||||
int NMEA_Str2num(uint8_t *buf,uint8_t*dx)
|
int NMEA_Str2num(uint8_t *buf,uint8_t*dx)
|
||||||
{
|
{
|
||||||
uint8_t *p = buf;
|
uint8_t *p = buf;
|
||||||
uint32_t ires = 0,fres = 0;
|
uint32_t ires = 0,fres = 0;
|
||||||
uint8_t ilen = 0,flen = 0,i;
|
uint8_t ilen = 0,flen = 0,i;
|
||||||
uint8_t mask = 0;
|
uint8_t mask = 0;
|
||||||
int res;
|
int res;
|
||||||
while(1)
|
while(1)
|
||||||
|
{
|
||||||
|
if(*p=='-'){mask |= 0x02;p++;}//说明有负数
|
||||||
|
if(*p==','||*p=='*')break;//遇到结束符
|
||||||
|
if(*p=='.'){mask |= 0x01;p++;}//遇到小数点
|
||||||
|
else if(*p>'9'||(*p<'0'))//数字不在0和9之内,说明有非法字符
|
||||||
{
|
{
|
||||||
if(*p=='-'){mask |= 0x02;p++;}//说明有负数
|
ilen = 0;
|
||||||
if(*p==','||*p=='*')break;//遇到结束符
|
flen = 0;
|
||||||
if(*p=='.'){mask |= 0x01;p++;}//遇到小数点
|
break;
|
||||||
else if(*p>'9'||(*p<'0'))//数字不在0和9之内,说明有非法字符
|
|
||||||
{
|
|
||||||
ilen = 0;
|
|
||||||
flen = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(mask&0x01)flen++;//小数点的位数
|
|
||||||
else ilen++;//str长度加一
|
|
||||||
p++;//下一个字符
|
|
||||||
}
|
}
|
||||||
if(mask&0x02)buf++;//移到下一位,除去负号
|
if(mask&0x01)flen++;//小数点的位数
|
||||||
for(i=0;i<ilen;i++)//得到整数部分数据
|
else ilen++;//str长度加一
|
||||||
{
|
p++;//下一个字符
|
||||||
ires += NMEA_Pow(10,ilen-1-i)*(buf[i]-'0');
|
}
|
||||||
}
|
if(mask&0x02)buf++;//移到下一位,除去负号
|
||||||
if(flen>5)flen=5;//最多取五位小数
|
for(i=0;i<ilen;i++)//得到整数部分数据
|
||||||
*dx = flen;
|
{
|
||||||
for(i=0;i<flen;i++)//得到小数部分数据
|
ires += NMEA_Pow(10,ilen-1-i)*(buf[i]-'0');
|
||||||
{
|
}
|
||||||
fres +=NMEA_Pow(10,flen-1-i)*(buf[ilen+1+i]-'0');
|
if(flen>5)flen=5;//最多取五位小数
|
||||||
}
|
*dx = flen;
|
||||||
res = ires*NMEA_Pow(10,flen)+fres;
|
for(i=0;i<flen;i++)//得到小数部分数据
|
||||||
if(mask&0x02)res = -res;
|
{
|
||||||
return res;
|
fres +=NMEA_Pow(10,flen-1-i)*(buf[ilen+1+i]-'0');
|
||||||
|
}
|
||||||
|
res = ires*NMEA_Pow(10,flen)+fres;
|
||||||
|
if(mask&0x02)res = -res;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
/***************************************************\
|
/***************************************************\
|
||||||
* 函数名称: NMEA_BDS_GPRMC_Analysis
|
* 函数名称: NMEA_BDS_GPRMC_Analysis
|
||||||
* 函数功能:解析GPRMC信息
|
* 函数功能:解析GPRMC信息
|
||||||
* 输入值:gpsx,NMEA信息结构体
|
* 输入值:gpsx,NMEA信息结构体
|
||||||
* buf:接收到的GPS数据缓冲区首地址
|
* buf:接收到的GPS数据缓冲区首地址
|
||||||
\***************************************************/
|
\***************************************************/
|
||||||
void NMEA_BDS_GPRMC_Analysis(gps_msg *gpsmsg,uint8_t *buf)
|
void NMEA_BDS_GPRMC_Analysis(gps_msg *gpsmsg,uint8_t *buf)
|
||||||
{
|
{
|
||||||
uint8_t *p4,dx;
|
uint8_t *p4,dx;
|
||||||
uint8_t posx;
|
uint8_t posx;
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
float rs;
|
float rs;
|
||||||
p4=(uint8_t*)strstr((const char *)buf,"$GPRMC");//"$GPRMC",经常有&和GPRMC分开的情况,故只判断GPRMC.
|
p4=(uint8_t*)strstr((const char *)buf,"$GPRMC"); //"$GPRMC",经常有&和GPRMC分开的情况,故只判断GPRMC.
|
||||||
posx=NMEA_Comma_Pos(p4,3); //得到纬度
|
posx=NMEA_Comma_Pos(p4,3); //得到纬度
|
||||||
if(posx!=0XFF)
|
if(posx!=0XFF)
|
||||||
{
|
{
|
||||||
temp=NMEA_Str2num(p4+posx,&dx);
|
temp=NMEA_Str2num(p4+posx,&dx);
|
||||||
gpsmsg->latitude_bd=temp/NMEA_Pow(10,dx+2); //得到°
|
gpsmsg->latitude_bd=temp/NMEA_Pow(10,dx+2); //得到°
|
||||||
rs=temp%NMEA_Pow(10,dx+2); //得到'
|
rs=temp%NMEA_Pow(10,dx+2); //得到'
|
||||||
gpsmsg->latitude_bd=gpsmsg->latitude_bd*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为°
|
gpsmsg->latitude_bd=gpsmsg->latitude_bd*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为°
|
||||||
}
|
}
|
||||||
posx=NMEA_Comma_Pos(p4,4); //南纬还是北纬
|
posx=NMEA_Comma_Pos(p4,4); //南纬还是北纬
|
||||||
if(posx!=0XFF)gpsmsg->nshemi_bd=*(p4+posx);
|
if(posx!=0XFF)gpsmsg->nshemi_bd=*(p4+posx);
|
||||||
posx=NMEA_Comma_Pos(p4,5); //得到经度
|
posx=NMEA_Comma_Pos(p4,5); //得到经度
|
||||||
if(posx!=0XFF)
|
if(posx!=0XFF)
|
||||||
{
|
{
|
||||||
temp=NMEA_Str2num(p4+posx,&dx);
|
temp=NMEA_Str2num(p4+posx,&dx);
|
||||||
gpsmsg->longitude_bd=temp/NMEA_Pow(10,dx+2); //得到°
|
gpsmsg->longitude_bd=temp/NMEA_Pow(10,dx+2); //得到°
|
||||||
rs=temp%NMEA_Pow(10,dx+2); //得到'
|
rs=temp%NMEA_Pow(10,dx+2); //得到'
|
||||||
gpsmsg->longitude_bd=gpsmsg->longitude_bd*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为°
|
gpsmsg->longitude_bd=gpsmsg->longitude_bd*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60; //转换为°
|
||||||
}
|
}
|
||||||
posx=NMEA_Comma_Pos(p4,6); //东经还是西经
|
posx=NMEA_Comma_Pos(p4,6); //东经还是西经
|
||||||
if(posx!=0XFF)gpsmsg->ewhemi_bd=*(p4+posx);
|
if(posx!=0XFF)gpsmsg->ewhemi_bd=*(p4+posx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -339,39 +338,38 @@ void NMEA_BDS_GPRMC_Analysis(gps_msg *gpsmsg,uint8_t *buf)
|
|||||||
***************************************************************/
|
***************************************************************/
|
||||||
void E53_ST1_Read_Data(void)
|
void E53_ST1_Read_Data(void)
|
||||||
{
|
{
|
||||||
HAL_UART_Receive_IT(&huart3,gps_uart,1000);
|
HAL_UART_Receive_IT(&huart3,gps_uart,1000);
|
||||||
NMEA_BDS_GPRMC_Analysis(&gpsmsg,(uint8_t*)gps_uart); //分析字符串
|
NMEA_BDS_GPRMC_Analysis(&gpsmsg,(uint8_t*)gps_uart); //分析字符串
|
||||||
E53_ST1_Data.Longitude=(float)((float)gpsmsg.longitude_bd/100000);
|
E53_ST1_Data.Longitude=(float)((float)gpsmsg.longitude_bd/100000);
|
||||||
E53_ST1_Data.Latitude=(float)((float)gpsmsg.latitude_bd/100000);
|
E53_ST1_Data.Latitude=(float)((float)gpsmsg.latitude_bd/100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: E53SF1_LED_StatusSet
|
* 函数名称: E53_ST1_LED_StatusSet
|
||||||
* 说 明: E53SF1开发板上的LED灯的亮灭控制
|
* 说 明: E53 ST1开发板上的LED灯的亮灭控制
|
||||||
* 参 数: status,LED灯的状态
|
* 参 数: status,LED灯的状态
|
||||||
* 非1,关灯
|
* 非1,关灯
|
||||||
* 1,开灯
|
* 1,开灯
|
||||||
* 返 回 值: 无
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
void E53_ST1_LED_StatusSet(E53ST1_Status_ENUM status)
|
void E53_ST1_LED_StatusSet(E53ST1_Status_ENUM status)
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(ST1_LED_GPIO_Port, ST1_LED_Pin, status != ST1_ON ? GPIO_PIN_RESET : GPIO_PIN_SET );
|
HAL_GPIO_WritePin(ST1_LED_GPIO_Port, ST1_LED_Pin, status != ST1_ON ? GPIO_PIN_RESET : GPIO_PIN_SET );
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 函数名称: E53SF1_BEEP
|
* 函数名称: E53_ST1_Beep
|
||||||
* 说 明: E53SF1蜂鸣器报警与否
|
* 说 明: E53 ST1蜂鸣器报警与否
|
||||||
* 参 数: status,LED_ENUM枚举的数据
|
* 参 数: status,LED_ENUM枚举的数据
|
||||||
* LED_OFF,关灯
|
* LED_OFF,关灯
|
||||||
* LED_ON,开灯
|
* LED_ON,开灯
|
||||||
* 返 回 值: 无
|
* 返 回 值: 无
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
void E53_ST1_Beep(E53ST1_Status_ENUM status)
|
void E53_ST1_Beep(E53ST1_Status_ENUM status)
|
||||||
{
|
{
|
||||||
if(status == ST1_ON)
|
if(status == ST1_ON)
|
||||||
HAL_TIM_PWM_Start(&htim16,TIM_CHANNEL_1);
|
HAL_TIM_PWM_Start(&htim16,TIM_CHANNEL_1);
|
||||||
if(status == ST1_OFF)
|
if(status == ST1_OFF)
|
||||||
HAL_TIM_PWM_Stop(&htim16,TIM_CHANNEL_1);
|
HAL_TIM_PWM_Stop(&htim16,TIM_CHANNEL_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,13 +16,13 @@
|
|||||||
#define ST1_GPS_POW_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
#define ST1_GPS_POW_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* 名 称: GasStatus_ENUM
|
* 名 称: E53ST1_Status_ENUM
|
||||||
* 说 明:枚举状态结构体
|
* 说 明:枚举状态结构体
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
ST1_OFF = 0,
|
ST1_OFF = 0,
|
||||||
ST1_ON
|
ST1_ON
|
||||||
} E53ST1_Status_ENUM;
|
} E53ST1_Status_ENUM;
|
||||||
|
|
||||||
/***************************************************\
|
/***************************************************\
|
||||||
@@ -31,25 +31,25 @@ typedef enum
|
|||||||
\***************************************************/
|
\***************************************************/
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
{
|
{
|
||||||
uint32_t latitude_bd; //纬度 分扩大100000倍,实际要除以100000
|
uint32_t latitude_bd; //纬度 分扩大100000倍,实际要除以100000
|
||||||
uint8_t nshemi_bd; //北纬/南纬,N:北纬;S:南纬
|
uint8_t nshemi_bd; //北纬/南纬,N:北纬;S:南纬
|
||||||
uint32_t longitude_bd; //经度 分扩大100000倍,实际要除以100000
|
uint32_t longitude_bd; //经度 分扩大100000倍,实际要除以100000
|
||||||
uint8_t ewhemi_bd; //东经/西经,E:东经;W:西经
|
uint8_t ewhemi_bd; //东经/西经,E:东经;W:西经
|
||||||
}gps_msg;
|
}gps_msg;
|
||||||
|
|
||||||
/* E53_ST1传感器数据类型定义 ------------------------------------------------------------*/
|
/* E53_ST1传感器数据类型定义 ------------------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float Longitude; //经度
|
float Longitude; //经度
|
||||||
float Latitude; //纬度
|
float Latitude; //纬度
|
||||||
} E53_ST1_Data_TypeDef;
|
} E53_ST1_Data_TypeDef;
|
||||||
|
|
||||||
extern E53_ST1_Data_TypeDef E53_ST1_Data;
|
extern E53_ST1_Data_TypeDef E53_ST1_Data;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char Longitude[9]; //经度
|
char Longitude[9]; //经度
|
||||||
char Latitude[8]; //纬度
|
char Latitude[8]; //纬度
|
||||||
} E53_ST1_Send_TypeDef;
|
} E53_ST1_Send_TypeDef;
|
||||||
|
|
||||||
extern E53_ST1_Send_TypeDef E53_ST1_Send;
|
extern E53_ST1_Send_TypeDef E53_ST1_Send;
|
||||||
@@ -62,9 +62,5 @@ void E53_ST1_Read_Data(void);
|
|||||||
void E53_ST1_LED_StatusSet(E53ST1_Status_ENUM status);
|
void E53_ST1_LED_StatusSet(E53ST1_Status_ENUM status);
|
||||||
void E53_ST1_Beep(E53ST1_Status_ENUM status);
|
void E53_ST1_Beep(E53ST1_Status_ENUM status);
|
||||||
|
|
||||||
#endif
|
#endif /* __E53_ST1_H__ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ void mqtt_demo_task(void)
|
|||||||
printf("MQTT: %s\n", state == MQTT_STATE_CONNECTED ? "CONNECTED" : "DISCONNECTED");
|
printf("MQTT: %s\n", state == MQTT_STATE_CONNECTED ? "CONNECTED" : "DISCONNECTED");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>topic */
|
/* ¿ªÊ¼¶©ÔÄtopic */
|
||||||
size = snprintf(report_reply_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/down/property/%s/%s", product_id, device_name);
|
size = snprintf(report_reply_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/down/property/%s/%s", product_id, device_name);
|
||||||
|
|
||||||
if (size < 0 || size > sizeof(report_reply_topic_name) - 1) {
|
if (size < 0 || size > sizeof(report_reply_topic_name) - 1) {
|
||||||
@@ -78,7 +78,7 @@ void mqtt_demo_task(void)
|
|||||||
printf("module mqtt sub success\n");
|
printf("module mqtt sub success\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(report_topic_name, sizeof(report_topic_name), 0);
|
memset(report_topic_name, 0, sizeof(report_topic_name));
|
||||||
size = snprintf(report_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/up/property/%s/%s", product_id, device_name);
|
size = snprintf(report_topic_name, TOPIC_NAME_MAX_SIZE, "$thing/up/property/%s/%s", product_id, device_name);
|
||||||
|
|
||||||
if (size < 0 || size > sizeof(report_topic_name) - 1) {
|
if (size < 0 || size > sizeof(report_topic_name) - 1) {
|
||||||
@@ -88,7 +88,7 @@ void mqtt_demo_task(void)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
/* <EFBFBD>ϱ<EFBFBD>ֵ */
|
/* Éϱ¨Öµ */
|
||||||
memset(payload, 0, sizeof(payload));
|
memset(payload, 0, sizeof(payload));
|
||||||
snprintf(payload, sizeof(payload), REPORT_DATA_TEMPLATE, 30);
|
snprintf(payload, sizeof(payload), REPORT_DATA_TEMPLATE, 30);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user