Accelerometer output from LSM303DLH carrier board reads "0"

Dear Forum Members,
I am trying to interface LSM303DLH carrier board with MSP430. My problem is when I read the accelerometer, it reads all zero values. My code is able to detect the presence of LSM303 over I2C with address 0x18.

I have attached a part of my code below:

[code]void write_ACC_REG(unsigned char byteCount, unsigned char *field)
TI_USCI_I2C_transmitinit(0x18,0x12); // prescaler generates I2C of 100KHz
while( TI_USCI_I2C_notready() );
if(TI_USCI_I2C_slave_present(0x18)) // check slave address

char read_ACC(unsigned char count1)
{unsigned char val1;
unsigned char store1[1] = {ā€˜jā€™};
while( TI_USCI_I2C_notready() );
while( TI_USCI_I2C_notready() ); // wait till bus is free before leaving this function
val1 = store1[0];
return val1;

unsigned char initial1_ACC[2] = {LSM303DLH_CTRL_REG1_A, 0x27};
unsigned char initial2_ACC[2] = {LSM303DLH_CTRL_REG4_A, 0x40};
unsigned char reg_DATA_ACC[1] = {(LSM303DLH_OUT_X_L_A | 0x80)};

void main(void){
unsigned char X_H_A, X_L_A, Y_H_A, Y_L_A, Z_H_A, Z_L_A;
write_ACC_REG(2,initial1_ACC); // enable ACC
write_ACC_REG(2,initial2_ACC); // REG4_A

for (;;){
X_L_A = read_ACC(1);
X_H_A = read_ACC(1);
Y_L_A = read_ACC(1);
Y_H_A = read_ACC(1);
Z_L_A = read_ACC(1);
Z_H_A = read_ACC(1);

send2pc(X_L_A); // this function transmits data over RS232 link to PC


Can anyone please tell me where am I going wrong? Am I missing something?
I will highly appreciate any help to resolve this problem.


I also tried to reduce length of cable from board to the controller, but didn;t help.

A quick summary of my code is:

  1. Use 0x18 as I2C address for accelerometer
  2. Write 0x27 to REG1 --> Before writing code checks if the slave is present or not
  3. Write 0x40 to REG4
  4. Write 0xA8 to OUT_X_L_A --> Wait for 20000 for the data to get updated. CLK of CPU is 1MHz and that of I2C is 100KHz
  5. Read X_L_A, X_H_A, Y_L_A, Y_H_A, Z_L_A, Z_H_A
  6. Send the acquired data to PC over RS232 link

Can someone please point out what I am doing wrong? Or where shall I look for potential problems? Am i missing something?

Will be very grateful to you for your assistance.


Hello, Nick.

Could you tell us more about your setup? Is there anything else connected to the MSP430? Could you post a photo of your entire setup, including all the connections?

Also, do you have an Arduino that you can use to try the example programs?

- Jeremy

Hi Jeremy,

Thank you for your response! I will take a pic of my setup and put it up here.

But do you think I am missing any step in the reading accelerometer. There is nothing else connected to I2C line only the LSM303DLH carrier board.

Unfortunately, I do not have Adruino and so I could not try out sample example. What do you suspect might be going wrong? Any one any pointers.


I am not sure. Could you try reading the WHO_AM_I address and see if you get the correct value? Also, could you try communicating with the magnetometer and see if you can get any readings?

- Jeremy

Hi Nick,

short question, why are you writing to the OUT_X_L register?
You should only read from this register, right?