cancel
Showing results for 
Search instead for 
Did you mean: 

Temperature sensor on LIS2HH12 accelerometer

Jose Marcelino
Associate
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
1 ACCEPTED SOLUTION

Accepted Solutions
Legacy member
Not applicable
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 << 😎 | 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.

View solution in original post

12 REPLIES 12
Miroslav BATEK
ST Employee
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.
Legacy member
Not applicable
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 << 😎 | 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.

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.

Legacy member
Not applicable
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.

Posted on November 13, 2017 at 13:39

So what the '11-bit resolution' means in chapter 2.3 of the datasheet ?

Cause I receive strange values according to your method ( TEMP_H : 0xFA, TEMP_L : 0xA0 for example).

Posted on November 13, 2017 at 16:11

11-bits resolution means the value in encoded in the highest 11 bit of the 16 bit value (TEMP_H, TEMP_L).

Temperature sensor output change vs. temperature is 8 digit/°C which means 1LSB = 0.125

°C.

The value is encoded as two's complement.

So your example means -11.375°C (difference respect to a reference value).

Posted on November 13, 2017 at 17:23

I don't understand how you find -11.375°C, for tempHex, i have 1111 1010 1010 0000 (FAA0), what do you do after ?

Posted on November 13, 2017 at 17:58

1111 1010 1010 0000 (0xFAA0) ... 16-bit value 

111 1101 0101 ... 11-bit value, the value is left adjusted

2005 ... conversion to decimal value

2005 - 2048 = -43 ... conversion from

https://en.wikipedia.org/wiki/Two%27s_complement

-43 / 8 = -5.375

°C ... conversion to °C (8 digit/°C which means 1LSB = 0.125

°C)

I'm sorry, I did a mistake in conversion in my previous post.

Posted on February 27, 2018 at 19:01

Txs for the complete answer

Batek.Miroslav

‌ .It was not that intuitive to read the temp value from the sensor. Cheers