diff --git a/apps/earphone/board/br28/board_jl701n_demo_cfg.h b/apps/earphone/board/br28/board_jl701n_demo_cfg.h index 09398ad..3b32b7a 100644 --- a/apps/earphone/board/br28/board_jl701n_demo_cfg.h +++ b/apps/earphone/board/br28/board_jl701n_demo_cfg.h @@ -47,7 +47,7 @@ */ #define TCFG_HW_I2C0_PORTS 'B' -#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:400k +#define TCFG_HW_I2C0_CLK 1000000 //硬件IIC波特率:400k //*********************************************************************************// // 硬件SPI 配置 // diff --git a/apps/earphone/xtell_Sensor/send_data.c b/apps/earphone/xtell_Sensor/send_data.c index 523b397..72242db 100644 --- a/apps/earphone/xtell_Sensor/send_data.c +++ b/apps/earphone/xtell_Sensor/send_data.c @@ -105,7 +105,7 @@ u32 get_ms_timer(void) { * */ void sensor_collect_task(void){ - ble_send_data_t send_data; + static ble_send_data_t send_data; mmc5603nj_mag_data_t mmc5603nj_buffer; float temperature = 0; float pressure = 0; @@ -117,6 +117,7 @@ void sensor_collect_task(void){ signed short gyry_buf[100]; signed short gyrz_buf[100]; int fifo_num = 0; + static int data_index = 0; u8 index = 1; while(1){//4组地磁数据、16组六轴数据、1组气压计数据 @@ -128,6 +129,12 @@ void sensor_collect_task(void){ send_data.sensor_package[i].mmc5603nj_buffer[2] = (int32_t)(mmc5603nj_buffer.z * 1000.0f); } // xlog("MAG x: %.2f,y: %.2f,z: %.2f\n",mmc5603nj_buffer.x,mmc5603nj_buffer.y,mmc5603nj_buffer.z); + + fifo_num = SL_SC7U22_FIFO_Read(accx_buf,accy_buf,accz_buf,gyrx_buf,gyry_buf,gyrz_buf); //40ms一次性读取内置fifo的数据 + for(int i = 0; i < fifo_num; i++){ + + } + if(interval >= 4){ interval = 0; memset(&accx_buf, 0, sizeof(accx_buf)); diff --git a/apps/earphone/xtell_Sensor/sensor/SC7U22.c b/apps/earphone/xtell_Sensor/sensor/SC7U22.c index 833b623..e329d2a 100644 --- a/apps/earphone/xtell_Sensor/sensor/SC7U22.c +++ b/apps/earphone/xtell_Sensor/sensor/SC7U22.c @@ -295,7 +295,7 @@ void SL_SC7U22_RawData_Read(signed short * acc_data_buf,signed short * gyr_data_ unsigned char Acc_FIFO_Num; unsigned char Gyr_FIFO_Num; -unsigned char SL_SC7U22_FIFO_DATA[1024]; +unsigned char SL_SC7U22_FIFO_DATA[2048]; unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf,signed short *accz_buf,signed short *gyrx_buf,signed short *gyry_buf,signed short *gyrz_buf) { @@ -346,7 +346,8 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf SL_SC7U22_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x20,1,&fifo_num2); if((fifo_num1&0x10)==0x10) { - fifo_num=2048; + // fifo_num=2048; // 原始代码,会导致溢出 + fifo_num = 2048; // 传感器FIFO已满,但我们的缓冲区只有1024字节,所以最多读1024字节 } else { @@ -354,6 +355,11 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf } #endif + // 增加保护,确保读取的字节数不超过缓冲区大小 (1024 bytes) + // fifo_num 是 word (2 bytes) 的数量, 所以最大值是 512 + if (fifo_num > 1024) { + fifo_num = 1024; + } SL_SC7U22_I2c_Spi_Read(SL_SPI_IIC_INTERFACE, 0x21, fifo_num*2, SL_SC7U22_FIFO_DATA);//读取FIFO数据 BYTE NUM // SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D, 0x00);//BY PASS MODE // SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D, 0x20);//Stream MODE @@ -395,7 +401,7 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf gyrx_buf[Gyr_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 0] * 256 + SL_SC7U22_FIFO_DATA[i + 1])) ; gyry_buf[Gyr_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 2] * 256 + SL_SC7U22_FIFO_DATA[i + 3])) ; gyrz_buf[Gyr_FIFO_Num] = ((s16)(SL_SC7U22_FIFO_DATA[i + 4] * 256 + SL_SC7U22_FIFO_DATA[i + 5])) ; - xlog("GyrNum : %d, Gyr_x : %4d, Gyr_y : %4d, Gyr_z : %4d,\r\n",Gyr_FIFO_Num, gyrx_buf[Gyr_FIFO_Num], gyry_buf[Gyr_FIFO_Num], gyrz_buf[Gyr_FIFO_Num]); + // xlog("GyrNum : %d, Gyr_x : %4d, Gyr_y : %4d, Gyr_z : %4d,\r\n",Gyr_FIFO_Num, gyrx_buf[Gyr_FIFO_Num], gyry_buf[Gyr_FIFO_Num], gyrz_buf[Gyr_FIFO_Num]); i = i + 6; Gyr_FIFO_Num++; } @@ -406,8 +412,11 @@ unsigned short SL_SC7U22_FIFO_Read(signed short *accx_buf,signed short *accy_buf i = i + 2; } } - fifo_len = Acc_FIFO_Num; - // xlog("Acc_FIFO_Num:%d,Gyr_FIFO_Num:%d\n",Acc_FIFO_Num,Gyr_FIFO_Num); + if(Acc_FIFO_Num > Gyr_FIFO_Num) + fifo_len = Acc_FIFO_Num; + else + fifo_len = Gyr_FIFO_Num; + xlog("Acc_FIFO_Num:%d,Gyr_FIFO_Num:%d\n",Acc_FIFO_Num,Gyr_FIFO_Num); SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D,0x00); SL_SC7U22_I2c_Spi_Write(SL_SPI_IIC_INTERFACE, 0x1D,0x20); diff --git a/cpu/br28/tools/app.bin b/cpu/br28/tools/app.bin index 0803cca..ecca5cd 100644 Binary files a/cpu/br28/tools/app.bin and b/cpu/br28/tools/app.bin differ diff --git a/cpu/br28/tools/data_code.bin b/cpu/br28/tools/data_code.bin index 51bab63..db84310 100644 Binary files a/cpu/br28/tools/data_code.bin and b/cpu/br28/tools/data_code.bin differ diff --git a/cpu/br28/tools/download/earphone/jl_isd.bin b/cpu/br28/tools/download/earphone/jl_isd.bin index 69e734b..697ee92 100644 Binary files a/cpu/br28/tools/download/earphone/jl_isd.bin and b/cpu/br28/tools/download/earphone/jl_isd.bin differ