This discussion shows how to interface a Dallas Semiconductor DS1620 Thermometer with the Basic Stamp BS2.
A data sheet is available in Adobe .pdf format from
The following discussion is in rough form. It will be reworked and eventually it will become a part of a new book which discuuses interfacing with serial devices. But, in the interim, you may find it useful.
Program DS_1620_1.BS2 illustrates how to write to the configuration register, start temperature conversions, read the temperature from the device and stop the temperature conversions so as to save power when temperature readings are not required.
The configuration register is configured in subroutine config_1621 by writing the command $0c followed by the data $02 to configure the 1621 in a CPU controlled mode with continuous temperature conversion. The temperature conversion process is then initiated in subroutine start_convert with the $ee command. Readings are then made in subroutine meas by sending the $aa command and then reading the nine bits from the 1621. After ten readings, the loop is exited and the conversion process is halted using subroutine stop_convert by sending the command $22.
My handling of the conversion to temperature by simply dividing the nine bits received from the 1621 by 2 is clumsy as it sacrifices the 0.5 resolution.
' DS1620_1.BS2 ' ' Illustrates how to measure temperature using DS1620 3-Wire Thermometer ' ' BS2 DS1620 ' ' Pin2 (term 7) -------------------- DQ (term 1) ' Pin1 (term 6) -------------------- CLk (term 2) ' Pin0 (term 5) -------------------- RST (term 3) ' ' ' Debug statements were included only to see what is going on. ' ' Program configures 1620 for CPU operation, starts conversion, makes ' 10 measurments and stop conversion. ' ' copyright H. Paul Roach, MSU, March 13, '97 ' o_byte var byte ' byte sent to DS1620 i_9_bit var word ' reaw temperature data from 1620 n var byte ' index times var byte ' number of measurements dirs = $f0ff IN con 0 OUT con 1 RST con 0 CLK con 1 DQ con 2 DQ_OUT var out2 DQ_IN var in2 DQ_DIR var dir2 main gosub config_1620 ' configure 1620 gosub start_convert ' continuous conversion for times=1 to 10 ' make 10 measurments gosub meas T_C = i_9_bit/2 debug dec T_C sleep 60 ' one minute between readings next gosub stop_convert ' stop conversion process to save power stop config_1620 ' send command $0c followed by $02 to configure ' for CPU mode low RST high CLK high RST ' initiate by bringing RST high o_byte = $0c gosub out_byte o_byte = $02 gosub out_byte low RST pause 200 ' give some time for the internal programming return start_convert ' send command $ee to cause continuous conversion high CLK high RST o_byte = $ee gosub out_byte low RST return meas ' send command $aa to read data and then read high CLK high RST o_byte = $aa gosub out_byte gosub read_9_bits low RST return stop_convert ' send command $22 to stop the conversions high CLK high RST o_byte = $22 gosub out_byte low RST return out_byte ' outputs byte in o_byte, beginning with least ' significant bit DQ_DIR=OUT for n = 0 to 7 DQ_OUT = o_byte & $01 'least significant bit low CLK debug dec DQ_OUT high CLK o_byte = o_byte >> 1 'shift data 1 place right next debug 13 return get_9_bits ' reads 9 bits from 1620 beginning with least ' significant bit DQ_DIR = IN i_9_bit = 0 for n = 0 to 8 low CLK i_9_bit = (i_9_bit >> 1) | (DQ_IN << 8) debug dec D_IN high CLK next DQ_DIR=OUT debug 13 return