#include "hp203b.h" #include "i2c.h" #include "filter.h" #include "anemometer_dev.h" /**************************** *名称:set_mode *功能:配置从机模式,设置通道及采样率 *参数:无 * * *返回:无 *****************************/ void hp203_set_mode() { uint8_t cmd[1] = {HP20X_CONVERT_OSR1024}; HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, cmd, 1, 0xff); } /**************************** *名称:Hp203bReadPressure *功能:获取气压数据 *参数:Press--气压值 * * *返回:无 *****************************/ float Hp203bReadPressure(void) { float ret = 0.0; long Hp203b_Pressure = 0; uint8_t Hp203bPressure_Temp[3] = {0}; uint8_t read_command[1] = {HP20X_READ_P}; HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff); HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff); Hp203b_Pressure = Hp203bPressure_Temp[0]; Hp203b_Pressure <<= 8; Hp203b_Pressure |= Hp203bPressure_Temp[1]; Hp203b_Pressure <<= 8; Hp203b_Pressure |= Hp203bPressure_Temp[2]; Hp203b_Pressure = Hp203b_Pressure / 100; ret = Hp203b_Pressure; return ret; } /**************************** *名称:get_press_data *功能:获取气压数据 *参数:Press--气压值 * * *返回:无 *****************************/ #define COLLECT_PRESS_DATA_NUM 10 BOOL get_press_data(void) { U_DataType collect_pressure[30]={0x00}; for(int i=0; i 1200) { tmp_press.fValue = 1200; return FALSE; } g_stMcs_Para.pressure = tmp_press.fValue; return TRUE; }