Why acceleration data of LSM303D on the Z-axis doesn't work?
Hi,
I have a LSM303D, compass, and acceleration sensor. I can communicate with the sensor, and I get the magnetometer data on all of the axes, unlike the accelerometer. Accelerometer Z-axis data comes "-32760" all the time. I work on stm32f103c8t6
Here is my sensor initialization code:
AESK_StatusTypeDef AESK_LSM303_Init()
{
//This Register must be set to ‘0’ for the correct operation of the device.
if(AESK_LSM303_Write_Reg(CTRL0, 0x00) != AESK_OK)
{
return AESK_COM_ERROR;
}
// Accelerometer
// 0x57 = 0b01010111
// AODR = 0101 (50 Hz ODR); AZEN = AYEN = AXEN = 1 (all axes enabled)
if(AESK_LSM303_Write_Reg(CTRL1, 0x57) != AESK_OK)
{
return AESK_COM_ERROR;
}
// 0x57 = 0b01010111
// AFS = 0 (+/- 2 g full scale)
if(AESK_LSM303_Write_Reg(CTRL2, 0x00) != AESK_OK)
{
return AESK_COM_ERROR;
}
// Magnetometer
// 0x64 = 0b01100100
//Temp sensor disabled
// M_RES = 11 (high resolution mode); M_ODR = 001 (6.25 Hz ODR)
//6.25 Hz available only for if AODR >50 Hz
if(AESK_LSM303_Write_Reg(CTRL5, 0x64) != AESK_OK)
{
return AESK_COM_ERROR;
}
// 0x20 = 0b00100000
// MFS = 01 (+/- 4 gauss full scale)
if(AESK_LSM303_Write_Reg(CTRL6, 0x00) != AESK_OK)
{
return AESK_COM_ERROR;
}
// 0x00 = 0b00000000
// MLP = 0 (low power mode off); MD = 00 (continuous-conversion mode)
if(AESK_LSM303_Write_Reg(CTRL7, 0x00) != AESK_OK)
{
return AESK_COM_ERROR;
}
return AESK_OK;
}
I don't get any errors during initialization.
And, here is the sensor data.
What can be the problem? I think the initialization can be different, but I couldn't find what should I change.
EDIT:
Magnetometer doesn't need 2 bytes. Why ST set 2 bytes for the magnetometer axes. The magnetometer output is always between -15 and +102 on x axis, -115and -27 on y axis, -308 and -103 on z axis. Also, the output is very noisy cause of the narrow gap of the output. I think I should have chosen bno055.
Thank you for your time.
