> > @@ -78,7 +80,7 @@ static void tmp105_set_temperature(Object *obj, Visitor > > *v, void *opaque, > > return; > > } > > > > - s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4; > > + s->temperature = (int16_t) (temp * 256 / 1000); > > Did you check whether those magic 4 bits shift were for some other > purpose such as flags possibly? CC'ing Alex Horn.
>From the data sheet, the temperature register is 9-12 bits, depending on the configuration. So the low 4 bits will always read back as zero. However, they are already masked away when reading the temperature in tmp105_read: s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8); s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) & (0xf0 << ((~s->config >> 5) & 3)); /* R */ The equivalence of the formula can be proved as follows: ((int16_t) (temp * 0x800 / 128000)) << 4 = (int16_t) (temp * 0x8000 / 128000) & ~15 = (int16_t) (temp * (0x100 * 0x80) / (1000 * 0x80)) & ~15 = (int16_t) (temp * 0x100 / 1000) & ~15 and the AND can be removed as mentioned above. > Since we do have a tmp105-test, we should also add a regression test for > the getter bug. Yeah, if only tmp105-test already tested the setter. :) Paolo