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

Francisco notifications at github.com
Wed May 15 23:37:12 CEST 2019


fjmolinas 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));

Not sure if I'm missing something but if temp_frac is b'1000 this converts to 50 or 0.5, but if its b'1111 this converts to 93.75 or 0.9375 which is incorrect since it should be 0.0625.  Shouldn't you be using 2 complement of the fraction part  (since you have been using unsigned types for the fractional part)

` uint8_t temp_frac = ((~temp & 0x00f0) >> 4) + 1;`

-- 
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#pullrequestreview-238084296
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190515/cd571d31/attachment-0001.html>


More information about the notifications mailing list