cancel
Showing results for 
Search instead for 
Did you mean: 

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

MM.10
Associate II

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);

1 ACCEPTED SOLUTION

Accepted Solutions
Winfred LU
ST Employee

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

View solution in original post

1 REPLY 1
Winfred LU
ST Employee

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