AnsweredAssumed Answered

Trouble with STM32F4 and LSM303DLHC accelerometer data

Question asked by anton.bogdan on Oct 27, 2014
Latest reply on Oct 28, 2014 by baird.hal.001
Hello all, i started a while ago some IMU project... but i have some doubts about reading the correct data from my accelerometer, wich is LSM303DLHC

Acording to my code, i setup the following registers

CTRL_REG1_A   0x77  set  400hz data rate
CTRL_REG4_A   0x00  2g, little endian

When i set the MSB of the first register to be read ( 0x28, with msb set results 0xA8) then acording to the LSM datasheet
it continues to send me data from all 6 register in the following order:

uint8_t dataBuffer[6];

1st  dataBuffer[0] X_LSB ( address 0x28)
2nd  dataBuffer[1] X_MSB ( address 0x29)
3rd  dataBuffer[2] Y_LSB ( address 0x2A)
4th  dataBuffer[3] Y_MSB ( address 0x2B)
5th  dataBuffer[4] Z_LSB ( address 0x2C)
6th  dataBuffer[5] Z_MSB ( address 0x2D)

then i integrate the MSB`s and the LSBs in 16bit integer like this:

 int16_t Buf[3];

The /16 division is for 4 bit right shift since LSM303DLHC outputs on accelerometer only 12bit values from the 16bit register

and after this i divide by the 2g factor, wich acording to the datsheet is 1 for 2g, ending in 1LSB/mg

float x,y,z;


I want to know, at this poit did i interpret the data corectly?

And these final values are somehow doubtfull to be corectly, the values where printed directly troug serial port

X:4.00    Y:36.00   Z:0.00   
X:4.00    Y:40.00   Z:0.00   
X:4.00    Y:36.00   Z:2056.00   
X:4.00    Y:20.00   Z:1028.00   
X:8.00    Y:36.00   Z:3084.00   
X:4.00    Y:40.00   Z:3084.00   
X:4.00    Y:32.00   Z:2056.00   
X:8.00    Y:28.00   Z:0.00   
X:0.00    Y:28.00   Z:0.00   
X:12.00   Y:20.00   Z:1028.00   
X:16.00   Y:24.00   Z:2056.00   
X:4092.00 Y:20.00   Z:2056.00   
X:16.00   Y:32.00   Z:3084.00   
The end result is in miliG`s? or LSB`s ?