I'm using the exact same code below and the temp is always -0.5C. On the BX24 it uses parasite power and it will alway return +85C. I've tried different DS1820s and get the same results.
Is there a good way to troubleshoot and find out where the problem is? I've checked and double checked but as far as I can tell it is hooked up correctly for the ZX24 code and it is the only thing hooked up to the processor. Also, I was told these are DS18S20 but on the side of the TO-92 package it says DS1820? Shouldn't it be a DS18S20?
Any help will be greatly appreciated.
TIA
David
Code: Select all
' This code is intended for the DS18S20 temperature chip
' operating in the externally powered mode (i.e. not
' powered parasitically via the DQ line). The code assumes
' the presence of a single device on the 1-wire bus.
Const owPin as Byte = 13 ' the pin to which the DQ line is connected
Sub Main()
Dim temp as Single
temp = readTemp()
Debug.Print "The temperature is "; Fmt(temp, 1); "*C"
End Sub
'
'' readTemp
'
' Request a temperature conversion and read the result. The
' return value is in degrees Centigrade.
'
Function readTemp() as Single
Dim b as Byte
Dim data(1 to 9) as Byte
' initialize the 1-wire interface (return value is the "presence" bit)
b = Reset1Wire(owPin)
' initiate a conversion
data(1) = &Hcc ' "skip ROM" command
data(2) = &H44 ' conversion command
Call Put1WireData(owPin, data, 2)
' delay to allow for the conversion
Call Delay(0.750)
' send another reset pulse
b = Reset1Wire(owPin)
' prepare to read the data
data(1) = &Hcc ' "skip ROM" command
data(2) = &Hbe ' "read scratchpad" command
Call Put1WireData(owPin, data, 2)
' read the data
Call Get1WireData(owPin, data, 9)
' send another reset pulse
b = Reset1Wire(owPin)
' compute the temperature
Dim ival as Integer Alias data(1)
readTemp = CSng(ival) / 2.0
End Function