Can not read from bmi160's fifo

Hi,

We have design a custom board that can read single frame from bmi160 without problems,

Now we want to read more imu data, so we modify the bmi160 and mcu setting.

Using WM trigger to triiger bmi160_get_fifo_data() function, but i got an error return 11(Hex).

which is #define BMI160_FOC_FAILURE INT8_C(-11), but the error can't be fix by calling rslt = start_foc(&s_spi_bmi160_sensor);

i read the datasheet and the repo from github:

https://github.com/piMagpie/IoT/blob/2fd729ea7dd2e3afe2a169f9798d4ef98656b70b/last Project/ble_app_uart/main.c

/mems-sensors-forum-jrmujtaw/post/bmi160-fifo-readings-are-not-updating-data-EivJRftdPBHrMlL

https://github.com/haleighdefoor/GroupDelta_Project2/blob/e4c4336ee705ffa792350caaaf5b5f18c2e14862/Labsolutions_1_1/Lab21_BMI160_TestMain.c 

/knowledge-base-pg631enp/post/bmi160-fifo-advanced-usage-n7HOuG4Le1uKOSU 

and compare the setting with these github repo with my code, still can't figure out why and how to fix it.

here is snip from my code:

https://gist.github.com/ttn115/82ab37c0e0acf89587ca60dbee63d51a 

Please help me to fix the problem, thanks.

 

 

 

Best reply by BSTRobin

Hello TTN,

1.I setup SW demo on MCU,  you could refer attachment example code to run FIFO poll read, FIFO watermark interrupt read.

2. For how to extract sensor time in FIFO, you could refer the following driver code in BMI160 sensor API.

static void extract_accel_header_mode(struct bmi160_sensor_data *accel_data, uint8_t *accel_length, const struct bmi160_dev *dev)

{

...

/* Sensor time frame */
case BMI160_FIFO_HEAD_SENSOR_TIME:
unpack_sensortime_frame(&data_index, dev);
break;

...

}

/*!
* @brief This API is used to parse and store the sensor time from the
* FIFO data in the structure instance dev.
*/
static void unpack_sensortime_frame(uint16_t *data_index, const struct bmi160_dev *dev)
{
uint32_t sensor_time_byte3 = 0;
uint16_t sensor_time_byte2 = 0;
uint8_t sensor_time_byte1 = 0;

/*Partial read, then move the data index to last data*/
if ((*data_index + BMI160_SENSOR_TIME_LENGTH) > dev->fifo->length)
{
/*Update the data index as complete*/
*data_index = dev->fifo->length;
}
else
{
sensor_time_byte3 = dev->fifo->data[(*data_index) + BMI160_SENSOR_TIME_MSB_BYTE] << 16;
sensor_time_byte2 = dev->fifo->data[(*data_index) + BMI160_SENSOR_TIME_XLSB_BYTE] << 8;
sensor_time_byte1 = dev->fifo->data[(*data_index)];

/* Sensor time */
dev->fifo->sensor_time = (uint32_t)(sensor_time_byte3 | sensor_time_byte2 | sensor_time_byte1);
*data_index = (*data_index) + BMI160_SENSOR_TIME_LENGTH;
}
}

3.Sensor time is for last frame.

You could refer this do calculate frame time:

Previous frame time = dev->fifo->sensor_time*39.0625us-10000us

BMI160_ExampleCode.zip
12.53KB
View original
8 replies
Resolved