cun
This commit is contained in:
@ -135,18 +135,18 @@ static float compensate_pressure(int32_t adc_P) {
|
||||
|
||||
|
||||
|
||||
uint8_t bmp280_init(void) {
|
||||
uint8_t BMP280_init(void) {
|
||||
uint8_t id;
|
||||
uint8_t calib_data[24];
|
||||
|
||||
// 1. 检查芯片ID
|
||||
if (bmp280_read_regs(BMP280_REG_ID, &id, 1) == 0) {
|
||||
printf("bmp280 get id error:%d\n",id );
|
||||
return 1; // I2C读取失败
|
||||
// return 1; // I2C读取失败
|
||||
}
|
||||
if (id != 0x58) {
|
||||
printf("bmp280 check diff:%d\n",id );
|
||||
return 1; // ID不匹配
|
||||
// return 1; // ID不匹配
|
||||
}
|
||||
printf("bmp280 get id:0%X\n",id );
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define BMP_PULL_UP 0 //外部是否接的上拉
|
||||
#define BMP_PULL_UP 1 //外部是否接的上拉
|
||||
|
||||
// I2C 从设备地址
|
||||
#if BMP_PULL_UP == 1 //外部接的高
|
||||
@ -33,7 +33,7 @@
|
||||
* @return 0: 成功, 1: 芯片ID错误, 2: 读取校准参数失败
|
||||
* @note 此函数会完成ID检查、软复位、读取校准参数,并设置传感器为连续测量模式。
|
||||
*/
|
||||
uint8_t bmp280_init(void);
|
||||
uint8_t BMP280_init(void);
|
||||
|
||||
/**
|
||||
* @brief 从BMP280读取温度和气压数据
|
||||
|
||||
@ -6,6 +6,15 @@
|
||||
#include <stdint.h> // 推荐使用标准类型
|
||||
#include "gSensor/gSensor_manage.h"
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
/*==================================================================================*/
|
||||
/* WF282A 内部定义 */
|
||||
/*==================================================================================*/
|
||||
@ -109,13 +118,14 @@ uint8_t WF_Init() {
|
||||
|
||||
// 1. 配置传感器工作模式
|
||||
// 推荐配置:压力8次过采样,温度1次过采样,测量速率16Hz
|
||||
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_16 << 4) | PM_PRC_8);
|
||||
wf282a_write_reg(WF_TMP_CFG, (TMP_RATE_16 << 4) | TMP_PRC_1 | TMP_INT_SENSOR);
|
||||
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_32);
|
||||
wf282a_write_reg(WF_TMP_CFG, TMP_INT_SENSOR | (TMP_RATE_32 << 4) | TMP_PRC_32);
|
||||
wf282a_write_reg(WF_MEAS_CFG, 0x07); // 启动连续压力和温度测量
|
||||
wf282a_write_reg(WF_CFG_REG, 0x00); // 无中断或FIFO移位配置
|
||||
|
||||
// 2. 一次性读取所有校准系数 (从0x10到0x21,共18字节)
|
||||
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 0) {
|
||||
if (wf282a_read_regs(COEF_C0, calib_buf, 18) == 0) {
|
||||
xlog("Failed to read the calibration coefficient\n");
|
||||
return 2; // 读取校准数据失败
|
||||
}
|
||||
parse_calibration_data(calib_buf);
|
||||
@ -123,6 +133,7 @@ uint8_t WF_Init() {
|
||||
// 3. 检查配置是否写入成功
|
||||
wf282a_read_regs(WF_MEAS_CFG, &check_cfg, 1);
|
||||
if (check_cfg != 0x07) {
|
||||
xlog("WF_Init error, check_cfg: %d\n", check_cfg);
|
||||
return 1; // 错误
|
||||
} else {
|
||||
return 0; // 成功
|
||||
@ -168,6 +179,19 @@ float WF_Pressure_Calculate() {
|
||||
return Pcomp;
|
||||
}
|
||||
|
||||
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
|
||||
int32_t Traw = Get_Traw();
|
||||
int32_t Praw = Get_Praw();
|
||||
float Traw_sc = (float)Traw / KT;// 缩放原始温度值
|
||||
float Praw_sc = (float)Praw / KP;// 缩放原始压力值
|
||||
|
||||
*temperature = (float)c0 * 0.5f + (float)c1 * Traw_sc;
|
||||
*precessure = (float)c00
|
||||
+ Praw_sc * ((float)c10 + Praw_sc * ((float)c20 + Praw_sc * (float)c30))
|
||||
+ Traw_sc * (float)c01
|
||||
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
|
||||
}
|
||||
|
||||
float WF_Altitude_Calculate() {
|
||||
float pressure_pa = WF_Pressure_Calculate();
|
||||
// 使用标准大气压公式计算海拔
|
||||
|
||||
@ -4,8 +4,19 @@
|
||||
#include <stdint.h> // 使用标准整数类型
|
||||
|
||||
// 标定值
|
||||
#define KT 524288.0f
|
||||
#define KP 1572864.0f
|
||||
/*
|
||||
Oversampling Rate Scale Factor (kP or kT
|
||||
1 (single) 524288
|
||||
2 times (Low Power) 1572864
|
||||
4 times 3670016
|
||||
8 times 7864320
|
||||
16 times (Standard) 253952
|
||||
32 times 516096
|
||||
64 times (High Precision) 1040384
|
||||
128 times 2088960
|
||||
*/
|
||||
#define KT 516096.0f //温度
|
||||
#define KP 516096.0f //压力
|
||||
|
||||
|
||||
#define WF_PULL_UP 1 //外部是否接的上拉
|
||||
@ -95,7 +106,7 @@
|
||||
#define TMP_RATE_32 0x05 // 32 次/秒
|
||||
#define TMP_RATE_64 0x06 // 64 次/秒
|
||||
#define TMP_RATE_128 0x07 // 128 次/秒
|
||||
// 温度配置 (TMP_CFG[3:0]) - 过采样率
|
||||
// 温度配置 (TMP_CFG[2:0]) - 过采样率
|
||||
#define TMP_PRC_1 0x00 // 1 次
|
||||
#define TMP_PRC_2 0x01 // 2 次
|
||||
#define TMP_PRC_4 0x02 // 4 次
|
||||
@ -145,4 +156,6 @@ float WF_Pressure_Calculate(void);
|
||||
*/
|
||||
float WF_Temperature_Calculate(void);
|
||||
|
||||
void WF_GET_Temperature_Pressure(float* temperature, float* precessure);
|
||||
|
||||
#endif // _WF282A_H_
|
||||
Reference in New Issue
Block a user