LSM303DLHC Trouble with accelerometer

Hi guys,

my LSM303DLHC accelerometer is acting strange.

My accelerometer seems to be giving me a value of around 2g at rest.
This is not expected at all.

Here is some data.
The data is in big endian format.

                                            X       Y       Z
Flat on X axis:                           7C:A0   FA:E0   10:A0
Flat on X axis, but on the opposite side: 80:A0   00:60   08:A0

My settings for my accelerometer:
CTRL_REG1_A: 0x37
CTRL_REG4_A: 0x40

I am pretty puzzled by this result and would appreciate some help.

Hello.

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.

- Ryan

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.

Any help?

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?

- Ryan

Setting the BLE bit to 0 fixes the problem!

This is pretty unexpected behavior because the BLE bit only messes around with big/little endian…
Any idea why this happens?

Hi, I am now having trouble getting the magnetometer to work. :frowning:

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?

All I need to do is to write 0 to MR_REG_M?

No. I haven’t looked into it with a unit here. If you do look into it and figure it out, I would be glad to know.

From the product page Protocol Hints section:

Are you reading all of the addresses? Can you post your code? The code in our Arduino library works, so you should be able to use that as an example.

- Ryan

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.

- Ryan

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 :smiley:

You’re welcome. I am glad you got it working!

Are you referring to C7 on our schematic (available on the product page)? Do you know what was wrong with it?

- Ryan