2020-11-19 05:44 AM
Hello, everyone!
As I was following the polling example on GitHub with the STM32 drivers for the LSM9DS1. I noticed that, during the configuration, reading the Accelerometer & Gyroscope registers, the WHO_AM_I read value was 0x28h, instead of 0x68h. The reading of the magnetometer correspondent register (WHO_AM_I_M) returns the expected value(0x3Dh).
After a few tests on altering the code, I noticed that I had to read it twice in order to get a correct reading, exactly as follows:
lsm9ds1_id_t whoamI;
lsm9ds1_dev_id_get(&dev_ctx_mag, &dev_ctx_imu, &whoamI);
lsm9ds1_dev_id_get(&dev_ctx_mag, &dev_ctx_imu, &whoamI);
if (whoamI.imu != LSM9DS1_IMU_ID || whoamI.mag != LSM9DS1_MAG_ID){
while(1){
return 0;
}
}
I tryed also adding a delay between the the initialization of the device and the register read process (up to 2 seconds), to no avail. Here, I was hoping that there was the need for a Boot Time in order to get a correct reading, but that seems to not be the case.
Any idea on what's causing this issue?
Thanks in advance
Solved! Go to Solution.
2020-11-19 07:09 AM
Got it!
By default, both pins CS_M ans CS_AG were configured to start with a low level. Whenever a read occurs, with my callback functions, I reset the pins before sending SPI data and set it back on afterwards. It seems that the first read occurs with errors because such transition does not occur in the first place, because it was set to low level as default. I can not explain why WHO_AM_I_M had no error in the first read, though.
Anyway, setting both pins to High level output as default solved the problem!
2020-11-19 05:51 AM
Could be an issue with falling / rising edges on the I2C bus. If you can hook-up a scope, I would recommend that. And checking / tuning the timing register & filters, pull-up resistor tuning.
2020-11-19 06:27 AM
Hi,
I'm actually reading through an SPI bus. I've double checked the clock configuration (CPOL high and CPHASE 2nd edge, 8 bits SPI data size). Unfortunately, the lines are on inside layers of the PCB, and I cannot take a look into the signals. Also, that seems not to be the case, since I get the expected readings if I run the lsm9ds1_dev_id_get() function several times, just not at first time.
2020-11-19 07:09 AM
Got it!
By default, both pins CS_M ans CS_AG were configured to start with a low level. Whenever a read occurs, with my callback functions, I reset the pins before sending SPI data and set it back on afterwards. It seems that the first read occurs with errors because such transition does not occur in the first place, because it was set to low level as default. I can not explain why WHO_AM_I_M had no error in the first read, though.
Anyway, setting both pins to High level output as default solved the problem!
2020-11-22 11:12 PM
Thank you @Community member for the solved issue reporting.
>> I can not explain why WHO_AM_I_M had no error in the first read, though.
That's interesting... could be related to some internal timings, but not sure...
-Eleon