cun
This commit is contained in:
@ -266,7 +266,8 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
|
||||
// xlog("iic_tx_byte id\n");
|
||||
if (0 == iic_tx_byte(gSensor_info->iic_hdl, w_chip_id)) {
|
||||
ret = 0;
|
||||
xlog("\n gsen iic wr err 0\n");
|
||||
xlog("iic write: I2C NACK on writing ADDR: 0x%X\n", w_chip_id);
|
||||
// xlog("\n gsen iic wr err 0\n");
|
||||
strcpy(&w_log_buffer_1, "gsen iic wr err 0\n");
|
||||
goto __gcend;
|
||||
}
|
||||
@ -316,7 +317,7 @@ u8 _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, u8 data
|
||||
|
||||
iic_start(gSensor_info->iic_hdl);
|
||||
if (0 == iic_tx_byte(gSensor_info->iic_hdl, r_chip_id - 1)) {
|
||||
xlog("I2C NACK on writing ADDR: 0x%X\n", r_chip_id - 1);
|
||||
xlog("iic read: I2C NACK on writing ADDR: 0x%X\n", r_chip_id - 1);
|
||||
read_len = 0;
|
||||
strcpy(&sen_log_buffer_1, "gsen iic rd err 0\n");
|
||||
goto __gdend;
|
||||
|
||||
@ -469,8 +469,8 @@ void test_func(void){
|
||||
acc_data_buf[i] = i;
|
||||
}
|
||||
|
||||
SL_SC7U22_Config();
|
||||
mmc5603nj_init();
|
||||
// SL_SC7U22_Config();
|
||||
// mmc5603nj_init();
|
||||
#if BMP280
|
||||
BMP280_init();
|
||||
#else
|
||||
|
||||
@ -23,17 +23,78 @@ static int32_t c00, c10;
|
||||
/*==================================================================================*/
|
||||
/* 封装的底层I2C读写函数 (Provided by user) */
|
||||
/*==================================================================================*/
|
||||
#define I2C_HANDLE 0
|
||||
/**
|
||||
* @brief 写入单个字节到WF282A寄存器
|
||||
*/
|
||||
static void wf282a_write_reg(uint8_t reg, uint8_t data) {
|
||||
gravity_sensor_command(WF_IIC_WRITE_ADDRESS, reg, data);
|
||||
hw_iic_start(I2C_HANDLE);
|
||||
// 发送从设备地址 (写模式)
|
||||
if (!hw_iic_tx_byte(I2C_HANDLE, WF_IIC_WRITE_ADDRESS)) {
|
||||
// 如果没有收到ACK,可能是设备不存在或忙,直接停止
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
// 可以添加错误日志或返回错误码
|
||||
xlog("WF282A Write: No ACK after slave address\n");
|
||||
return;
|
||||
}
|
||||
// 发送寄存器地址
|
||||
if (!hw_iic_tx_byte(I2C_HANDLE, reg)) {
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
xlog("WF282A Write: No ACK after register address\n");
|
||||
return;
|
||||
}
|
||||
// 发送数据字节
|
||||
if (!hw_iic_tx_byte(I2C_HANDLE, data)) {
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
xlog("WF282A Write: No ACK after data byte\n");
|
||||
return;
|
||||
}
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
|
||||
// gravity_sensor_command(WF_IIC_WRITE_ADDRESS, reg, data);
|
||||
}
|
||||
/**
|
||||
* @brief 从WF282A读取多个字节
|
||||
*/
|
||||
static uint32_t wf282a_read_regs(uint8_t reg, uint8_t *buf, uint8_t len) {
|
||||
return _gravity_sensor_get_ndata(WF_IIC_READ_ADDRESS, reg, buf, len);
|
||||
uint32_t bytes_read = 0;
|
||||
if (len == 0) return 0;
|
||||
|
||||
hw_iic_start(I2C_HANDLE);
|
||||
// 1. 发送从设备地址 (写模式) 和寄存器地址
|
||||
if (!hw_iic_tx_byte(I2C_HANDLE, WF_IIC_WRITE_ADDRESS)) {
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
xlog("WF282A Read: No ACK after slave address (write phase)\n");
|
||||
return 0;
|
||||
}
|
||||
if (!hw_iic_tx_byte(I2C_HANDLE, reg)) {
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
xlog("WF282A Read: No ACK after register address\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 2. 发送重复开始条件
|
||||
hw_iic_start(I2C_HANDLE); // Repeated START
|
||||
|
||||
// 3. 发送从设备地址 (读模式)
|
||||
if (!hw_iic_tx_byte(I2C_HANDLE, WF_IIC_READ_ADDRESS)) {
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
xlog("WF282A Read: No ACK after slave address (read phase)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 4. 循环读取数据
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
// 如果是最后一个字节,发送NACK
|
||||
// hw_iic_rx_byte 的第二个参数是 ack_enable (1 for ACK, 0 for NACK)
|
||||
uint8_t ack_val = (i == (len - 1)) ? 0 : 1; // 最后一个字节NACK,其余ACK
|
||||
buf[i] = hw_iic_rx_byte(I2C_HANDLE, ack_val);
|
||||
bytes_read++;
|
||||
}
|
||||
|
||||
hw_iic_stop(I2C_HANDLE);
|
||||
return bytes_read;
|
||||
// return _gravity_sensor_get_ndata(WF_IIC_READ_ADDRESS, reg, buf, len);
|
||||
}
|
||||
/*==================================================================================*/
|
||||
/* Delay functions (Copied from manufacturer's code for consistency) */
|
||||
@ -51,22 +112,26 @@ static void parse_calibration_data(const uint8_t *buf) {
|
||||
// c0 (12-bit)
|
||||
// 制造商: (tempbuf[0]<<4) + ((tempbuf[1]>>4) & 0x0F);
|
||||
c0 = ((int16_t)buf[0] << 4) | ((buf[1] >> 4) & 0x0F);
|
||||
if (c0 & (1 << 11)) c0 |= 0xF000;
|
||||
// if (c0 & (1 << 11)) c0 |= 0xF000;
|
||||
if(c0 > 0x7ff) c0 = c0 - 0x1000;
|
||||
|
||||
// c1 (12-bit)
|
||||
// 制造商: tempbuf[2] + ((tempbuf[1] & 0x0F)<<8);
|
||||
c1 = (((int16_t)buf[1] & 0x0F) << 8) | buf[2];
|
||||
if (c1 & (1 << 11)) c1 |= 0xF000;
|
||||
// if (c1 & (1 << 11)) c1 |= 0xF000;
|
||||
if(c1 > 0x7ff) c1 = c1 -0x1000;
|
||||
|
||||
// c00 (20-bit)
|
||||
// 制造商: (((u32)((tempbuf[3]<<8) + tempbuf[4]))<<4)+((tempbuf[5]>>4)&0x0F);
|
||||
c00 = ((int32_t)buf[3] << 12) | ((int32_t)buf[4] << 4) | ((buf[5] >> 4) & 0x0F);
|
||||
if (c00 & (1 << 19)) c00 |= 0xFFF00000;
|
||||
// if (c00 & (1 << 19)) c00 |= 0xFFF00000;
|
||||
if(c00 > 0x7ffff) c00 = c00 - 0x100000;
|
||||
|
||||
// c10 (20-bit)
|
||||
// 制造商: (((u32)((tempbuf[5]&0x0F)<<8)+tempbuf[6])<<8)+tempbuf[7];
|
||||
c10 = (((int32_t)buf[5] & 0x0F) << 16) | ((int32_t)buf[6] << 8) | buf[7];
|
||||
if (c10 & (1 << 19)) c10 |= 0xFFF00000;
|
||||
// if (c10 & (1 << 19)) c10 |= 0xFFF00000;
|
||||
if(c10 > 0x7ffff) c10 = c10 - 0x100000;
|
||||
|
||||
// c01, c11, c20, c21, c30 (16-bit)
|
||||
c01 = (int16_t)((uint16_t)buf[8] << 8 | buf[9]);
|
||||
@ -95,9 +160,10 @@ static int32_t Get_Traw() {
|
||||
// buff[0] = B2 (MSB), buff[1] = B1, buff[2] = B0 (LSB)
|
||||
Traw = (int32_t)buff[0] << 16 | (int32_t)buff[1] << 8 | (int32_t)buff[2];
|
||||
// 24位二进制补码转32位
|
||||
if (Traw & (1 << 23)) {
|
||||
Traw |= 0xFF000000;
|
||||
}
|
||||
// if (Traw & (1 << 23)) {
|
||||
// Traw |= 0xFF000000;
|
||||
// }
|
||||
if(Traw > 0x7fffff) Traw = Traw - 0x1000000;
|
||||
return Traw;
|
||||
}
|
||||
/**
|
||||
@ -114,10 +180,11 @@ static int32_t Get_Praw() {
|
||||
}
|
||||
// buff[0] = B2 (MSB), buff[1] = B1, buff[2] = B0 (LSB)
|
||||
Praw = (int32_t)buff[0] << 16 | (int32_t)buff[1] << 8 | (int32_t)buff[2];
|
||||
// 24位二进制补码转32位
|
||||
if (Praw & (1 << 23)) {
|
||||
Praw |= 0xFF000000;
|
||||
}
|
||||
// // 24位二进制补码转32位
|
||||
// if (Praw & (1 << 23)) {
|
||||
// Praw |= 0xFF000000;
|
||||
// }
|
||||
if(Praw > 0x7fffff) Praw = Praw - 0x1000000;
|
||||
return Praw;
|
||||
}
|
||||
/*==================================================================================*/
|
||||
@ -125,21 +192,21 @@ static int32_t Get_Praw() {
|
||||
/*==================================================================================*/
|
||||
uint8_t WF_Init() {
|
||||
uint8_t calib_buf[18];
|
||||
xlog("WF282A: soft reset\n");
|
||||
// 1. 软复位
|
||||
wf282a_write_reg(WF_RESET_REG, 0x09);
|
||||
delay(100); // 复位后等待100ms
|
||||
delay(1000); // 复位后等待1000ms
|
||||
// 2. 读取校准系数
|
||||
if (wf282a_read_regs(COEF_C0, calib_buf, 18) != 18) { // 检查是否成功读取18字节
|
||||
xlog("Failed to read the calibration coefficient\n");
|
||||
return 2; // 读取校准数据失败
|
||||
}
|
||||
parse_calibration_data(calib_buf);
|
||||
|
||||
// DEBUG: 打印解析后的校准系数
|
||||
xlog("Parsed Coefficients: c0=%d, c1=%d, c00=%ld, c10=%ld, c01=%d, c11=%d, c20=%d, c21=%d, c30=%d\n",
|
||||
c0, c1, c00, c10, c01, c11, c20, c21, c30);
|
||||
|
||||
#if 0 //test:0
|
||||
#if 1 //连续测量
|
||||
// 3. 配置压力、温度和通用寄存器为连续测量模式
|
||||
// 压力配置: 32Hz测量速率 (PM_RATE_32), 16x过采样 (PM_PRC_16) -> 0x54
|
||||
wf282a_write_reg(WF_PRS_CFG, (PM_RATE_32 << 4) | PM_PRC_16);
|
||||
@ -159,7 +226,7 @@ uint8_t WF_Init() {
|
||||
wf282a_write_reg(WF_PRS_CFG, 0x07);
|
||||
wf282a_write_reg(WF_TMP_CFG, 0x87);
|
||||
wf282a_write_reg(WF_CFG_REG, 0x0C);
|
||||
wf282a_write_reg(WF_MEAS_CFG, 0x07);//后台连续测量温度和压力
|
||||
// wf282a_write_reg(WF_MEAS_CFG, 0x07);//后台连续测量温度和压力
|
||||
delay(40); // 稍长一点的延迟,确保传感器开始正常工作
|
||||
#endif
|
||||
|
||||
@ -204,7 +271,17 @@ float WF_Pressure_Calculate() {
|
||||
+ Traw_sc * Praw_sc * ((float)c11 + Praw_sc * (float)c21);
|
||||
return Pcomp;
|
||||
}
|
||||
|
||||
//非连续测量
|
||||
void WF_start_measure(void){
|
||||
wf282a_write_reg(WF_MEAS_CFG, 0x02); //进行一次温度测量
|
||||
delay(200);
|
||||
wf282a_write_reg(WF_MEAS_CFG, 0x01); //内部进行一次压力测量
|
||||
delay(200);
|
||||
}
|
||||
|
||||
void WF_GET_Temperature_Pressure(float* temperature, float* precessure){
|
||||
// WF_start_measure();
|
||||
int32_t Traw = Get_Traw();
|
||||
int32_t Praw = Get_Praw();
|
||||
float Traw_sc = (float)Traw / KT; // 缩放原始温度值 (KT is now 16x scale factor)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -10,7 +10,7 @@ copy ..\..\ota.bin .
|
||||
copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key AC69.key -format all -key 646-AC690X-7603.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -format all
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
Binary file not shown.
@ -5393,8 +5393,6 @@ objs/apps/earphone/xtell_Sensor/send_data.c.o
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,test_uart_init,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,sensor_test_task,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,test_func,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,SL_SC7U22_Config,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,mmc5603nj_init,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,WF_Init,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,puts,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/send_data.c.o,j,pl
|
||||
@ -5513,18 +5511,21 @@ objs/apps/earphone/xtell_Sensor/sensor/AK8963.c.o
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/AK8963.c.o,puts,l
|
||||
objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Init,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,delay,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,printf,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,delay,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_GetID,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Sleep,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Wakeup,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Temperature_Calculate,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Pressure_Calculate,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_start_measure,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_GET_Temperature_Pressure,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,WF_Altitude_Calculate,pl
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,powf,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,gravity_sensor_command,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,_gravity_sensor_get_ndata,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,hw_iic_start,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,hw_iic_tx_byte,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,hw_iic_stop,l
|
||||
-r=objs/apps/earphone/xtell_Sensor/sensor/WF282A.c.o,hw_iic_rx_byte,l
|
||||
cpu/br28/liba/cpu.a.llvm.19376.crc16.c
|
||||
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,__crc16_mutex_init,pl
|
||||
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,os_mutex_create,l
|
||||
|
||||
Reference in New Issue
Block a user