cancel
Showing results for 
Search instead for 
Did you mean: 

[LSM9DS19] Weird bahavior observed while reading WHO_AM_I register (accelerometer + Gyroscope)

PMach.1
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
PMach.1
Senior

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!

View solution in original post

4 REPLIES 4
KnarfB
Principal III

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.

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.

PMach.1
Senior

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!

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