Interfacing the DS1620 ( well almost )
I do have some BS2 experience, but I am completely stumped. I am trying to
interface the DS1620 thermometer. I copied the code from the APP note, wired it
up, and Tthe data reads back in the freezing range with the device at ambient
temperature. I started looking at the code and tried to verify the
configuration. I can't do that either.
I figure if i can't read the configuration, I'm probably not writing it properly
either.
' This program interfaces the DS1620 Digital Thermometer to
' the BS2. Input and output routines can be combined to set
' the '1620 for thermometer or thermostat operation, read
' or write nonvolatile temperature setpoints and configuration
' data. In addition to using the BS2's new Shiftin and Shiftout
' instructions to communicate with the 1620, this program uses
' new math and display operators that work with signed integers.
' This makes it relatively easy to convert between degrees C and
' F and to display both positive and negative temperature
' readings. Note that after math operations on negative numbers
' it's necessary to "extend the sign bits." All this means is
' setting all of the bits to the left of actual value to 1s.
' Also note the use of the new */ (pronounced 'star-slash')
' operator. This works like multiplying by an integer (0-255)
' and a fraction (in units of 1/256). For example, to multiply
' 17 by Pi (approx 3.1416) would be written "17 */ $0324."
' The second value is written in hex to emphasize that it's being
' split into bytes: $03 is the integer and $24/$100 is the fraction.
' In the C-to-F conversion below, we multiply the C value by 1.8
' with "*/ $01CC" since $CC/$FF (204/256) = 0.8.
' ===================== Define Pins and Variables ================
Myread VAR word
DQ con 2 ' Pin 2 <=> DQ.
CLK con 1 ' Pin 1 => CLK.
RST con 0 ' Pin 0 => RST (high = active).
DSdata var word ' Word variable to hold 9-bit data.
Sign var DSdata.bit8 ' Sign bit of raw temperature data.
T_sign var bit ' Saved sign bit for converted temperature.
' ===================== Define DS1620 Constants ===================
' >>> Constants for configuring the DS1620
Rconfig con $AC ' Protocol for 'Read Configuration.'
Wconfig con $0C ' Protocol for 'Write Configuration.'
CPU con %10 ' Config bit: serial thermometer mode.
NoCPU con %00 ' Config bit: standalone thermostat mode.
OneShot con %01 ' Config bit: one conversion per start request.
Cont con %00 ' Config bit: continuous conversions after start.
' >>> Constants for serial thermometer applications.
StartC con $EE ' Protocol for 'Start Conversion.'
StopC con $22 ' Protocol for 'Stop Conversion.'
Rtemp con $AA ' Protocol for 'Read Temperature.'
' >>> Constants for programming thermostat functions.
RhiT con $A1 ' Protocol for 'Read High-Temperature Setting.'
WhiT con $01 ' Protocol for 'Write High-Temperature Setting.'
RloT con $A2 ' Protocol for 'Read Low-Temperature Setting.'
WloT con $02 ' Protocol for 'Write Low-Temperature Setting.'
Using the DS1620 Digital Thermometer / Thermostat
sales / technical support (916) 624-8333 · fax (916) 624-8003
pictech@p... · stamptech@p... Page 17
BASIC Stamp II Program Listing: Thermometer (cont.)
' ===================== Begin Program ============================
low RST ' Deactivate '1620 for now.
high CLK ' Put clock in starting state.
pause 100 ' Let things settle down a moment.
high RST ' Activate the '1620 and set it for continuous..
shiftout DQ,CLK,lsbfirst,[noparse][[/noparse]Wconfig,%10] ' ..temp conversions.
low RST ' Done--deactivate.
pause 50 ' Wait for the EEPROM to self-program.
high RST ' Now activate it again and send the..
shiftout DQ,CLK,lsbfirst,[noparse][[/noparse]Rconfig] ' Send start-conversion protocol.
shiftin DQ,CLK,lsbpre,[noparse][[/noparse]Myread]
low RST ' Done--deactivate.
DEBUG ? Myread
"Myread" reads back as 0. I rewrote the code here, but I get no errors when I
download. I hope I am missing something in the syntax, but I can't se it. My
Stamp is a BS2 and I am using the PBasic 2.5
Thanks
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
[noparse][[/noparse]Non-text portions of this message have been removed]
interface the DS1620 thermometer. I copied the code from the APP note, wired it
up, and Tthe data reads back in the freezing range with the device at ambient
temperature. I started looking at the code and tried to verify the
configuration. I can't do that either.
I figure if i can't read the configuration, I'm probably not writing it properly
either.
' This program interfaces the DS1620 Digital Thermometer to
' the BS2. Input and output routines can be combined to set
' the '1620 for thermometer or thermostat operation, read
' or write nonvolatile temperature setpoints and configuration
' data. In addition to using the BS2's new Shiftin and Shiftout
' instructions to communicate with the 1620, this program uses
' new math and display operators that work with signed integers.
' This makes it relatively easy to convert between degrees C and
' F and to display both positive and negative temperature
' readings. Note that after math operations on negative numbers
' it's necessary to "extend the sign bits." All this means is
' setting all of the bits to the left of actual value to 1s.
' Also note the use of the new */ (pronounced 'star-slash')
' operator. This works like multiplying by an integer (0-255)
' and a fraction (in units of 1/256). For example, to multiply
' 17 by Pi (approx 3.1416) would be written "17 */ $0324."
' The second value is written in hex to emphasize that it's being
' split into bytes: $03 is the integer and $24/$100 is the fraction.
' In the C-to-F conversion below, we multiply the C value by 1.8
' with "*/ $01CC" since $CC/$FF (204/256) = 0.8.
' ===================== Define Pins and Variables ================
Myread VAR word
DQ con 2 ' Pin 2 <=> DQ.
CLK con 1 ' Pin 1 => CLK.
RST con 0 ' Pin 0 => RST (high = active).
DSdata var word ' Word variable to hold 9-bit data.
Sign var DSdata.bit8 ' Sign bit of raw temperature data.
T_sign var bit ' Saved sign bit for converted temperature.
' ===================== Define DS1620 Constants ===================
' >>> Constants for configuring the DS1620
Rconfig con $AC ' Protocol for 'Read Configuration.'
Wconfig con $0C ' Protocol for 'Write Configuration.'
CPU con %10 ' Config bit: serial thermometer mode.
NoCPU con %00 ' Config bit: standalone thermostat mode.
OneShot con %01 ' Config bit: one conversion per start request.
Cont con %00 ' Config bit: continuous conversions after start.
' >>> Constants for serial thermometer applications.
StartC con $EE ' Protocol for 'Start Conversion.'
StopC con $22 ' Protocol for 'Stop Conversion.'
Rtemp con $AA ' Protocol for 'Read Temperature.'
' >>> Constants for programming thermostat functions.
RhiT con $A1 ' Protocol for 'Read High-Temperature Setting.'
WhiT con $01 ' Protocol for 'Write High-Temperature Setting.'
RloT con $A2 ' Protocol for 'Read Low-Temperature Setting.'
WloT con $02 ' Protocol for 'Write Low-Temperature Setting.'
Using the DS1620 Digital Thermometer / Thermostat
sales / technical support (916) 624-8333 · fax (916) 624-8003
pictech@p... · stamptech@p... Page 17
BASIC Stamp II Program Listing: Thermometer (cont.)
' ===================== Begin Program ============================
low RST ' Deactivate '1620 for now.
high CLK ' Put clock in starting state.
pause 100 ' Let things settle down a moment.
high RST ' Activate the '1620 and set it for continuous..
shiftout DQ,CLK,lsbfirst,[noparse][[/noparse]Wconfig,%10] ' ..temp conversions.
low RST ' Done--deactivate.
pause 50 ' Wait for the EEPROM to self-program.
high RST ' Now activate it again and send the..
shiftout DQ,CLK,lsbfirst,[noparse][[/noparse]Rconfig] ' Send start-conversion protocol.
shiftin DQ,CLK,lsbpre,[noparse][[/noparse]Myread]
low RST ' Done--deactivate.
DEBUG ? Myread
"Myread" reads back as 0. I rewrote the code here, but I get no errors when I
download. I hope I am missing something in the syntax, but I can't se it. My
Stamp is a BS2 and I am using the PBasic 2.5
Thanks
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
[noparse][[/noparse]Non-text portions of this message have been removed]