lsm303d output never changes? solved

Just got LSM303D 3D Compass and Accelerometer Carrier with Voltage Regulator. I have no trouble configuring it over I2C. I can set all registers, and read them back to confirm that they have been set. However, the accel and magnetometer values never change.

I am using a STM32F4 Discovery board w/ Chibios. I have tried MANY combinations of things, but what I would expect to work does not. Simply trying to get the Accelerometer data returns hex 8/80/8/80/8/80 for the 6 accel bytes (starting at addr 0x40), every time. Status Reg (0x39) is always FF.
i configure Ctl2 reg as 0
i configure Ctl1 reg as 0x57
i configure Ctl7 reg as 0x0

Same results always. I have tried enabling the self test bit. It enables, but the output never changes. I have tried reading enabling and reading the magnetometer, and those output regs never change either.

I have plenty of other devices that I talk to no I2C with no problem. THey are not currently connected. I have a logic analyzer hooked up to the I2C Bus, and see the signals are what I say they are.



We have noticed that when the LSM303D accelerometer consistently reports values like 0x8008 (-32760) on all axes, it can be because the IC is in a bad state from browning-out. We have written a FAQ that addresses this.

Can you try making sure the voltage on the 3.3V line to your LSM303D is allowed to fall to 0V when power is removed? You might also try to minimize the 3.3V rise time when you apply power; for example, if your power supply takes a while to get to 3.3V when you turn it on, you could try connecting your system after the supply is already powered up instead of turning it on with everything connected.

If that does not solve it, can you tell me more about your setup? How are you supplying power? Can you post pictures that show how everything is connected? Can you post the simplest version of your code that shows the issue?


Hmm. Im not giving it 3.3v. I bought this package with a voltage regulator on it, and Im giving it 5v, which comes from a dc-dc converter on my board.
My pinouts are:
Vdd to 5v (exactly)
Gnd to Gnd.
scl and sda are pulled up thru 5.1K resistors to 5v and go to scl and sda on my disco board.

Again, I have no trouble talking I2C to the device. I can read and write ALL of the registers - changing them to my hearts content, and reading back the changed content. Its just the accelerometer values that dont change :frowning: It strikes me as very puzzling that even self test doesnt cause a change. I will try an adxl345 in this setup, and see how that goes. I will also check out your FAQ.

If this fails, I will see if I can produce some simple code to post.
Thanks for responding.

Problem solved.
HA. Well, both of us should have figured this out, but you gave me the clues to do so.
Exec summary is: I had supply power connected to VDD, not VIN. Peculiar that it worked at all.

Verbose summary:
The FAQ said my symptoms (everything I2C works, but accel output pinned to 0x8008) were related to power, so I started chasing power. My system had its own dc-dc power supply, which was providing 5v exactly, pulled from a big 12v lipo. Surely, that wasnt the issue. But for grins, I powered the LSM303D from a BIG 5v bench supply. Lo and behold, the accel values started changing. Measuring the output of the bench supply showed it to be 5.2v. I couldnt imagine that .2v would be a big diff, and I went back to the spec for the pololu module. Upon reading it more carefully, I saw that the VDD was meant as an output, not an input. VIN (surprise) is meant to be the power in. Changed it, and problem solved. Truly amusing that I2C initially worked at all. More amusing that my bench supply made the whole thing work. Anyway - power it from VIN :slight_smile:


I am glad you were able to figure out why you were getting that behavior; thanks for letting us know what the issue was!


I will tell you - this story isnt quite over yet. I find this part to be a bit fickle. If I power cycle my system, it often comes up only partially working - like on the X axis only. I presume it is because of the brownout issue that is mentioned. I will pursue that set of solutions and keep you informed

[quote] I find this part to be a bit fickle. [/quote]I’ve used an LSM303D for quite a bit now, and it always functions according to specs.

Jim, did you use THIS part? The problem is only on power-up/reset. I find that it needs to be initialized twice - same exact init code, but twice. Maybe I have the sequence incorrect…

[quote]Exec summary is: I had supply power connected to VDD, not VIN.[/quote]That part has probably been damaged by subjecting it to 5V. It is surprising that it still functions. I would not draw any conclusions about other parts, based on its behavior.

Umm - the pololu part has a voltage regulator on board. It can handle 5v :slight_smile: I love forums.

Ive delayed the initialization of this component for a few ms after power cycle. Didnt change any of the init code - just delayed it. That seems to have solved the problem and made it reliable.

Im closing this case completely.

For anyone else reading this, please note that it is definitely not okay to supply 5V to VDD on our LSM303D carrier. The appropriate connection point for 5V is the VIN pin; VDD is the output of the board’s 3.3V linear regulator, and it is directly connected to the supply voltage pins on the LSM303D IC (which is a 3.3V part). I am glad ljfischer’s sensor still seems to be working, but what he did has a good chance of destroying this sensor.