cancel
Showing results for 
Search instead for 
Did you mean: 

LSM6DSV IMU sensor hub with external 3-axis 18-bit high precision magnetometer sensor

NWang.1
Associate II

Hello,

We want to use LSM6DSV IMU sensor with external 3-axis 18-bit high-precision magnetometer sensor through IMU sensor hub function also with its FIFO function. We refer to following LSM6DSV sensor hub example:

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lsm6dsv_STdC/examples/lsm6dsv_sensor_hub.c

We found that we can't get 3-axis 18-bit (3 x 3 = 9 bytes) mag sensor data from above example. It seemed that we can only get 3-axis 16-bit (3 x 2 = 6 bytes) through sensor hub with FIFO function. Because our total sensor data size has 9 bytes more than 6 bytes, we don't know how to use sensor hub to get 9 bytes mag sensor data with LSM6DSV. Could you give us some suggestion to acquire 9 bytes data from sensor hub or workaround method? 

Thank you very much.

Nan

3 REPLIES 3
Federica Bossi
ST Employee

Hi @NWang.1 ,

Unfortunately we don't have an example with a 3-axis 18bit, however you will have to put 3 bytes to read for the 18 bits and then as subadd you will have to put the register from which the data starts. If the data are non-contiguous, you could configure several readings separated by the right points.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Bossi,

Thank you for your information. For our purpose, we want to acquire 3-axis(18-bit data for each axis) 9 bytes at once. We use following code to initialize IMU:

sh_cfg_read.slv_add = (MAGNETOMETER_SLAVE_ADDR & 0xFEU) >> 1; /* 7bit I2C address */
sh_cfg_read.slv_subadd = MAG_REG_HXL;  
sh_cfg_read.slv_len = 6;   // HXL,HXM,HXH,HYL,HYM,HYH,HZL,HZM,HZH
lsm6dsv_sh_slv_cfg_read(&dev_ctx, 0, &sh_cfg_read);
lsm6dsv_fifo_sh_batch_slave_set(&dev_ctx, 0, PROPERTY_ENABLE);

Then we want to acquire 9 bytes mag sensor data from while loop or drdy interrupt signal.

int imu_sensor_data_poll()
{
    ...
    ret = lsm6dsv_fifo_status_get(&dev_ctx, &fifo_status);
    num = fifo_status.fifo_level;
    while (num--) 
    {
         /* Read FIFO sensor value */
	 lsm6dsv_fifo_out_raw_get(&dev_ctx, &f_data);
         switch (f_data.tag) 
	 {
             case LSM6DSV_SENSORHUB_SLAVE0_TAG:
                 // Here We want to handle 9 bytes mag sensor data
             break;
             ......
         }
    }
    ...
}

But we found that the above code slv_len(Slave0_numop[2:0]) shouldn't exceed 7 according to following figure from datasheet:

NWang1_0-1725006599284.png

What does this sentence "If the data are non-contiguous, you could configure several readings separated by the right points." mean? Can you provide some more detail information about it? Thank you very much.

NWang.1
Associate II

Hi, ST guys:

Can we initialize sensor hub function to read 3-axis 18bit mag data on LSM6DSV IMU as following code:

......
# Note connect only one mag sensor but use same address
sh_cfg_read.slv_add = (MAGNETOMETER_SLAVE_ADDR & 0xFEU) >> 1; /* 7bit I2C address */
sh_cfg_read.slv_subadd = REG_ST1;   // Read fix 6 bytes for status and X,Y axis
sh_cfg_read.slv_len = 6;
lsm6dsv_sh_slv_cfg_read(&dev_ctx, 0, &sh_cfg_read);
lsm6dsv_fifo_sh_batch_slave_set(&dev_ctx, 0, PROPERTY_ENABLE);

sh_cfg_read.slv_add = (MAGNETOMETER_SLAVE_ADDR & 0xFEU) >> 1; /* 7bit I2C address */
sh_cfg_read.slv_subadd = REG_HYH;   // Read remaining 6 bytes for Z axis and status
sh_cfg_read.slv_len = 6;
lsm6dsv_sh_slv_cfg_read(&dev_ctx, 1, &sh_cfg_read);
lsm6dsv_fifo_sh_batch_slave_set(&dev_ctx, 1, PROPERTY_ENABLE);
......

imu_sensor_data_poll()
{
   ......
   while (num--) {
      switch(f_data.tag)
      {
          ......
          case LSM6DSV_SENSORHUB_SLAVE0_TAG:
             // Get mag sensor first 6 bytes data for status and X, Y axis 
             break;
          case LSM6DSV_SENSORHUB_SLAVE1_TAG:
             // Get mag sensor remaining 6 bytes for Z axis and status
             break;
      }
   }
}

Can we use above method to acquire 12 bytes data from mag sensor? Thank you very much. Note: We have only one mag sensor.

BRs.