[riot-notifications] [RIOT-OS/RIOT] drivers/ds75lx: add basic driver for temperature sensor (#11505)

Parks Projets notifications at github.com
Thu May 16 00:07:16 CEST 2019


ParksProjets commented on this pull request.



> +    }
+
+    /* Release I2C device */
+    i2c_release(DEV_I2C);
+
+    temp = (tmp[0] << 8) | tmp[1];
+    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:
https://github.com/RIOT-OS/RIOT/pull/11505#discussion_r284470692
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190515/24ee946e/attachment.html>


More information about the notifications mailing list