03-30-2022 04:28 PM
Hi there,
I run into a problem where the int_fwm_en bit is constantly set even after emptying the contents of the fifo.
No ISR routine is used yet so the code polls for any motion or fifo watermark flags (via I2C) to reguarly (once per second) empty the fifo contents.
What I can see on the scope is that the watermark interrupt is continously triggerd (high). I expect that the bug is in the setup of the bmx160 code as shown here below. I use a stm32 nucleo board for testing.
The code that I use is here below,
Any help is greatly appriciated
Thanks!
André
struct bmi160_int_settg int_config;
uint8_t rslt;
dev->intf = BMI160_I2C_INTF;
dev->id = BMI160_I2C_ADDR;
dev->read = SensorAPI_I2Cx_Read;
dev->write = SensorAPI_I2Cx_Write;
dev->delay_ms = HAL_Delay;
dev->read_write_len = 32;
rslt = bmi160_soft_reset(dev);
dev->delay_ms(200);
bmi160_init(dev);
dev->accel_cfg.odr = BMI160_ACCEL_ODR_200HZ;
dev->accel_cfg.range = BMI160_ACCEL_RANGE_2G;
dev->accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
dev->gyro_cfg.power = BMI160_GYRO_SUSPEND_MODE;
bmi160_set_sens_conf(dev);
fifo_frame.data = fifo_buff;
fifo_frame.length = 1024;
dev->fifo = &fifo_frame;
/* Clear FIFO configuration register */
bmi160_set_fifo_config(BMI160_FIFO_CONFIG_1_MASK, BMI160_DISABLE, dev);
bmi160_set_fifo_wm(20, dev);
bmi160_set_fifo_config(BMI160_FIFO_A_ENABLE /*|BMI160_FIFO_TIME_ENABLE*/ |BMI160_FIFO_TAG_INT2, BMI160_ENABLE, dev);
bmi160_set_fifo_flush(dev);
int_config.int_channel = BMI160_INT_CHANNEL_2;
int_config.int_type = BMI160_ACC_GYRO_FIFO_WATERMARK_INT;
int_config.int_pin_settg.output_en = BMI160_ENABLE; /* Enabling interrupt pins to act as output pin */
int_config.int_pin_settg.output_mode = BMI160_DISABLE; /* Choosing push-pull mode for interrupt pin */
int_config.int_pin_settg.output_type = BMI160_ENABLE; /* Choosing active low output */
int_config.int_pin_settg.edge_ctrl = BMI160_DISABLE; /* Choosing edge triggered output */
int_config.int_pin_settg.input_en = BMI160_DISABLE; /* Disabling interrupt pin to act as input */
int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_10_MILLI_SEC; /* non-latched output */
int_config.fifo_wtm_int_en = BMI160_ENABLE;
bmi160_set_int_config(&int_config, dev);
int_config.int_type = BMI160_ACC_ANY_MOTION_INT;
int_config.int_channel = BMI160_INT_CHANNEL_1;
int_config.int_pin_settg.output_en = BMI160_ENABLE; /* Enabling interrupt pins to act as output pin */
int_config.int_pin_settg.output_mode = BMI160_DISABLE; /* Choosing push-pull mode for interrupt pin */
int_config.int_pin_settg.output_type = BMI160_ENABLE; /* Choosing active low output */
int_config.int_pin_settg.edge_ctrl = BMI160_DISABLE; /* Choosing edge triggered output */
int_config.int_pin_settg.input_en = BMI160_DISABLE; /* Disabling interrupt pin to act as input */
int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_320_MILLI_SEC; /* non-latched output */
int_config.int_type_cfg.acc_any_motion_int.anymotion_en = BMI160_ENABLE; // 1- Enable the any-motion, 0- disable any-motion
int_config.int_type_cfg.acc_any_motion_int.anymotion_x = BMI160_ENABLE; // Enabling x-axis for any motion interrupt
int_config.int_type_cfg.acc_any_motion_int.anymotion_y = BMI160_ENABLE; // Enabling y-axis for any motion interrupt
int_config.int_type_cfg.acc_any_motion_int.anymotion_z = BMI160_ENABLE; // Enabling z-axis for any motion interrupt
int_config.int_type_cfg.acc_any_motion_int.anymotion_dur = 1; // any-motion duration
int_config.int_type_cfg.acc_any_motion_int.anymotion_thr = 1;
int_config.int_type_cfg.acc_any_motion_int.anymotion_thr = 0x80;
bmi160_set_int_config(&int_config, dev);
uint8_t reg_data, samples_count=0;
for(;;)
{
memset(int_status.data, 0x00, sizeof(int_status.data));
bmi160_get_int_status(BMI160_INT_STATUS_ALL, &int_status, dev);
if(int_status.bit.fwm )
{
acc_frames_req = 50;
/* disable fifo watermark otherwise the BMX160 can generate interrupts while reading the fifo */
disable_fifo_watermark_interrupt(dev);
while(acc_frames_req>0) {
rslt = bmi160_get_fifo_data(dev);
print_bmi160_rslt(rslt);
//PDEBUG("Fifo length:%d\r\n", dev->fifo->length);
if(rslt == BMI160_OK)
{
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
rslt = bmi160_extract_accel(fifo_acc_data, &acc_frames_req, dev);
if (rslt == BMI160_OK)
{
PDEBUG("Parsed accelerometer data frames: %d\r\n", acc_frames_req);
/* Print the parsed accelerometer data from the FIFO buffer */
for(bmi160_fifo_idx = 0 ; bmi160_fifo_idx < acc_frames_req ; bmi160_fifo_idx++)
{
samples_count++;
PDEBUG("ACCEL[%d] x=%d y=%d z=%d time=%x\r\n", bmi160_fifo_idx , fifo_acc_data[bmi160_fifo_idx].x, fifo_acc_data[bmi160_fifo_idx].y, fifo_acc_data[bmi160_fifo_idx].z,
fifo_acc_data[bmi160_fifo_idx].sensortime);
}
} else {
PDEBUG("bmi160_extract_accel ERROR rslt=%d\r\n", rslt);
}
}
}
enable_fifo_watermark_interrupt(dev);
}
HAL_Delay(1000);
}
Solved! Go to Solution.
03-30-2022 04:42 PM - edited 03-30-2022 04:43 PM
03-31-2022 07:55 PM
i found the error in my own code 😕 ... I kept reading the fifo in small chunks without checking the watermark flag in the bmx160 itself.