Electronic – DS18B20 temperature interpretation

1-wiretemperature

I have a problem interpretting the temperature reading of a DS18B20 chip. There is a certain situation I am not abble to resolve. This is the example temp table for the chip from the datasheet:
enter image description here

an example for reading of -0.5*C is shown as FFF8. Cutting off the 4 LSBits we get 0x0FFF. In signed data structure that is equal to -1, not 0. How am I abble to resolve the difference between 2 readings: -0.5*C and -1.5*C? If 0xFFF8 = -0.5 then what is the form of -1.5?

The table then shows an example for -10.125*C. Cutting off the 4 LSBits gives 0x0FF5 which really is -10, then there is no reason to think that there is some kind of a shift for reading negative values…

Best Answer

You don't shift, you divide.

The value is a simple 16-bit signed integer that is 16 times larger than the temperature. Just assign the value to a 16-bit integer, then divide it by 16.0 as a floating point number:

int16_t min5s = 0xFF5E;
double d = (double)min5s / 16.0;
printf("%g\n", d);

>>> -10.125