Spin code with DS1820 thermometer
K6MLE
Posts: 106
Can someone show me the errors of my ways with the DS1820? I'm using the code for the DS1822 (Demo1.spin) and understand that the part defaults to 12-bit resolution. The DS1820 uses only 9-bit resolution. I've tried a few combinations of shifting bits around, but to no avail. My understanding is that the line reading:
temp := ow.readByte + ow.readByte << 8
is taking the lowest bit in the MSB of the temperature register and moving it to the highest bit position, then adding them together.
If I'm correct, the first ow.readByte command grabs the LSB of the temperature register; the second grabs the MSB. I've tried the code (unchanged) with a DS1822 and it works just fine! It seems that a shift of more than 7 bits will push bits into oblivion, therefore the code, as written, should not work.
Clearly I'm missing something quite simple! If someone can steer me back on track, I'd greatly appreciate it!
Thanks,
Michael
K6MLE
temp := ow.readByte + ow.readByte << 8
is taking the lowest bit in the MSB of the temperature register and moving it to the highest bit position, then adding them together.
If I'm correct, the first ow.readByte command grabs the LSB of the temperature register; the second grabs the MSB. I've tried the code (unchanged) with a DS1822 and it works just fine! It seems that a shift of more than 7 bits will push bits into oblivion, therefore the code, as written, should not work.
Clearly I'm missing something quite simple! If someone can steer me back on track, I'd greatly appreciate it!
Thanks,
Michael
K6MLE
Comments
temp := ow.readByte + ow.readByte << 8
so it takes the LSByte and then adds the MSByte shifted by 8 to form a WORD (16-Bit)
Enjoy!
Mike