[riot-notifications] [RIOT-OS/RIOT] drivers/ds75lx: add basic driver for temperature sensor (#11505)
notifications at github.com
Wed May 15 23:37:12 CEST 2019
fjmolinas 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));
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:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the notifications