Shop OBEX P1 Docs P2 Docs Learn Events
DS18B20 interface problem — Parallax Forums

DS18B20 interface problem

LarrydogLarrydog Posts: 3
edited 2009-05-15 00:09 in BASIC Stamp
I have been trying to connect a DS18B20 to BS2p24.· I have tried a couple sample programs and have the same results on both programs.· The output reads 85C· / 185F.· Any help or pointers.

Thanks Larry

Sample one:
' {$STAMP BS2p}
' {$PBASIC 2.5}
' Tracy Allen, EME Systems
' DS18B20 (12 bit) program displays temperature, -55 to +125 Celsius +/- 0.1 degree
' For a single DS18B20 on the one-wire buss--the skip ROM command is used here.
' If more than one is on the buss, then the match ROM command must be used.
' Note that this routine is not good for the older 8-bit DS1820 nor the DS18S20.
degC VAR Word
signC VAR degC.BIT15·· ' alias for sign bit
degF VAR Word
signF VAR degF.BIT15·· ' alias for sign bit
DO
· OWOUT 0,1,[noparse][[/noparse]$CC, $44]
· DO : OWIN 0,4,[noparse][[/noparse]degC] : LOOP UNTIL degC· ' wait for done
· OWOUT 0,1,[noparse][[/noparse]$CC, $BE]
· OWIN 0,2,[noparse][[/noparse]degC.BYTE0, degC.BYTE1]
· degC = -signC ^ (ABS degC */ 160) + signC·· ' convert to degC*10, good for -degC too.
· degF = degC + 1000 * 9 / 5 - 1800·· ' convert to F using offset trick
· DEBUG "degC=", REP "-"\signC, DEC ABS degC/10, ".", DEC1 ABS degC,TAB
· DEBUG "degF=", REP "-"\signF, DEC ABS degF/10, ".", DEC1 ABS degF, CR
· PAUSE 1000
LOOP

Sample two:
' OWIN_OWOUT.bsp
' 1-Wire Digital Thermometer chip using the BS2p's 1-Wire commands. Connect
' the BS2p, BS2pe, or BS2px to the DS1822 as shown in the diagram in the
' OWIN or OWOUT command description. This program uses a simplified
' approach that ignores the fractional portion of the temperature.
' {$STAMP BS2p}
' {$PBASIC 2.5}
DQ PIN· 0 ' 1-Wire buss pin
RdROM CON $33 ' read serial number
MatchROM CON $55 ' match SN -- for multiple devices
SkipROM CON $CC ' ignore SN -- use for one device
CvrtTmp CON $44 ' start temperature conversion
RdSP CON $BE ' read scratch pad
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT11 ' 1 = negative temperature
tLo VAR tempIn.BYTE0
tHi VAR tempIn.BYTE1
tSign VAR Bit ' saved sign bit
tempC VAR Word ' final Celsius temp
tempF VAR Word ' final Fahrenheit temp
Main:
DO
GOSUB Get_Temperature ' read temperature from DS1822
DEBUG· HOME,
"DS18B20", CR,
"
", CR,
SDEC tempC, " C ", CR,
SDEC tempF, " F "
PAUSE 1000
LOOP
END
Get_Temperature:
OWOUT DQ, 1, [noparse][[/noparse]SkipROM, CvrtTmp] ' send convert temperature command
DO ' wait on conversion
PAUSE 25 ' small loop pad
OWIN DQ, 4, [noparse][[/noparse]tempIn] ' check status (bit transfer)
LOOP UNTIL (tempIn) ' 1 when complete
OWOUT DQ, 1, [noparse][[/noparse]SkipROM, RdSP] ' read DS1822 scratch pad
OWIN DQ, 2, [noparse][[/noparse]tLo, tHi] ' get raw temp data
tSign = sign ' save sign bit
tempC = tempIn >> 4 ' round to whole degrees
tempC.BYTE1 = $FF * tSign ' correct twos complement bits
tempF = (ABS tempC) * 9 / 5 ' start F conversion
IF (tSign) THEN ' finish F conversion
tempF = 32 - tempF ' C was negative
ELSE
tempF = tempF + 32 ' C was positive
ENDIF
RETURN

Comments

  • Radridz3Radridz3 Posts: 49
    edited 2009-05-14 07:54
    Try hooking the ds1820's power pins to ground. NO+ and NEg-
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-05-14 17:17
    You do have the pullup resistor on the 1wire line, right? Does the value reported change as you heat or cool the device? Are you sure it is a "B", DS18B20?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • FranklinFranklin Posts: 4,747
    edited 2009-05-14 19:21
    Somebody said...
    The output reads 85C· / 185F
    According to the datasheet this is the default value returned if no conversion took place.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • LarrydogLarrydog Posts: 3
    edited 2009-05-14 22:12
    The device is DS18B20·thought this might be the problem and have checked it.· I have two device and they both·act the same.· There is no change in the read when heated or cooled.· If this is the default output if no conversion.·

    Thanks for the help.

    Larry

  • FranklinFranklin Posts: 4,747
    edited 2009-05-14 23:42
    could you attach your actual code using the attachment manager and a drawing of how you have it hooked up?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • LarrydogLarrydog Posts: 3
    edited 2009-05-15 00:09
    I have the DS18B20 connected to pin 0 & have a 4.7K resistor connected between Vcc & pin 0.· Vcc & GND are also connected to the DS18B20.· This is breadboard out on a Parallax Professional Development Board·with BS2p24.·

    Thanks
    Larry
Sign In or Register to comment.