LSM303AGR magnetometer will not pass self test
Hello,
I have been battling with getting an LSM303AGR to pass the self test. The accelerometer is passing the self test and the values look reasonable (Z-axis ~1g), but the magnetometer will not pass. I have 2 STEVAL-MKI172V1 boards, both are showing the same symptoms. I am testing with a Nucleo-U5A5ZJ-Q with I2C at fast mode (400KHz).
Initially, I wrote my own self test based on the procedures in the datasheet (Version 11.0, Aug 2022). I was able to get the accelerometer to pass, but not the magnetometer. After debugging ad infinitum, I decided to try using the test provided from the STMems_Standard_C_driver repo contained in lsm303agr_self_test.c. I found a few posts here and this was what everyone was directed to.
It is worth noting there are several bugs in this test: using uninitialized data, using previous data from the accelerometer test for the mag test without clearing, etc. Once I had these bugs sorted, I reran the tests to get the exact same outcome I was getting from my own self test. Here is an example that is typical of what I have seen, this is after conversion and averaging:
Name : maes_st_off_mag
Details:{-0.50999999, -1.83000004, 0} // {x,y,z}
Name : maes_st_on_mag
Details:{0.839999974, -0.899999976, 1.20000005} // {x,y,z}
What I am seeing is a very small difference between measurements with/out the self test enabled. I have checked all I2C comms with a Saleae logic analyzer and can rule out any comms issues. I've checked for data corruption, timing issues, and all the other commonplace issues and can confidently rule them out. There are no data overruns and no apparent saturation, and no magnets in the vicinity.
I have attached the exported data from the logic analyzer for both tests as well as the modified self test file. The first reads have overruns as they are after the delay period: this is expected and the values are discarded. The rest of the values all work out to be pretty close to 0 for both with and without self test enabled.
As an aside, the sensors were ordered separately and have been handled with the appropriate ESD precautions. I'm at least a little bit disappointed these dev kit sensors do not come in an ESD bag, just bare in a carboard box. I'd be happy if this is just a few bad sensors, but after the same behavior from 2 different sensors ordered a few months apart, it's hard to say one way or another.
