2019-07-25 10:44 AM
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);
Solved! Go to Solution.
2019-07-26 01:29 AM
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
2019-07-26 01:29 AM
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