2016-07-07 09:19 AM
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];
}
2016-07-08 08:00 AM
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 regardsMiroslav