While I am not familiar with the 1820 I did have problems with the 1620 when
I had my pin connections to long. I would get bogus data from the chip at
times until I shortened the connections.
Just a thought.
----- Original Message -----
From: "James R. Parish"
To:
Sent: Wednesday, February 13, 2008 6:33 PM
Subject: RE: [BasicX] Re: DS1820 1-wire temperature not working > Tried that, didn't work. Maybe my output routine
is not getting the data
> out correctly? I tried yours (PHAnderson) as well with no different
> results.
>
> '-----------------------
>
> ' OutByte_1Wire
>
> '
>
> ' Output a byte to the selected device on the bus.
> Sub OutByte_1W(ByVal Pin as Byte, ByVal OByte as Byte)
>
> DIM X as Byte
>
> FOR X = 0 to 7
>
> CALL Put1Wire (Pin, GetBit (OByte, X))
>
> NEXT
>
> End Sub
>
> THIS IS PRETTY MUCH STOCK:
>
> Function MakeTempMeas(ByVal Pin as Byte) as Single
>
> ' Returns temperature. Returns -89.99 if CRC error
>
> Dim N as Integer
>
> Dim Dat(1 To 9) as Byte, CRC as Byte
>
> Dim T_C as Single
>
> DIM OKAY as BOOLEAN
>
> OKAY = Init_1W(PIN)
>
> Call OutByte_1W(Pin, &HCC) 'skip ROM
>
> Call OutByte_1W(Pin, &H44) 'perform temperature conversion
> 'StrongPullUp
>
> CALL PutPin (Pin, bxOutputHigh)
>
> Call Sleep(0.70)
>
> CALL PutPin (Pin, bxInputTristate)
>
> OKAY = Init_1W(PIN)
>
> Call OutByte_1W(Pin, &HCC) ' skip ROM
>
> Call OutByte_1W(Pin, &HBE) ' get temperature data
>
> For N = 1 to 9
>
> Dat(N) = InByte_1W(Pin) ' fetch the nine bytes
>
> Next
>
> For N = 1 to 9
>
> Call PutHexB(Dat(N))
>
> Next
>
> CRC = CalcCRC(Dat, 9) ' calculate CRC of the 9 bytes
>
> DEBUG.PRINT
>
> DEBUG.PRINT "CRC = ";CSTR(CRC)
>
> If (CRC <>0) Then ' CRC
> failure
>
> T_C = -89.99
>
> Else
>
> If (Dat(2) = 0) Then ' its postive
>
> T_C = CSng(Dat(1)) / 2.0
>
> Else
>
> Dat(1) = (Dat(1) XOR &Hff) + 1 ' takes the 2's
comp
>
> T_C = CSng(Dat(1)) / 2.0
>
> End If
>
> End If
>
> MakeTempMeas = T_C
>
> End Function
>
> MY INIT (RESET from files section) ROUTINE:
>
> '-----------------------
>
> ' Init_1W
>
> '
>
> ' Reset the 1-wire bus by sending a 500 usec low pulse.
>
> ' Return true if any devices respond, false if there
>
> ' are no devices on the bus.
>
> Function Init_1W(ByVal Pin as Byte) as Boolean
>
> DIM busTransitions as Long
>
> ' It is important for timing reasons that this function
>
> ' not be pre-empted...
>
> call LockTask
>
> call PutPin (Pin, bxInputTristate)
>
> call PutPin (Pin, bxOutputLow)
>
> ' Delay for ~500 usec - fake it with PulseOut on pin
> 0...
>
> call PulseOut (0, 0.0005, 0)
>
> ' Now let the pullup resistor do its thing...
>
> Call PutPin (Pin, bxInputTristate)
>
> ' Look for the presence pulse over a 300 usec period
>
> busTransitions = CountTransitions (Pin, 0.0003)
>
> call UnlockTask
>
> Init_1W = (busTransitions > 0)
>
> IF (Init_1W) THEN
>
> DEBUG.PRINT "RESET = TRUE"
>
> ELSE
>
> DEBUG.PRINT "RESET = FALSE"
>
> END IF
>
> End Function
>
> From: b... [mailto:b...] On Behalf
> Of pha555
> Sent: Wednesday, February 13, 2008 12:53 PM
> To: b...
> Subject: [BasicX] Re: DS1820 1-wire temperature not working
>
> --- In b... , "James
> R. Parish" wrote:
>>
>> I'm having a problem getting this DS1820 to give me any temperature
>> other than the 85 degrees. I have checked timings and everything looks
>> good. On reading the scratch pad I get "AA OO 4B 46 FF FF 0C 10 87".
>> The CRC checks okay but I get no actual temperature reading. Help?
I'm
>> using parasitic mode, one sensor. I check the archives and did find
>> something about the power on reset erasing the EEPROM, any clue on
> where
>> to get it fixed? Could this be my problem? This is my first attempt at
>> using a 1-wire device.
>>
>>
>> At my page; http://www.phanderson.com/bx24/ds1820_1.html
>
> Increase the duration of the StrongPullUp to 0.75 or even 1.0.
>
> Sub StrongPullUp_1W(ByVal Pin as Byte)
> ' Provide a hard logic one for 0.5 secs
> Call PutPin(Pin, 1)
> Call Sleep(0.5) <<<<<<<<<<<<<<<<<<<
> Call PutPin(Pin, 2)
> End Sub
>
> The 85 you are getting is the default Dallas setting indicating the
> temperature conversion did not complete.
>
> Peter H Anderson
> http://www.phanderson.com/basicx/
>
>
Reply by "James R. Parish"●February 14, 20082008-02-14
I switched over to powered mode instead of parasitic mode and it works
fine. I'm not one to just move on when there is a quirk causing an
issue and a fix is found. I'm thinking the problem is in the "hard
pull-up" on the data line, I tried increasing the time from 0.5 sec to
1.5sec with no different results. I have a task running while testing
the DS1820, it is just this:
DIM DACCounter as BYTE
DO
Call DACPIN(18, SETIOUT, DACCounter)
SLEEP(0.0)
LOOP
End Sub 'SetIOUTtask
I'm not sure if this is effecting the time it takes for the hard pull-up
to be applied to the dS1820 data pin. Maybe the extra current is not
getting to the chip before the temperature conversion starts. I stopped
the task and it didn't make a difference either.
Reply by "James R. Parish"●February 13, 20082008-02-13
Tried that, didn't work. Maybe my output routine is not getting the data
out correctly? I tried yours (PHAnderson) as well with no different
results.
'-----------------------
' OutByte_1Wire
'
' Output a byte to the selected device on the bus.
Sub OutByte_1W(ByVal Pin as Byte, ByVal OByte as Byte)
DIM X as Byte
FOR X = 0 to 7
CALL Put1Wire (Pin, GetBit (OByte, X))
NEXT
End Sub
THIS IS PRETTY MUCH STOCK:
Function MakeTempMeas(ByVal Pin as Byte) as Single
' Returns temperature. Returns -89.99 if CRC error
Dim N as Integer
Dim Dat(1 To 9) as Byte, CRC as Byte
Dim T_C as Single
DIM OKAY as BOOLEAN
OKAY = Init_1W(PIN)
Call OutByte_1W(Pin, &HCC) 'skip ROM
Call OutByte_1W(Pin, &H44) 'perform temperature conversion
'StrongPullUp
CALL PutPin (Pin, bxOutputHigh)
Call Sleep(0.70)
CALL PutPin (Pin, bxInputTristate)
OKAY = Init_1W(PIN)
Call OutByte_1W(Pin, &HCC) ' skip ROM
Call OutByte_1W(Pin, &HBE) ' get temperature data
For N = 1 to 9
Dat(N) = InByte_1W(Pin) ' fetch the nine bytes
Next
For N = 1 to 9
Call PutHexB(Dat(N))
Next
CRC = CalcCRC(Dat, 9) ' calculate CRC of the 9 bytes
' Reset the 1-wire bus by sending a 500 usec low pulse.
' Return true if any devices respond, false if there
' are no devices on the bus.
Function Init_1W(ByVal Pin as Byte) as Boolean
DIM busTransitions as Long
' It is important for timing reasons that this function
' not be pre-empted...
call LockTask
call PutPin (Pin, bxInputTristate)
call PutPin (Pin, bxOutputLow)
' Delay for ~500 usec - fake it with PulseOut on pin
0...
call PulseOut (0, 0.0005, 0)
' Now let the pullup resistor do its thing...
Call PutPin (Pin, bxInputTristate)
' Look for the presence pulse over a 300 usec period
busTransitions = CountTransitions (Pin, 0.0003)
call UnlockTask
Init_1W = (busTransitions > 0)
IF (Init_1W) THEN
DEBUG.PRINT "RESET = TRUE"
ELSE
DEBUG.PRINT "RESET = FALSE"
END IF
End Function
From: b... [mailto:b...] On Behalf
Of pha555
Sent: Wednesday, February 13, 2008 12:53 PM
To: b...
Subject: [BasicX] Re: DS1820 1-wire temperature not working
--- In b... , "James
R. Parish" wrote: >
> I'm having a problem getting this DS1820 to give me any temperature
> other than the 85 degrees. I have checked timings and everything looks
> good. On reading the scratch pad I get "AA OO 4B 46 FF FF 0C 10 87".
> The CRC checks okay but I get no actual temperature reading. Help? I'm
> using parasitic mode, one sensor. I check the archives and did find
> something about the power on reset erasing the EEPROM, any clue on where > to get it fixed? Could this be my problem? This is my
first attempt at
> using a 1-wire device.
>
>
>
Increase the duration of the StrongPullUp to 0.75 or even 1.0.
Sub StrongPullUp_1W(ByVal Pin as Byte)
' Provide a hard logic one for 0.5 secs
Call PutPin(Pin, 1)
Call Sleep(0.5) <<<<<<<<<<<<<<<<<<<
Call PutPin(Pin, 2)
End Sub
The 85 you are getting is the default Dallas setting indicating the
temperature conversion did not complete.
--- In b..., "James R. Parish" wrote: >
> I'm having a problem getting this DS1820 to give me any temperature
> other than the 85 degrees. I have checked timings and everything looks
> good. On reading the scratch pad I get "AA OO 4B 46 FF FF 0C 10 87".
> The CRC checks okay but I get no actual temperature reading. Help?
I'm
> using parasitic mode, one sensor. I check the archives and did find
> something about the power on reset erasing the EEPROM, any clue on where
> to get it fixed? Could this be my problem? This is my first attempt at
> using a 1-wire device.
>
>
>
Increase the duration of the StrongPullUp to 0.75 or even 1.0.
Sub StrongPullUp_1W(ByVal Pin as Byte)
' Provide a hard logic one for 0.5 secs
Call PutPin(Pin, 1)
Call Sleep(0.5) <<<<<<<<<<<<<<<<<<<
Call PutPin(Pin, 2)
End Sub
The 85 you are getting is the default Dallas setting indicating the
temperature conversion did not complete.
Reply by "James R. Parish"●February 13, 20082008-02-13
I'm having a problem getting this DS1820 to give me any temperature
other than the 85 degrees. I have checked timings and everything looks
good. On reading the scratch pad I get "AA OO 4B 46 FF FF 0C 10 87".
The CRC checks okay but I get no actual temperature reading. Help? I'm
using parasitic mode, one sensor. I check the archives and did find
something about the power on reset erasing the EEPROM, any clue on where
to get it fixed? Could this be my problem? This is my first attempt at
using a 1-wire device.