AnsweredAssumed Answered

lsm303dlhc acceleration computing

Question asked by putintsev.roman.002 on Jul 7, 2016
Latest reply on Jul 8, 2016 by Miroslav B
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: 4992. Range +-2g. Please, describe process of calculating acceleration in m/s^2 if i have values from registers
01.int8_t buffer[6];
02.uint8_t aTxBuffer[8];
03.int16_t pnRawData[3];
04. 
05.while (1)
06.  {
07.   
08. 
09.        HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x28 , 1, (uint8_t*)&aTxBuffer[0], 1, 1);
10.        HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x29 , 1, (uint8_t*)&aTxBuffer[1], 1, 1);
11.        HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2A , 1, (uint8_t*)&aTxBuffer[2], 1, 1);
12.        HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2B , 1, (uint8_t*)&aTxBuffer[3], 1, 1);
13.        HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2C , 1, (uint8_t*)&aTxBuffer[4], 1, 1);
14.        HAL_I2C_Mem_Read(&hi2c1, 0x32, 0x2D , 1, (uint8_t*)&aTxBuffer[5], 1, 1);
15.         
16.         
17.    for(int i=0; i<3; i++)
18.    {
19.      pnRawData[i]=((int16_t)((uint16_t)aTxBuffer[2*i+1] << 8) + aTxBuffer[2*i]);
20.    }
21.////////////////////////////////////////////////////////////////////////////////////       
22.         
23.int16_t x = pnRawData[0];
24.int16_t y = pnRawData[1];
25.int16_t z = pnRawData[2];
26.}

Outcomes