The TeensyDuino One Wire library website contains this description:
The DS18x20_Temperature does not properly handle lower resolution (faster) modes on some chips. Thanks to Pete Hardie for this fix. Replace this:
} else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
With this:
} else {
unsigned char t_mask[4] = {0x7, 0x3, 0x1, 0x0};
byte cfg = (data[4] & 0x60) >> 5;
raw &= ~t_mask[cfg];
}
I would like to know: is the following code equivalent? Would it be more performant since it has no addressing operations?
raw &= ~0 << (3 – ((data[4] >> 5) & 3));
Does anyone have an applicable DS18x20_Temperature device to check this?
Thanks!