Posted on June 21, 2017 at 08:52I 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.