Shop OBEX P1 Docs P2 Docs Learn Events
interfacing DS1820 with BS2 — Parallax Forums

interfacing DS1820 with BS2

SourabhSourabh Posts: 5
edited 2005-12-01 22:30 in BASIC Stamp
I am having toruble interfacing the DS1820 with BS2. I am trying to display the temperature on a 2x16 serial LCD which I bought from parallax itself. I have connected the data pin of DS1820 to pin 11 of BS2 using a 4.7k resistor. It is similar to Jon William's code to interface the 1820 and BS Sx plus.

Here is my code:

' {$STAMP BS2}
' {$PBASIC 2.5}
LCDpin CON 0 ' data on pins 4 - 7
DS1820pin CON 11
B_19200 CON 32
NoCmd CON $00 ' just print
DDRam CON $80 ' Display Data RAM control
Line1 CON $80 ' address of line 1
Line2 CON $C0 ' address of line 2
DegSym CON 223 ' degrees symbol
ReadROM CON $33 ' read ID, serial num, CRC
MatchROM CON $55 ' look for specific device
SkipROM CON $CC ' skip rom (one device)
ConvertTemp CON $44 ' do temperature conversion
ReadScratch CON $BE ' read DS1820 scratchpad
' ----[noparse][[/noparse] Variables ]
'
idx VAR Byte ' loop counter
romData VAR Byte(8) ' ROM data from DS1820
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT8 ' 1 = negative temperature
tInLow VAR tempIn.LOWBYTE
tInHigh VAR tempIn.HIGHBYTE
tSign VAR Bit
tempC VAR Word ' Celsius
tempF VAR Word ' Fahrenheit
Main:
HIGH LCDpin
PAUSE 100
TempDemo:
SEROUT LCDpin,B_19200,[noparse][[/noparse]"CURRENT TEMP:"]
ShowTemp:
SEROUT DS1820pin,B_19200,[noparse][[/noparse]SkipROM]
SEROUT DS1820pin,B_19200,[noparse][[/noparse]ConvertTemp]
PAUSE 500 ' give time for conversion
SEROUT DS1820pin,B_19200,[noparse][[/noparse]SkipROM]
SEROUT DS1820pin,B_19200,[noparse][[/noparse]ReadScratch]
PAUSE 500
SERIN DS1820pin,16780,[noparse][[/noparse]tInLow,tInHigh] ' read temperature
tSign = sign ' save sign bit
tempIn = tempIn/2 ' round to whole degrees
IF tSign = 0 THEN NoNeg1
tempIn = tempIn | $FF00 ' extend sign bits for negs
NoNeg1:
tempC = tempIn ' save Celsius value
tempIn = tempIn */ $01CC ' multiply by 1.8
IF tSign = 0 THEN NoNeg2 ' if neg, extend sign bits
tempIn = tempIn | $FF00
NoNeg2:
tempF = tempIn+32 ' finish C -> F conversion
' display temps
'
SEROUT LCDpin,Line2,[noparse][[/noparse]SDEC tempC, DegSym, " C"]
SEROUT LCDpin,NoCmd,[noparse][[/noparse]" / ", SDEC tempF, DegSym, " F"]
SEROUT LCDpin,NoCmd,[noparse][[/noparse]REP " "\6]
PAUSE 1500
'GOTO ShowTemp ' update temp display








Thanks,
Sourabh

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-30 22:29
    No can do, Buckaroo... the DS1820 is a 1-Wire device and our BS2p series are the only BASIC Stamp modules that directly support that protocol.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SourabhSourabh Posts: 5
    edited 2005-11-30 22:40
    I have modified the code according to BS2 syntax. I think there is a problem with the baud rate, due to which it does not display the temperature. Please help.

    Thanks,
    Sourabh
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-01 00:34
    What I think you're missing is that the DS1820 uses the Dallas/Maxim 1-Wire protocol and the only BS2 modules that support that protocol is the BS2p and higher. You cannot connect the DS1820 directly to the BS2 (or BS2e or BS2sx) -- you would need to use a DS2480 Serial 1-Wire driver chip? ·Do you have that chip (your post says nothing about it).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 12/1/2005 12:37:41 AM GMT
  • SourabhSourabh Posts: 5
    edited 2005-12-01 22:30
    Thanks a lot, I did'nt know that! i will work on it and let you know.
Sign In or Register to comment.