cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure mode 2?

suads
Associate III

Hello,

I have STEVAL-MKI197V1 (lsm6dsox sensor) that I use to communicate over spi with my stm32 board, and getting accelerometer and gyro data. Now I want to connect to the i2c lines of STEVAL-MKI197V1 a magnetometer(lsm303agr). How to setup this mode and read the raw data from the external sensor.

Thanks

6 REPLIES 6
Eleon BORLINI
ST Employee

Hi @suads​ , I suggest you to check the AN5272 p.65, where the sensor hub mode - Mode 2 of the LSM6DSOX is described, if not already done. Yo should connect PIN2 and PIN3 of the LSM6DSOX (STEVAL-MKI197V1) to the LSM303AGR PIN1 and PIN3, with the CS_MAG (I2C selection) high.

0693W000001pgGvQAI.png

On Github, you can also find an example code for the sensor hub between LSM6DSOX and LIS2MDL magnetometer --> lsm6dsox_sensor_hub_fifo_lis2mdl_simple.c

Regards

suads
Associate III

Thanks for the help,

I've implemented the code with my sensor, but I have some issues. So I want to read the device ID but its not working always getting zero.

On the oscilloscope i can see clock, and data on sda line. So i can see write is working I see the first byte for write 3c and register 4f (who am I), but then is coming the read byte 9e (should be 3d) and in the end the value 20.

I discovered If I move the read command 9e one clock to left, then I am getting 3d(read byte) and 40(response) and that's the correct value. Its like glitching one clock for some reason.

What could be the reason for this?

Thanks

suads
Associate III

I ve made some progress, I successfully read the ID of the magnetometer. But when I try to read the raw data from magnetometer I m always getting the same 6 bytes.

What could be the cause?

Did you configured the LSM303AGR magnetometer for continuous reading (sensor startup sequence described in the AN4825 p. 14 and further)? Regards

Thanks Eleon, yes I set it to continues reading the problem was in this function lsm6dsox_sh_read_data_raw_get(&ag_ctx, (lsm6dsox_emb_sh_read_t*)&data); the data was not returned

But I'm having another problem so i add the second accelomoter from lsm303agr.

It is working with just one slave device . So I have lsm6dsox acc and gyro and one slave device from lsm303agr mag and it works.

If I add the second slave device, accelometer 2 reads always the same numbers. But the device ID's from all devices are correct.

0693W000001qPYVQA2.png

Finally getting some changes from the accelomoter . So the slave subadd in the configure function (even within my example is not needed) is the output registers from the sensors. So configure as following

Set the corresponding slave addresses and subadresses

Set full_scale :acc 2g gyro 2000dps

data rate: acc, gyro 104hz, acc2,mag 100hz

enable block data update for all sensors

mag operating mode : LP_8bit

read the drdy flag then read the raw data.