I have two questions/problems with MMA8452Q readings and I would be grateful for explanations.
- I am using this accelerometer with my Teensy board which is Arduino comaptible. That means I can use also all the libraries. So I am using Sparkfun's library: MMA8452_Accelerometer/Firmware/libraries/SFE_MMA8452Q at master · sparkfun/MMA8452_Accelerometer · GitHub. After modification in this code thanks to the Tomas Vaverka and his answer to my previous question (MMA8452Q - Strange reading values) I was able to fix no negative value error. But now when I am looking again at the readings displayed at the Sarkfun webpage I think that still I have something wrong and to be honest, don't know why (my readings are included in the file).
My current reading value code in library looks like that:
// in header file: short x, y, z; x = ((short)(rawData<<8 | rawData)) >> 4; y = ((short)(rawData<<8 | rawData)) >> 4; z = ((short)(rawData<<8 | rawData)) >> 4; cx = (float) x / (float)(scale); cy = (float) y / (float)(scale); cz = (float) z / (float)(scale);
I have sensitivity (scale) set to 2g. What is wrong in my code?
- Second question is not so strong connected to source code or any error (to my knowledge). In documentation I found out that there are in fact 2 registers that holds 12 bit data. However, both in libaray and in Tomas Vaverka code (MMA8652FC - Bare metal example project) there is only getting value from 6 bits. Only thinkg that I found and might be an answer, but I don't fully understand it is the paragraph at the bottom of 20th page in documentation:
OUT_X_MSB, OUT_X_LSB, OUT_Y_MSB, OUT_Y_LSB, OUT_Z_MSB, and OUT_Z_LSB are stored in the autoincrementing address range of 0x01 to 0x06 to reduce reading the status followed by 12-bit axis data to 7 bytes. If the F_READ bit is set (0x2A bit 1), auto-increment will skip over LSB registers. This will shorten the data acquisition from 7 bytes to 4 bytes. The LSB registers can only be read immediately following the read access of the corresponding MSB register. A random read access to the LSB registers is not possible. Reading the MSB register and then the LSB register in sequence ensures that both bytes (LSB and MSB) belong to the same data sample, even if a new data sample arrives between reading the MSB and the LSB byte.
Can someone explain me why we are reading only 6 bits and in those bits there is value of 12 bits? Or do I understand it wrong?
Original Attachment has been moved to: data.txt.zip