Some numbers you have there are bigger than can be represented by 12 bits, so I suspect you haven’t converted the 16-bit space into an appropriate 12 bit representation. The accelerometer readings are 12-bit numbers that are left-justified in the space.
Those are raw data without any conversion or bit shifting.
So, the value for the X axis is 7C:A0 which is 7CA if we ignore the last 4 bits.
This is equals to 1994.
The 2nd value for the X axis is 80:A0 which is 80A after ignoring the last 4 bits.
This is equal to -2038.
If I am not wrong, the formula to convert to g is
(raw data) * 1mg. (I am using ±2g range).
Thus, my acceleration when the board is flat on the x axis is 1.994 g and -2.038g respectively.
This is not expected at all. I expect a value of around + and - 1g.
Can you try reading the data with the BLE bit set to zero (the default)? That is what we do in our LSM303 library. Also, can you tell me which register contained 7C and which register contained A0? What are you using to communicate with the LSM303DLHC? Can you post your code?
Hi, I am now having trouble getting the magnetometer to work.
I am getting values hovering around 0 when the magnetometer is stationary.
There is no changes in the values even when I bring an magnet close to the sensor.
Can I ask what are the steps to initialize the magnetometer?
I’m using an 8051 based MCU, with the I2C interface written in software by me. Not an Arduino.
So, I don’t think it is very helpful for me to post my code.
My I2C code seems fine because it works with the accelerometer portion perfectly, and I am able to read/write from the 3 configuration registers for the magnetometer portion.
Anyway, I think I have identified the problem (by going through your Arduino library and the datasheet).
Is there a different way of reading multiple bytes from the accelerometer and the magnetometer?
Yes. The auto-address-updating reads are different for the accelerometer and the magnetomer. (We have a description of the differences in the Protocol Hints section of the product page.) The LSM303DLHC is pretty much the combination of a separate accelerometer and magnetometer into one pacakage.
I’ve finally figured out the problem with my chip!
The 220nF capacitor that is connected to the LSM303DLHC was faulty, which caused the magenetometer reading to be hovering around the 0 range. Replacing it solved the problem.
RyanTM, Thanks for your help!
Your advice really helped me in getting my chip to work