Skip to main content
Visitor II
June 19, 2017
Solved

Temperature sensor on LIS2HH12 accelerometer

  • June 19, 2017
  • 2 replies
  • 3450 views
Posted on June 19, 2017 at 20:00

We're using the LIS2HH12 accelerometer and there's a temperature sensor listed in the datasheet accessible via the temp_L and temp_H registers (16 bits).

However the numbers I get don't make any sense.

The datasheet mentions 'Temperature sensor output change vs. temperature' of 8 digit/�C

11-bit resolution, -40 to 80C range and that the it uses two's complement, but I can't find a way to make the readings return any meaningful value.

What do these 

temp_L and temp_H numbers really mean? Thank you.

#lis2hh12 #temperature-sensor
    This topic has been closed for replies.
    Best answer by
    Posted on June 21, 2017 at 08:52

    I think Jose is asking for the data interpretation. I would also appreciate a more detailed description in the datasheet.

    TEMP_H:TEMP_L is the raw sensor output - a signed 16-bit number, stored as two's complement.

    At 25 centigrades, the output is 0. For every centigrade, the sensor output value changes for 8 LSBs, meaning 1 LSB is a 0,125 centigrades change (2 LSBs 0,25 centigrades, 4 LSBs 0,5 centigrades etc.).

    So the basic formula is: TEMP_H:TEMP_L + temp_offset_25_centigrades = measured_temperature

    (Please note that negative TEMP_H:TEMP_L value doesn't necessarily mean a negative temperature.)

    I personally display 2 decimal digits in my applications, but use integer variables to keep the code fast and clean, so I read the sensor output data like this:

    int16_t tempHex = (temp_h << 8) | temp_l;

    and then do the following computation: multiply the sensor output value by

    TEMP_FRACTION_MULTIPLIER = 

    125 and divide it with

    TEMP_FRACTION_DIVIDER = 

    10. This way the value stored in the temperature register contains temperature value multiplied by a hunded (12.34 centigrades is stored as 1234 etc.). 

    TEMP_OFFSET = 2500 (for 25.00 centigrades).

    int32_t temperature = ((tempHex * TEMP_FRACTION_MULTIPLIER) / TEMP_FRACTION_DIVIDER) + TEMP_OFFSET;

    Or you can just divide TEMP_H:TEMP_L by 8 (shift by 3 positions to the right), discard the decimal points and use only the round value of centigrades. (You still need to add the offset of 25 centigrades.)

    Hope this helps a bit.

    2 replies

    ST Employee
    June 20, 2017
    Posted on June 20, 2017 at 11:07

    The temperature sensor can be used to measure temperature variations. 

    It isn't suitable to return absolute temperatures measures. The value represents difference respect to a reference not specified value.
    Answer
    June 21, 2017
    Posted on June 21, 2017 at 08:52

    I think Jose is asking for the data interpretation. I would also appreciate a more detailed description in the datasheet.

    TEMP_H:TEMP_L is the raw sensor output - a signed 16-bit number, stored as two's complement.

    At 25 centigrades, the output is 0. For every centigrade, the sensor output value changes for 8 LSBs, meaning 1 LSB is a 0,125 centigrades change (2 LSBs 0,25 centigrades, 4 LSBs 0,5 centigrades etc.).

    So the basic formula is: TEMP_H:TEMP_L + temp_offset_25_centigrades = measured_temperature

    (Please note that negative TEMP_H:TEMP_L value doesn't necessarily mean a negative temperature.)

    I personally display 2 decimal digits in my applications, but use integer variables to keep the code fast and clean, so I read the sensor output data like this:

    int16_t tempHex = (temp_h << 8) | temp_l;

    and then do the following computation: multiply the sensor output value by

    TEMP_FRACTION_MULTIPLIER = 

    125 and divide it with

    TEMP_FRACTION_DIVIDER = 

    10. This way the value stored in the temperature register contains temperature value multiplied by a hunded (12.34 centigrades is stored as 1234 etc.). 

    TEMP_OFFSET = 2500 (for 25.00 centigrades).

    int32_t temperature = ((tempHex * TEMP_FRACTION_MULTIPLIER) / TEMP_FRACTION_DIVIDER) + TEMP_OFFSET;

    Or you can just divide TEMP_H:TEMP_L by 8 (shift by 3 positions to the right), discard the decimal points and use only the round value of centigrades. (You still need to add the offset of 25 centigrades.)

    Hope this helps a bit.

    ST Employee
    June 21, 2017
    Posted on June 21, 2017 at 09:10

    I would like to add that the TEMP_OFFSET is not guaranteed to be 25 

    centigrades. There is certain level of uncertainty so please don't expect high precision of the temperature measurement.

    June 21, 2017
    Posted on June 21, 2017 at 17:00

    On the other hand, assuming that the temperature value output is linear in sensor's working conditions, the TEMP_OFFSET can be measured using a known calibrated thermometer and adjusted as a constant in a firmware later. This approach creates quite a reliable output (I personally do this with prototypes). However, needs to be done with every sensor, which is always not possible or meaningful.