Shop OBEX P1 Docs P2 Docs Learn Events
Spin code with DS1820 thermometer — Parallax Forums

Spin code with DS1820 thermometer

K6MLEK6MLE Posts: 106
edited 2012-12-29 17:47 in Propeller 1
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

Comments

  • msrobotsmsrobots Posts: 3,709
    edited 2012-12-29 17:47
    Byte not Bit, so

    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
Sign In or Register to comment.