PDA

View Full Version : 1wire reset pulse



Karl_T
01-28-2010, 07:55 PM
I've been trying to get a 1wire temp sensor to work with a stamp for some time now. There's been the same issue the whole time: Can read the data from the DS1820 temp sensor but can't command it to resample the current temperature.
In consulting with a EE type I know, the 1wire device requires a reset pulse to get attention before sending the "convertTemp" command. This appears to not be happening.

An example of code for Javelin has this:
(clip from EE's note next)
<begin clip>
Have a look at:
AppNote001a_Getting_Started_with_1-Wire.PDF·· (Which is archived as:)
http://www.parallax.com/ProductInfo/Microcontrollers/Applications/tabid/430/Default.aspx#AN001
...if you would, please.
You might be able to create a version of their source that'll
talk to your DS1822.
Their source appears to have a bunch of initialization stuff
in the beginning. This may be useful to you.
You'll note the use of a reset command in their example:
// Send reset pulse to 1-wire bus.
oneWireBus.reset();
*That* is what I was looking for. :)
<end clip>

I've tried multiple examples of stamp code. The best one is copied below
The output of this particular program is:

DS1822 Data
Serial Number : 0000002488F0
·Checksum : 6C
·Raw Input : 0000010101010000
·Temp C : 85°°
·Temp F : 185°

Sorry, this got long. My question, anybody know how to command this reset pulse outside of the OWOUT command? (I've played with the mode parameter a lot - no joy) Or maybe I'm missing something else. Surely somebody has made a 1wire sensor work.
Karl





<example program>
' -----[Title ]----------------------------------------------------------------
'
' BS2p Professional Starter Kit
'
' File...... PSK_DS1822.BSP
' Purpose... Reads and displays information from a Dallas DS1822
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com (mailto:stamptech@parallaxinc.com)
' Started...
' Updated... 10 DEC 2001
' {$STAMP BS2px}
' -----[ ProgramDescription ]--------------------------------------------------
'
' This program demonstrates using the DS1822 in its simplest form for direct
' temperature measurement. With only one sensor, we can use SkipROM and ignore
' the device serial number.
'
' Program output is via DEBUG.
' -----[ Revision History ]-----------------------------------------------------
'
' -----[ I/O Definitions ]------------------------------------------------------
'
OWpin CON 15
' -----[Constants ]------------------------------------------------------------
'
' 1-Wire Support
'
OW_FERst CON %0001 ' Front-End Reset
OW_BERst CON %0010 ' Back-End Reset
OW_BitMode CON %0100
OW_HighSpd CON %1000
ReadROM CON $33 ' read ID, serial num, CRC
MatchROM CON $55 ' look for specific device
SkipROM CON $CC ' skip rom (one device)
SearchROM CON $F0 ' search
' DS1822 control
'
CnvrtTemp CON $44 ' do temperature conversion
RdScratch CON $BE ' read scratchpad
NoDevice CON %11 ' no device present
DS1822 CON $22 ' device code
DegSym CON 176
' -----[Variables ]------------------------------------------------------------
'
devCheck VAR Nib ' device check return ocde
idx VAR Byte ' loop counter
romData VAR Byte(8) ' ROM data from DS1820
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT11 ' 1 = negative temperature
tLo VAR tempIn.LOWBYTE
tHi VAR tempIn.HIGHBYTE
tSign VAR Bit
tempC VAR Word ' Celsius
tempF VAR Word ' Fahrenheit
' -----[ EEPROM DATA ]----------------------------------------------------------
'
' -----[Initialization ]-------------------------------------------------------
'
Initialize:
DEBUG CLS
PAUSE 250 ' allow DEBUG screen to open
' -----[ Main Code ]------------------------------------------------------------
'
Main:
GOSUB Device_Check ' look for device
IF (devCheck <> NoDevice) THEN Get_ROM
No_Device_Found:
DEBUG CLS,"No DS1822 present.", CR
DEBUG "-- Insert device and re-start."
END
Get_ROM
OWOUT OWpin,OW_FERst,[ReadROM] ' send Read ROM command
OWIN OWpin,OW_BERst,[STR romData\8] ' read serial number & CRC
IF (romData(0) = DS1822) THEN Show_Data
DEBUG "Installed device is not DS1822", CR
DEBUG "-- Code = ",HEX2 romData(0)
END
Show_Data:
DEBUG HOME, "DS1822 Data",CR,CR
DEBUG "Serial Number : "
FOR idx = 6 TO 1
DEBUG HEX2 romData(idx)
NEXT
DEBUG CR," Checksum : ",HEX2 romData(7),CR,CR
Show_Raw:
GOSUB Get_Temp
DEBUG " Raw Input : ",BIN16 tempIn,CR,CR
Display_Temperatures:
DEBUG " Temp C : ", SDEC tempC,DegSym,CR
DEBUG " Temp F : ", SDEC tempF,DegSym,CR
PAUSE 1000
GOTO Main
END
' -----[Subroutines ]----------------------------------------------------------
'
' This subroutine checks to see if any 1-Wire devices are present on the
' bus. It does NOT search for ROM codes
'
Device_Check:
devCheck = 0
OWOUT OWpin,OW_FERst,[SearchROM] ' reset and start search
OWIN OWpin,OW_BitMode,[devCheck.BIT1,devCheck.BIT0]
RETURN
Get_Temp:
OWOUT OWpin,OW_FERst,[SkipROM,CnvrtTemp] ' send conversion command
PAUSE 500 ' give it some time
OWOUT OWpin,OW_FERst,[SkipROM,RdScratch] ' go get the temperature
OWIN OWpin,OW_BERst,[tLo,tHi]
tSign = sign ' save sign bit
tempC = tempIn
tempC = tempC >> 4 ' round to whole degrees
IF (tSign = 0) THEN NoNegC
tempC = tempC | $FF00 ' extend sign bits for negs
NoNegC:
tempF = tempC */ $01CD ' multiply by 1.8
IF tSign = 0 THEN NoNegF ' if neg, extend sign bits
tempF = tempF | $FF00
NoNegF:
tempF = tempF + 32 ' finish C -> F conversion
RETURN
·

$WMc%
01-29-2010, 09:08 AM
Karl_T

This line of code looks like it might be a problem "IF (romData(0) = DS1822) THEN Show_Data".
It seems like it should be "IF (romData()=DS1822))THEN Show_Data"
or "IF (romData(0)=DS1822))THEN Show_Data, But I don't think the "0" shouldn't be their.

I don't have time tonight to look at the specs for the DS1822 but I have used this in the past with good results.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············___$WMc%___······················ ······ BoogerWoods, FL. USA

Franklin
01-29-2010, 12:19 PM
If you use the post reply button you can then use the attachment manager to attach your code file to your next post.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen