We're currently integrating a test routine for a MMA8452Q accelerometer. This routine is run each time our device is plugged (i.e. power supply comes up to the device and hence, to the chip).
To test this, we simply read the static acceleration, and compute the global acceleration that is expected to be close to 1 g as sqrt(x²+y²+z²) (gravity only, the device is not expected to move right after being plugged). No motion occured wile doing the tests.
The test goes as follow:
1) Device is plugged (power supply ON)
2) reset the accelerometer using the I2C command
3) disable the accelerometer using the I2C command
4) configures it for reading static acceleration only
5) enables it back the accelerometer using the I2C command
6) read 3 axis acceleration (once)
7) computes global acceleration and compares it to 1 g
8) disable accelerometer for power saving
9) device is unplugged (power supply off)
The fact is that upon certain conditions the acceleration is not within the range, but around 2 g...
Here are some experiments that have been done (results are repeatable):
- insert delay between steps 4) and 5) => acceleration Ok (around 1g)
- run to step 7) included, remove step 8) and reset the program to step 2) without unplugging the device (power supply is maintained) => acceleration Ok (around 1g)
My analysis: it seems the first accelerometer data upon chip power on (not on reset) are not valid, or take sometime before being valid (due to configuration change ?). Adding some delay between applying new configuration and reading first value seems to solve the problem, but I do not understand why this happen.
Does anybody have already encountered such a problem and would have an explanation ? I would like to be certain adding a delay will always solve this problem...
Thank you very much for your help.