Hi, in the compiler's one-wire example in the library manager I think I found 2 issues:
a.
Code: Select all
// Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
// 18S20: 9 (default setting; can be 9,10,11,or 12)
// 18B20: 12
In above it is the 18S20 that has always a resolution of 9 byte, and the 18B20 has a programmable resolution of 9, 10, 11 or 12 bits.
b.
Code: Select all
const TEMP_RESOLUTION : byte = 9;
const RES_SHIFT = TEMP_RESOLUTION - 8;
Code: Select all
// Extract temp_whole
temp_whole := word(temp2write shr RES_SHIFT);
Above code will only work well for the DS18S20, not for the DS18B20. The datasheet states that the shift to be used for the 18B20 is always 4, irrespective of the resolution set.
For the 18S20 the shift is always 1.
Code: Select all
// Extract temp_fraction and convert it to unsigned int
temp_fraction := word(temp2write shl (4-RES_SHIFT));
In above code the shift is only needed for the DS18S20, and only if a 4 digits after the decimal point -- of which 3 will be zero -- are needed in the string result. If only 1 decimal point is needed in the string result then no shift is needed at all.
For the DS18B20 a shift is never needed and above code gives an incorrect result.
Thanks for the adaptation! Keep up the good work!
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)