Hi @NicolasGoualard ,
While reviewing the code you shared, we noticed that in the section you indicated, a fundamental step was missing. This step is described in the Application Manual AN5845.
int imu_start_acquisition(imu_recording_state_t wanted_state)
{
lsm6dsv16bx_pin_int_route_t pin1_int = {0};
lsm6dsv16bx_fifo_sflp_raw_t fifo_sflp = {0};
lsm6dsv16bx_filt_settling_mask_t filt_settling_mask = {0};
int ret;
sensor.state.recording_state = wanted_state;
/* Enable Block Data Update */
ret = lsm6dsv16bx_block_data_update_set(&sensor.dev_ctx, PROPERTY_ENABLE);
if (ret) {
LOG_ERR("lsm6dsv16bx_block_data_update_set (%i)", ret);
return ret;
}
/* 2. Configuration Init*/
ret = lsm6dsv16bx_sflp_configure(&sensor.dev_ctx);
if (ret) {
LOG_ERR("lsm6dsv16bx_sflp_configure (%i)", ret);
return ret;
}
/* Set full scale */
ret = lsm6dsv16bx_xl_full_scale_set(&sensor.dev_ctx, LSM6DSV16BX_8g);
if (ret) {
LOG_ERR("lsm6dsv16bx_xl_full_scale_set (%i)", ret);
return ret;
}
ret = lsm6dsv16bx_gy_full_scale_set(&sensor.dev_ctx, LSM6DSV16BX_2000dps);
if (ret) {
LOG_ERR("lsm6dsv16bx_gy_full_scale_set (%i)", ret);
return ret;
}
/*
* Set FIFO watermark (number of unread sensor data TAG + 6 bytes
* stored in FIFO) to CONFIG_LSM6DSV16BX_FIFO_WATERMARK samples
*/
ret = lsm6dsv16bx_fifo_watermark_set(&sensor.dev_ctx, 25);
if (ret) {
LOG_ERR("lsm6dsv16bx_fifo_watermark_set (%i)", ret);
return ret;
}
/* Set FIFO batch of sflp data */
fifo_sflp.game_rotation = wanted_state.sflp_state.game_rot_enabled; // true
fifo_sflp.gravity = wanted_state.sflp_state.gravity_enabled; // false
fifo_sflp.gbias = wanted_state.sflp_state.gbias_enabled; // false
ret = lsm6dsv16bx_fifo_sflp_batch_set(&sensor.dev_ctx, fifo_sflp);
if (ret) {
LOG_ERR("lsm6dsv16bx_fifo_sflp_batch_set (%i)", ret);
return ret;
}
/* Set FIFO mode to Stream mode (aka Continuous Mode) */
ret = lsm6dsv16bx_fifo_mode_set(&sensor.dev_ctx, LSM6DSV16BX_STREAM_MODE);
if (ret) {
LOG_ERR("lsm6dsv16bx_fifo_mode_set (%i)", ret);
return ret;
}
pin1_int.fifo_th = PROPERTY_ENABLE;
ret = lsm6dsv16bx_pin_int1_route_set(&sensor.dev_ctx, pin1_int);
if (ret) {
LOG_ERR("lsm6dsv16bx_pin_int1_route_set (%i)", ret);
return ret;
}
/* Set High Performance mode */
ret = lsm6dsv16bx_xl_mode_set(&sensor.dev_ctx, LSM6DSV16BX_XL_HIGH_PERFORMANCE_MD);
if (ret)
{
LOG_ERR("lsm6dsv16bx_xl_mode_set %i", ret);
return ret;
}
/* Set Output Data Rate */
ret = lsm6dsv16bx_xl_data_rate_set(&sensor.dev_ctx, LSM6DSV16BX_XL_ODR_AT_960Hz);
if (ret) {
LOG_ERR("lsm6dsv16bx_xl_data_rate_set (%i)", ret);
return ret;
}
/* Set High Performance mode */
ret = lsm6dsv16bx_gy_mode_set(&sensor.dev_ctx, LSM6DSV16BX_GY_HIGH_PERFORMANCE_MD);
if (ret)
{
LOG_ERR("lsm6dsv16bx_xl_mode_set %i", ret);
return ret;
}
/* Set Output Data Rate */
ret = lsm6dsv16bx_gy_data_rate_set(&sensor.dev_ctx, LSM6DSV16BX_GY_ODR_AT_960Hz);
if (ret) {
LOG_ERR("lsm6dsv16bx_gy_data_rate_set (%i)", ret);
return ret;
}
if (wanted_state.sflp_state.gbias_enabled || wanted_state.sflp_state.game_rot_enabled || wanted_state.sflp_state.gravity_enabled)
{
ret = lsm6dsv16bx_sflp_data_rate_set(&sensor.dev_ctx, LSM6DSV16BX_SFLP_120Hz);
if (ret) {
LOG_ERR("lsm6dsv16bx_sflp_data_rate_set (%i)", ret);
return ret;
}
}
if (wanted_state.sflp_state.game_rot_enabled || wanted_state.sflp_state.gravity_enabled || wanted_state.sflp_state.gbias_enabled)
{
ret = lsm6dsv16bx_sflp_game_rotation_set(&sensor.dev_ctx, PROPERTY_ENABLE);
if (ret) {
LOG_ERR("lsm6dsv16bx_sflp_game_rotation_set (%i)", ret);
return ret;
}
lsm6dsv16bx_sflp_gbias_t gbias;
gbias.gbias_x = 0.0f;
gbias.gbias_y = 0.0f;
gbias.gbias_z = 0.0f;
ret = lsm6dsv16bx_sflp_game_gbias_set(&sensor.dev_ctx, &gbias);
if (ret) {
LOG_ERR("lsm6dsv16bx_sflp_game_gbias_set (%i)", ret);
return ret;
}
}
/* Mask accelerometer and gyroscope data until the settling of the sensors filter is completed */
filt_settling_mask.drdy = PROPERTY_ENABLE;
filt_settling_mask.irq_xl = PROPERTY_ENABLE;
filt_settling_mask.irq_g = PROPERTY_ENABLE;
ret = lsm6dsv16bx_filt_settling_mask_set(&sensor.dev_ctx, filt_settling_mask);
if (ret) {
LOG_ERR("lsm6dsv16bx_filt_settling_mask_set (%i)", ret);
return ret;
}
return 0;
}
I took the liberty to modify some parts.
I noticed that you were saving accelerometer and gyroscope values as well as the timestamp into the FIFO. For an initial test, I removed these to simplify the results and avoid the risk of incorrect data.
Please try running the test again with these modifications, and the expected results should be obtained.
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.