[riot-notifications] [RIOT-OS/RIOT] drivers/ds75lx: add basic driver for temperature sensor (#11505)
notifications at github.com
Thu May 16 00:07:16 CEST 2019
ParksProjets commented on this pull request.
> + }
+ /* Release I2C device */
+ temp = (tmp << 8) | tmp;
+ DEBUG("[ds75lx] temperature register content 0x%04X\n", temp);
+ /* isolate integer part of the temperature */
+ int8_t temp_int = (temp & 0xff00) >> 8;
+ /* compute fractional part of the temperature, the LSB bits 3 to 0 are
+ always zero and not used in the conversion */
+ uint8_t temp_frac = (temp & 0x00f0) >> 4;
+ /* fractional part is a multiple of 0.0625. Temperature is returned in c°C */
+ *temperature = (temp_int * 100 + ((uint16_t)temp_frac * 100 >> 4));
No because only integral part is 2 complemented. Fractional part is always positive.
For example, for `-25.0625 °C` DS75LX returns `0xE6F0`. Here integral part is `0xE6` (which is -26 in 2-complement representation) and fractional part is `0b1111` (which represents 0.9375).
We can verify that **-26 + 0.9375 = -25.0625**.
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the notifications