Dallas CRC

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi there...

i have made a device that communicates through USB to a PC and an application written in visual basic.

i have borrowed from here the dallas CRC8 code written in c:

UC crc_8bit(UC *frameStart, UC numberOfBytes){ 
 UC temp;
 UC bitCounter;
 UC feedbackBit;
 UC crc = 0; 
    
 while(numberOfBytes--){ 
  temp = *frameStart++; 
       
  for (bitCounter = 8; bitCounter; bitCounter--){ 
   feedbackBit = (crc & 0x01); 
   crc >>= 1; 
   if (feedbackBit ^ (temp & 0x01)){ 
             crc ^= 0x8c; 
   } 
   temp >>= 1; 
  }
 }      
 return crc; 

and i have made the needed changes in order to adjust it in visual basic:

  Dim temp, feedbackBit, crc As Byte
  Dim bitCounter, i As Integer
  crc = 0
  i = 0
  While lenght > 0
    temp = buffer(i)
    For bitCounter = 1 To 8 Step 1
      feedbackBit = (crc And &H1)
      crc = (crc / 2)
      If (feedbackBit Xor (temp And &H1)) = 1 Then
         crc = (crc Xor &H8C)
      End If
      temp = (temp / 2)
    Next bitCounter
    i += 1
    lenght -= 1
  End While
  Return crc

the problem is that i do not get the same result.
do i have any obvious problem in the trasformation that i can not see?

any ideas?

thanks in advance...

[cliff(moderator): Academy is the wrong forum - moving]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

never mind fox i have found the problem...

it needs "\" not "/" because 3>>1 = 1
and 3/2 = 2 instead of 3\2 = 1

thanks anyway