Skip to main content
Visitor II
April 30, 2020
Question

LIS2MDL embedded temperature sensor

  • April 30, 2020
  • 2 replies
  • 1068 views

Hello,

I try to use LIS2MDL embedded temperature sensor value, thru TEMP_OUT_L_REG and TEMP_OUT_H_REG. Data is signed 16-bit byte in 2’s complement and 8 LSB / °C. The four most

significant bits contain a copy of the sign bit.

At room temperature I read 0xFE20, so it is negative, so I convert in positive value with 2’s complement : NOT(0xFE20) + 1 = 480 in decimal. Then I div by 8 and I find 60, so -60°C.

What is wrong ?

Thanks

Best Regards

Thomas

    This topic has been closed for replies.

    2 replies

    ST Employee
    April 30, 2020

    Hi @Community member​ , I suggest you look at the C drivers for the LIS2MDL device on Github repository. The temperature conversion is shown in the code below:

    float_t lis2mdl_from_lsb_to_celsius(int16_t lsb)
    {
     return (((float_t)lsb / 8.0f) + 25.0f);
    }

    Being the sensitivity 8 digit/°C, I believe you have to divide your value by 2^8=256, meaning -480/256 = -1.875°C, and then add 25°C, meaning 23.125°C which could be a room temperature.

    Regards

    Visitor II
    July 9, 2024

    Hi Eleon,

    I have a similar problem and am a bit confused. The drivers state that you have to divide by 8, but you seem to suggest that the correct conversion implies a division by 2^8. So what's the correct way to do the conversion?

    In my case, I am measuring raw values that result in valid (room) temperatures regardless of whether I divide by 8 or by 2^8.

    Regards

    Visitor II
    April 30, 2020

    Hi Eleon, that's perfect thank you !