cancel
Showing results for 
Search instead for 
Did you mean: 

lis3mdl connected to lsm6dsox I2C

JPARK.2
Associate II

Hello, support team.

In my test board, lis3mdl is connected to lsm6dsox I2C.

From above board, I want to read acceleration and gyro at 1667Hz, magnetic at 1kHz.

I refer to lsm6dsox_sensor_hub_fifo_lis2mdl.c to implement SW.

But It looks like magnetic data is rarely read from FIFO.

And maximum speed of SHUB_ODR_ is 104hz.

How can I read magnetic data at 1kHz speed?

And could you check my configuration?

/* Electrical pin configuration */
    val.sdo_sa0_pull_up = 0;
    val.aux_sdo_ocs_pull_up = 0;
    val.int1_int2_push_pull = 0;
    val.int1_pull_down = 0;
    lsm6dsox_pin_conf_set(&lsm_ctx, val);
 
    /* Check device ID */
    lsm6dsox_device_id_get(&lsm_ctx, &whoamI);
    while (whoamI != LSM6DSOX_ID)
        nrf_delay_ms(10);
    
    /* Restore default configuration */
    lsm6dsox_reset_set(&lsm_ctx, PROPERTY_ENABLE);
    do {
        lsm6dsox_reset_get(&lsm_ctx, &rst);
    } while (rst);
 
    /* Disable I3C interface */
    lsm6dsox_i3c_disable_set(&lsm_ctx, LSM6DSOX_I3C_DISABLE);
 
    lis3mdl_device_id_get(&lis_ctx, &whoamI);
    while (whoamI != LIS3MDL_ID)
        nrf_delay_ms(10);
 
    /* Enable Block Data Update */
    lis3mdl_block_data_update_set(&lis_ctx, PROPERTY_ENABLE);
    
    /* Set device in continuos mode */
    lis3mdl_operating_mode_set(&lis_ctx, LIS3MDL_CONTINUOUS_MODE);
 
    /* Set Output Data Rate */
    lis3mdl_data_rate_set(&lis_ctx, LIS3MDL_LP_1kHz);// 1/1kHz*(1000msec/1sec) = 1msec
 
    /* Set full scale */
    lis3mdl_full_scale_set(&lis_ctx, LIS3MDL_16_GAUSS);
 
    /*
    * Configure LSM6DSOX FIFO.
    *
    *
    * Set FIFO watermark (number of unread sensor data TAG + 6 bytes
    * stored in FIFO) to 15 samples. 5 * (Acc + Gyro + Mag)
    */
    lsm6dsox_fifo_watermark_set(&lsm_ctx, 15);
 
    /* Set FIFO mode to Stream mode (aka Continuous Mode). */
    lsm6dsox_fifo_mode_set(&lsm_ctx, LSM6DSOX_STREAM_MODE);
 
    /*
    * Enable FIFO batching of Slave0.
    */
    lsm6dsox_sh_batch_slave_0_set(&lsm_ctx, PROPERTY_ENABLE);
    lsm6dsox_sh_data_rate_set(&lsm_ctx, LSM6DSOX_SH_ODR_104Hz);
 
    /* Set FIFO batch XL/Gyro ODR to 12.5Hz. */
    lsm6dsox_fifo_xl_batch_set(&lsm_ctx, LSM6DSOX_GY_BATCHED_AT_1667Hz);
    lsm6dsox_fifo_gy_batch_set(&lsm_ctx, LSM6DSOX_GY_BATCHED_AT_1667Hz); 
 
    /*
    * Prepare sensor hub to read data from external Slave0 continuously
    * in order to store data in FIFO.
    */
    lsm6dsox_sh_cfg_read_t sh_cfg_read;
 
    sh_cfg_read.slv_add = LIS3MDLTR_ADDR;
    sh_cfg_read.slv_subadd = LIS3MDL_OUT_X_L;
    sh_cfg_read.slv_len = 6;
    lsm6dsox_sh_slv0_cfg_read(&lsm_ctx, &sh_cfg_read);
    /* Configure Sensor Hub to read one slave. */
    lsm6dsox_sh_slave_connected_set(&lsm_ctx, LSM6DSOX_SLV_0);
    /* Enable I2C Master. */
    lsm6dsox_sh_master_set(&lsm_ctx, PROPERTY_ENABLE);
    
    /* Configure LSM6DSOX. */
    lsm6dsox_xl_full_scale_set(&lsm_ctx, LSM6DSOX_16g);
    lsm6dsox_gy_full_scale_set(&lsm_ctx, LSM6DSOX_2000dps);
    lsm6dsox_block_data_update_set(&lsm_ctx, PROPERTY_ENABLE);
    lsm6dsox_xl_data_rate_set(&lsm_ctx, LSM6DSOX_XL_ODR_1667Hz);
    lsm6dsox_gy_data_rate_set(&lsm_ctx, LSM6DSOX_XL_ODR_1667Hz);
    
    /* Configure gpiote for the sensors data ready interrupt. */
    if (!nrf_drv_gpiote_is_init())
    {
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code); 
    }

1 ACCEPTED SOLUTION

Accepted Solutions
Eleon BORLINI
ST Employee

Hi @Community member​ ,

please note from the LSM6DSOX datasheet p.169 that the maximum ODR rate for the master I2C is defined in the SHUB_ODR_[1:0] bit of register as 00: 104 Hz (or at the maximum ODR between the accelerometer and gyro if it is less than 104 Hz).

So basically the LIS3MDL can be configured to run at ODR 1kHz as a standalone device, but not in the sensorhub mode. You are maybe experience this limitation.

One of the reason of this fact is that you can connect up to 4 slaves, sharing the same I2C master; the I2C speed in the sensorhub goes max to 400kHz, which is the fast mode maximum, but consider that you may connect 4 IMU slaves with 16-bit 6 axis each one, meaning min 40 kbits/second, without considering the I2C spec limitation and the master internal processing speed (so at least you have to double the capability and take a margin, i.e. 100kbit/s).

Note also that all the digital embedded features on LSM6DSOX (such as the FSM and the MLC)) are running at maximum 104Hz, that is a trade off between the accuracy of the result and the power consumption of the device.

For completeness, you may try to check if this function:

/* Set Output Data Rate */
    lis3mdl_data_rate_set(&lis_ctx, LIS3MDL_LP_1kHz);// 1/1kHz*(1000msec/1sec) = 1msec

is correctly enabling the FAST_ODR bit in the CTRL_REG1 (20h) of the, which is needed for ODR > 80Hz on the magnetometer (datasheet p.24)

By the way, usually the magnetometer is used to measure quasi-static magnetic field variation... can I ask you for which application do you need to monitor up to 500Hz magnetic field?

-Eleon

View solution in original post

2 REPLIES 2
Eleon BORLINI
ST Employee

Hi @Community member​ ,

please note from the LSM6DSOX datasheet p.169 that the maximum ODR rate for the master I2C is defined in the SHUB_ODR_[1:0] bit of register as 00: 104 Hz (or at the maximum ODR between the accelerometer and gyro if it is less than 104 Hz).

So basically the LIS3MDL can be configured to run at ODR 1kHz as a standalone device, but not in the sensorhub mode. You are maybe experience this limitation.

One of the reason of this fact is that you can connect up to 4 slaves, sharing the same I2C master; the I2C speed in the sensorhub goes max to 400kHz, which is the fast mode maximum, but consider that you may connect 4 IMU slaves with 16-bit 6 axis each one, meaning min 40 kbits/second, without considering the I2C spec limitation and the master internal processing speed (so at least you have to double the capability and take a margin, i.e. 100kbit/s).

Note also that all the digital embedded features on LSM6DSOX (such as the FSM and the MLC)) are running at maximum 104Hz, that is a trade off between the accuracy of the result and the power consumption of the device.

For completeness, you may try to check if this function:

/* Set Output Data Rate */
    lis3mdl_data_rate_set(&lis_ctx, LIS3MDL_LP_1kHz);// 1/1kHz*(1000msec/1sec) = 1msec

is correctly enabling the FAST_ODR bit in the CTRL_REG1 (20h) of the, which is needed for ODR > 80Hz on the magnetometer (datasheet p.24)

By the way, usually the magnetometer is used to measure quasi-static magnetic field variation... can I ask you for which application do you need to monitor up to 500Hz magnetic field?

-Eleon

JPARK.2
Associate II

Hello,

lis3mdl_data_rate_get returned 1kHz correctly.

​I think My team may need to re-design the board.

ps. ​The goal of application is to measure vehicle wheel speed using accelerometer and gyrometer.

And magnetometer will be used to calibrate measurement error.