I thought I had this all cracked a while ago but on returning to it now I don't seem to be the right answer.

I am using the routine posted by Tom Estes http://www.picbasic.co.uk/forum/show...ighlight=1Wire
but when I test it against what I understand to be valid Device IDs I get a CRC failure.

This is my code: Can anyone suggest what I am doing wrong?

I Var Byte
CRC Var Byte
CRCData Var Byte
TestBit Var Bit
OW_Byte_Ptr Var Byte

'' PBP Version not using lookup table
'' Expects CRC starting value and CRCData
'' CRC will be cumulative unless reset externally
'' Gives ending CRC value and destroys CRCData
'' Uses I-Byte, TestBit-Bit, CRC-Byte, CRCData-Byte

CRC8:
For I = 0 To 7 ' Do for all 8 bits in data byte
TestBit = CRC.0 ^ CRCData.0 ' XOR bit0 of data byte and crc
CRCData = CRCData >> 1 ' Position data byte for next bit test
If TestBit = 0 Then Shift ' If test bit not set, just shift CRC
CRC = CRC ^ $18 ' If set, account for EXOR feedback
Shift: ' Shift right the CRC byte
CRC = CRC >> 1 ' CRC bit 0 to bit bucket
CRC.7 = TestBit ' Test bit rotates into CRC bit 7
Next I
Return

'TestCode------------------------------------------------

TestData VAR Byte[8]

' Load up Data array

TestData[0] = $05 '$28 'Family Code
TestData[1] = $C5 '$B1 'Serial Number
TestData[2] = $C3 '$FE
TestData[3] = $08 '$22
TestData[4] = $00 '$00
TestData[5] = $00 '$00
TestData[6] = $00 '$00
TestData[7] = $CD '$5D 'CRC

Main:
For OW_Byte_Ptr = 0 To 7
CRCData = TestData[OW_Byte_Ptr]
GoSub CRC8
HSerOut [HEX2 CRC, 10, 13]
Next

If CRC = 0 Then
HSerOut ["CRC OK",10,13]
Else
HSerOut ["CRC Error ", HEX2 CRC,10,13]
EndIf

Stop

What I am actually getting is
35
FF
4C
7E
D8
3E
8D
B1
CRC Error B1

Where I should be getting 0

Am I missing something?

JohnB