Closed Thread
Results 1 to 1 of 1

Thread: CRC-8 for SMBus

  1. - 26th April 2007, 14:30 #1
    Join Date
    Jul 2005
    Posts
    78

    Default CRC-8 for SMBus

    I am currently working with a Melexix temperature measurement device that uses SMBus protocol with transactions protected with a Packet Error Code (PEC) byte in CRC-8 format. While Tom Estes has posted some code at http://www.picbasic.co.uk/forum/showthread.php?t=1672 that looks like it works for this same format (based on a Dallas Semi app note), I did not find the example code to work for my application. So I filed off the serial numbers from his code and re-worked it.

    Code was tested by putting a device read into a loop and comparing the returned PEC from one I calculated from this code. While I did not do an exhaustive test of all combinations this is a fairly strong check. Of course, YMMV.

    Code:
     ' ********** Subroutine CRC8LU **********
    ' Uses CRCData for input, CRC for output
    ' CRC must be initialized to 0 for each new data set
    ' CRCData is used to pass each byte in turn to the check code
    ' no other variables used or changed in this code
    CRC8LU:
     CRC = CRCData ^ CRC
     ' PBP only handles 255 constants in the list (256 for 18Cxxx). Since table is
     ' indexed starting at zero, special case for $FF (256th element).
     If CRC = $FF Then
     CRC = $F3
     ELSE
     Lookup CRC, [0,ドル 7,ドル $E, 9,ドル 1ドルC, 1ドルB, 12,ドル 15,ドル 38,ドル 3ドルF, 36,ドル 31,ドル_
     24,ドル 23,ドル 2ドルA, 2ドルD, 70,ドル 77,ドル 7ドルE, 79,ドル 6ドルC, 6ドルB, 62,ドル 65,ドル_
     48,ドル 4ドルF, 46,ドル 41,ドル 54,ドル 53,ドル 5ドルA, 5ドルD, $E0, $E7, $EE, $E9,_
     $FC, $FB, $F2, $F5, $D8, $DF, $D6, $D1, $C4, $C3, $CA, $CD,_
     90,ドル 97,ドル 9ドルE, 99,ドル 8ドルC, 8ドルB, 82,ドル 85,ドル $A8, $AF, $A6, $A1,_
     $B4, $B3, $BA, $BD, $C7, $C0, $C9, $CE, $DB, $DC, $D5, $D2,_
     $FF, $F8, $F1, $F6, $E3, $E4, $ED, $EA, $B7, $B0, $B9, $BE,_
     $AB, $AC, $A5, $A2, 8ドルF, 88,ドル 81,ドル 86,ドル 93,ドル 94,ドル 9ドルD, 9ドルA,_
     27,ドル 20,ドル 29,ドル 2ドルE, 3ドルB, 3ドルC, 35,ドル 32,ドル 1ドルF, 18,ドル 11,ドル 16,ドル_
     3,ドル 4,ドル $D, $A, 57,ドル 50,ドル 59,ドル 5ドルE, 4ドルB, 4ドルC, 45,ドル 42,ドル_
     6ドルF, 68,ドル 61,ドル 66,ドル 73,ドル 74,ドル 7ドルD, 7ドルA, 89,ドル 8ドルE, 87,ドル 80,ドル_
     95,ドル 92,ドル 9ドルB, 9ドルC, $B1, $B6, $BF, $B8, $AD, $AA, $A3, $A4,_
     $F9, $FE, $F7, $F0, $E5, $E2, $EB, $EC, $C1, $C6, $CF, $C8,_
     $DD, $DA, $D3, $D4, 69,ドル 6ドルE, 67,ドル 60,ドル 75,ドル 72,ドル 7ドルB, 7ドルC,_
     51,ドル 56,ドル 5ドルF, 58,ドル 4ドルD, 4ドルA, 43,ドル 44,ドル 19,ドル 1ドルE, 17,ドル 10,ドル_
     5,ドル 2,ドル $B, $C, 21,ドル 26,ドル 2ドルF, 28,ドル 3ドルD, 3ドルA, 33,ドル 34,ドル_
     4ドルE, 49,ドル 40,ドル 47,ドル 52,ドル 55,ドル 5ドルC, 5ドルB, 76,ドル 71,ドル 78,ドル 7ドルF,_
     6ドルA, 6ドルD, 64,ドル 63,ドル 3ドルE, 39,ドル 30,ドル 37,ドル 22,ドル 25,ドル 2ドルC, 2ドルB,_
     6,ドル 1,ドル 8,ドル $F, 1ドルA, 1ドルD, 14,ドル 13,ドル $AE, $A9, $A0, $A7,_
     $B2, $B5, $BC, $BB, 96,ドル 91,ドル 98,ドル 9ドルF, 8ドルA, 8ドルD, 84,ドル 83,ドル_
     $DE, $D9, $D0, $D7, $C2, $C5, $CC, $CB, $E6, $E1, $E8, $EF,_
     $FA, $FD, $F4], CRC
     EndIF
    Return

« Previous Thread | Next Thread »

Similar Threads

  1. Dallas CRC8 Routines
    By Tom Estes in forum Code Examples
    Replies: 23
    Last Post: - 8th May 2018, 18:07
  2. Calculating CRC for Modbus RTU
    By tekart in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th January 2010, 22:42
  3. saving RCREG to word
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 13:51
  4. Sensirion CRC
    By Tom Estes in forum Code Examples
    Replies: 3
    Last Post: - 9th November 2007, 15:09
  5. Problems with CRC8 Calc in 1Wire
    By JohnB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th March 2007, 22:01

Members who have read this thread : 2

You do not have permission to view the list of names.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Forum Rules

AltStyle によって変換されたページ (->オリジナル) /