cancel
Showing results for 
Search instead for 
Did you mean: 

Why acceleration data of LSM303D on the Z-axis doesn't work?

AÖzba.1
Associate II

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.

 0693W000007BYC6QAO.jpgWhat 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.

4 REPLIES 4
Eleon BORLINI
ST Employee

Hi @Ahmet Özbay​ ,

so is the z-axis acceleration value (and not x-axis and y-axis) always stuck to the -32760, right?

The device seems to be correctly configured, but please note that you are using uint_16 variables while signed int_16 should be used, according to the LSB to physical units conversion formula (check also the endianess, the order of the MSB and the LSB, etc...):

float_t lsm303d_from_fs2g_to_mg(int16_t lsb)
{
  return ((float_t)lsb * 0.061f);
}

You can also try to set the BDU bit of CTRL1 (20h) register to avoid overlap in the MSB/LSB values during concatenating....

Ps: LSM303D device is not indeed the best-in-class device in ST portfolio, but in terms of performance and sure not in terms of failure... do you have the possibility to test another LSM303D with the same setup/firmware?

-Eleon

AÖzba.1
Associate II

Hi @Eleon BORLINI​ ,

Thank you for your answer.

"so is the z-axis acceleration value (and not x-axis and y-axis) always stuck to the -32760, right?" Yes, but I've noticed that sometimes it comes 8. So, the Z-axis accel value always stuck to -32760, and 8.

I've changed "uint16_t" to int16_t, but the result is the same as before. Also, I've tried to change CTRL1 register value. I've written 0x5F to CTRL1 but, the result is the same as before. (Also I've observed these values on stmstudio.)

0693W000007BfhuQAC.jpg 

I guess I must change the IC with another type. There is a possibility that if I test this with another LSM303D I would get the same result.

Eleon BORLINI
ST Employee

Hi @Ahmet Özbay​ ,

did you eventually have the possibility to test another chip?

-Eleon

AÖzba.1
Associate II

Hi @Eleon BORLINI​ 

I don't have the possibility to test another chip soon.