Skip to main content
MM.10
Associate II
July 25, 2019
Solved

Hi guys, I'm using the magnetometer of LSm303agr, but I have some doubts about how to interpret the data.

  • July 25, 2019
  • 1 reply
  • 799 views

Hi guys,

I'm using the magnetometer of LSm303agr, but I have some doubts about how to interpret the data. Let me explain below:

I know that LSm303agr returns magnetometer coordinates in two bytes (MSB, LSB) each one. Is it correct this conversion to get the coordinates as int16?

Thank you in advance.

int16_t X_MAG, Y_MAG, Z_MAG;
 
X_MAG = (int16_t)(i2c_ByteRead(0x3D, 0x69) << 8) | i2c_ByteRead(0x3D, 0x68);
 
Y_MAG = (int16_t)(i2c_ByteRead(0x3D, 0x6B) << 8) | i2c_ByteRead(0x3D, 0x6A);
 
Z_MAG = (int16_t)(i2c_ByteRead(0x3D, 0x6D) << 8) | i2c_ByteRead(0x3D, 0x6C);

This topic has been closed for replies.
Best answer by Winfred LU

Hi Manuel,

It is correct.

Please note that

the (signed) 16-bit magnetic data, aka LSB. must be multiplied by the proper sensitivity parameter, M_So = 1.5, in order to obtain the corresponding value in mG.

Best Regards,

Winfred

1 reply

Winfred LU
Winfred LUBest answer
ST Employee
July 26, 2019

Hi Manuel,

It is correct.

Please note that

the (signed) 16-bit magnetic data, aka LSB. must be multiplied by the proper sensitivity parameter, M_So = 1.5, in order to obtain the corresponding value in mG.

Best Regards,

Winfred