cancel
Showing results for 
Search instead for 
Did you mean: 

lsm303dlhc acceleration computing

spacecadt
Associate
Posted on July 07, 2016 at 18:19

Hi, I faced with the problem of acceleration calculations on lsm303dlhc

I read registers and past them, but in x, y, z variables contain crazy values, if demoboard is on the table, values must be x: 0, y: 0, z: 1000, but i get x: -1499 y : -1499 z:49 Range +-2g. Please, describe process of calculating acceleration in m/s^2 if i have values from registers


int8_t buffer[6];

uint8_t aTxBuffer[8];

int16_t pnRawData[3];


while
(1)

{



HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x28 , 1, (uint8_t*)&aTxBuffer[0], 1, 1);

HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x29 , 1, (uint8_t*)&aTxBuffer[1], 1, 1);

HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2A , 1, (uint8_t*)&aTxBuffer[2], 1, 1);

HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2B , 1, (uint8_t*)&aTxBuffer[3], 1, 1);

HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2C , 1, (uint8_t*)&aTxBuffer[4], 1, 1);

HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2D , 1, (uint8_t*)&aTxBuffer[5], 1, 1);



for
(
int
i=0; i<3; i++)

{

pnRawData[i]=((int16_t)((uint16_t)aTxBuffer[2*i+1] << 8) + aTxBuffer[2*i]);

}

//////////////////////////////////////////////////////////////////////////////////// 


int16_t x = pnRawData[0];

int16_t y = pnRawData[1];

int16_t z = pnRawData[2];

}

1 REPLY 1
Miroslav BATEK
ST Employee
Posted on July 08, 2016 at 17:00

Your calculation seems to be correct.

Can you please share the sensor settings?

Are the values which you get constant (x: -1499 y : -1499 z: 4992) or vary?

Best regards

Miroslav