Datasheet

Jon Waddington
30
Bits 11 to 15 are the sign bits. These define whether the temperature is positive or
negative. If it’s positive, these bits will be logic ‘0’. If the temperature is negative, these
bits will be logic ‘1’, and the temperature will be the two’s compliment of the
temperature.
The R0 and R1 bits of the configuration register are set to 0, meaning the temperature
resolution is 9 bits. This makes bits 0, 1 and 2 of the temperature redundant and the
temperature can be read in steps of 0.5°C. Examples of the temperature register are
shown in the table below
Temperature
MS Byte
LS Byte
+30.5
00000001
11101000
+25°C
00000001
10010000
0°C
00000000
00000000
-25°C
11111110
11110000
-30.5
11111110
00011000
The Spin code below shows how the temperature is read from the DS18B20 The “tin”
method initialises the 1-Wire object which starts a cog, dedicated to 1-Wire
communications. The program then waits for the cog to begin and a reset pulse is
transmitted. If a device is present, a CRC check is performed. If no errors are found in
the CRC, the “readtc” method is called which returns the value of the DS18B20’s
temperature registers. This is then passed to the “showc” method, which manipulates
the data to display it on the television screen. The cog is then fina lized, freeing a cog to
do other tasks if required.
PRI tin | status, temp, crc
ow.init(3) 'initialize 1-wire comms, pin 3 input
status := ow.reset ' check for device
if (status == %10) ' good 1W reset
crc := ow.crc8(@snum, 7) ' calculate CRC
if (crc <> snum[7]) ' compare with CRC in SN
text.str(string(" "))
text.hex(crc, 2)
text.str(string(" - bad CRC"))
repeat
else
temp := readtc ' read the temperature
showc(temp) ' display in °C
ow.finalize ‘free a cog
The Spin code below shows the “readtc” method. This begins by transmitting a reset










