Hi Robin, 1.Did you refer BMI160 driver code in github "https://github.com/BoschSensortec/BMI160_driver"? Yes, i use the lastest version of bmi160 driver. I remember there were examples of fifo settings. But now there are 3 examples, so the code of fifo setting i refer, is from other github repo. 2.For FIFO reading way: poll mode or FIFO watermark interrupt? I want to use FIFO watermark interrupt mode. The fifo setting function refer to below snap, more detail can refer: https://gist.github.com/ttn115/82ab37c0e0acf89587ca60dbee63d51a static void Spi_sensor_fifo_init( void ) {
/* You may assign a chip select identifier to be handled later */
s_spi_bmi160_sensor.id = 0 ;
s_spi_bmi160_sensor.interface = BMI160_SPI_INTF ;
s_spi_bmi160_sensor.read = Spi_read_transfer ;
s_spi_bmi160_sensor.write = Spi_write_transfer ;
s_spi_bmi160_sensor.delay_ms = Spi_delay_ms ;
int8_t rslt = BMI160_OK ;
rslt = bmi160_init( &s_spi_bmi160_sensor ) ;
if ( rslt == 0 ) {
SEGGER_RTT_printf( 0,"Get bmi160 data success ! \n", rslt ) ;
} // if
else
SEGGER_RTT_printf( 0,"Error : Get bmi160 data fail ! \n", rslt ) ;
/* After the above function call, accel_cfg and gyro_cfg parameters in the device
structure are set with default values, found in the datasheet of the sensor */
rslt = BMI160_OK ;
/* Select the Output data rate, range of accelerometer sensor */
s_spi_bmi160_sensor.accel_cfg.odr = BMI160_ACCEL_ODR_50HZ ;
s_spi_bmi160_sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G ;
s_spi_bmi160_sensor.accel_cfg.bw = BMI160_ACCEL_BW_OSR4_AVG1 ;
/* Select the power mode of accelerometer sensor */
s_spi_bmi160_sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE ;
/* Select the Output data rate, range of Gyroscope sensor */
s_spi_bmi160_sensor.gyro_cfg.odr = BMI160_GYRO_ODR_25HZ ;
s_spi_bmi160_sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS ;
s_spi_bmi160_sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE ;
/* Select the power mode of Gyroscope sensor */
s_spi_bmi160_sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE ;
/* Set the sensor configuration */
rslt = bmi160_set_sens_conf( &s_spi_bmi160_sensor ) ;
/* Select the power mode */
s_spi_bmi160_sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE ;
s_spi_bmi160_sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE ;
/* Set the Power mode */
rslt = bmi160_set_power_mode( &s_spi_bmi160_sensor ) ;
nrf_delay_ms( 10 ) ; // delay_10ms
rslt = start_foc(&s_spi_bmi160_sensor);
SEGGER_RTT_printf(0,"foc rslt=%d\n",rslt);
nrf_delay_ms(200);
struct bmi160_offsets sensor_offset;
rslt = bmi160_get_offsets(&sensor_offset,&s_spi_bmi160_sensor); //
SEGGER_RTT_printf(0,"calibration value: ax=%d,ay=%d,az=%d,gx=%d,gy=%d,gz=%d\n",sensor_offset.off_acc_x,sensor_offset.off_acc_y,sensor_offset.off_acc_z,sensor_offset.off_gyro_x,sensor_offset.off_gyro_y,sensor_offset.off_gyro_z);
/* Link the FIFO memory location */
fifo_frame.data = FIFO_BUFF;
fifo_frame.length = FIFO_LEN;
s_spi_bmi160_sensor.fifo = &fifo_frame;
/*Enable fifo*/
uint8_t fifo_config = BMI160_FIFO_HEADER | BMI160_FIFO_ACCEL | BMI160_FIFO_GYRO;
rslt = bmi160_set_fifo_config(fifo_config, BMI160_ENABLE, &s_spi_bmi160_sensor);
if (rslt != BMI160_OK)
{
SEGGER_RTT_printf(0,"BMI160 failed FIFO setting");
}
// instance for interrupt settings
struct bmi160_int_settg int_config;
int_config.int_channel = BMI160_INT_CHANNEL_1;
int_config.int_type = BMI160_ACC_GYRO_FIFO_WATERMARK_INT; // choose FIFO watermark IRQ (fires when a certain level of fullness is reached)
rslt = bmi160_set_fifo_wm((uint8_t) (FIFO_LEN - 20), &s_spi_bmi160_sensor);
if (rslt != BMI160_OK)
{
SEGGER_RTT_printf(0,"BMI160 failed FIFO wm setting");
}
int_config.int_pin_settg.output_en = BMI160_ENABLE; // enable output via INT_1 and INT_2 on BMI160
int_config.int_pin_settg.output_mode = BMI160_DISABLE; // push-pull mode
int_config.int_pin_settg.output_type = BMI160_ENABLE; // active high
int_config.int_pin_settg.edge_ctrl = BMI160_ENABLE; // edge-triggered
int_config.int_pin_settg.input_en = BMI160_DISABLE; // don't act as input
int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE; // non-latched output (no need to clear manually)
int_config.fifo_WTM_int_en = BMI160_ENABLE; // enable FIFO WM IRQ
rslt = bmi160_set_int_config(&int_config, &s_spi_bmi160_sensor);
if (rslt != BMI160_OK)
{
SEGGER_RTT_printf(0,"BMI160 failed IRQ config,rslt =%d\n",rslt);
}
} // Spi_sensor_fifo_init()
... View more