Shop OBEX P1 Docs P2 Docs Learn Events
One Wire Problem with DS18B20 — Parallax Forums

One Wire Problem with DS18B20

I decided to learn about the One Wire interface; got four pieces DS18B20 temperature sensors from Jameco.
Found I couldn't use MatchROM (to sort out multiple devices on 1 OneWire) reliably.  Some devices appear to not respond correctly to their serial number.  Got it down to the attached program in which I1.  Read and display the temperature using SkipROM.2.  Read, save, and display the 64-bit ROM.3.  Read and display the temperature using MatchROM and the exact ROM pattern I just read.
Three of the devices work reading the temperature using SkipROM and return what appears to be a perfectly good ROM pattern, but then do not respond when I re-read the temperature using MatchROM.  One of four does return the correct temperature with MatchROM.
One thing which I don't know is clue or a red herring:  The device that seems to be working correctly has a ROM checksum of all zeroes.
4.7K pullup on the OneWire wire, DS18B20 powered from VDD.
I doubt that I got 3 or 4 bad parts; must be a problem with the code which I cannot find.  I am hoping that someone who knows about OneWire and OWOUT/OWIN can help me.  Code is attached.

Comments

  • Well, I figured it out. Kinda.
    I tried with a Propellor (using jm_ds1822_demo from OBEX) and, LO, the devices produced different checksums (except for the one that was x00).  The family code and the serial numbers were the same, just the checksum was different.
    I noticed that Jon was reading the ROM one byte at a time, and tried the same thing with the BS-2 (FOR/NEXT loop instead of all eight bytes in a single OWIN).  Problem went away.  Now the dead time between bytes using a loop is about 400 uSec vs 100 uSec.  Don't see why that would make a difference but it clearly does.
  • If you use the right mode you can insert all at once.
    Get_Temperature:
    
    
    
      OWOUT DQ, 1, [ MatchRom,$28,$D4,$04,$60,$07,$00,$00,$F3]  'Match serial number to your device
      OWOUT DQ, 0, [ CvrtTmp]                ' send convert temperature command
      DO                                    ' wait on conversion
        PAUSE 25                            ' small loop pad
        OWIN DQ, 4, [tempIn]                ' check status (bit transfer)
      LOOP UNTIL (tempIn)
       OWOUT DQ, 1, [ MatchRom,$28,$D4,$04,$60,$07,$00,$00,$F3]
    
      OWOUT DQ, 0, [ RdSP]                  ' read DS1822 scratch pad
      OWIN  DQ, 2, [tLo, tHi]               ' get raw temp data
    
  • Hi Tom,

    For reference, Jon Williams included a one-wire search program along with his April 2001 N&V column "Searching the 1-Wire Bus". On Parallax web site.

    I'm attaching a program I used that covers the -55 to +125 °C range with 0.1 °C resolution. However, it does not search the bus and assumes there is only one device present.
  • Thanks, guys. I use the Am2303 these days. Gives back temp and humidity.
  • Now I see the date on your original post! Well, it never hurts to review I guess.

    How are you liking the Am2303? I've seen it advertised but haven't tried one. The Adafruit document says it contains a DS18B20 for the temperature, and the RH must also be one-wire. So, can you hang a bunch of them on one buss?

  • tomcrawfordtomcrawford Posts: 1,126
    edited 2016-01-04 21:28
    Here is a pointer to a simpleIDE "C" driver.

    It *is* an interface with one wire, but is *not* a one-wire compatible interface. Edit: You pretty much have to spend an I/O on each of them. No hanging a bunch on a buss. EndEdit

    It is also clearly beyond the capabilities of a BS-2. Having said that, it works just fine with propellor, in C or in spin.
Sign In or Register to comment.