Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:25 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : (MM-DM) CRC-8 library or code sample

Author Message
Greg Fordyce
Senior Member

Joined: 16/09/2011
Location: United Kingdom
Posts: 153
Posted: 12:30pm 25 Aug 2012
Copy link to clipboard 
Print this post

I am wondering if anyone has a code snippet or library for doing CRC-8 error checking with the polynomial of X^8 + X^2 + X + 1. I briefly though I might be able to use the built in function OWCRC8() but it appears to use a different polynomial (X^8 + X^5 + X^4 + 1).

I need to process data streams of up to 18 bytes plus the crc byte from a Linear Technology LTC6802-2 battery monitor. Just thought I would ask before I roll my own, no point reinventing the wheel if I don't have to.
 
Greg Fordyce
Senior Member

Joined: 16/09/2011
Location: United Kingdom
Posts: 153
Posted: 01:09am 28 Aug 2012
Copy link to clipboard 
Print this post

I've found a very useful app note from Maxim, App note 3479.

It describes a simple table based way of doing crc checking with the same poly that I need, and it even links to the 256 byte table. In the end its just a few lines of code. Here's what I've got so far.


dim datastream(3),crctable(256)
datastream(0) = 128
datastream(1) = 1
datastream(2) = 163

FOR i = 0 to 255
READ crctable(i)
NEXT i

crcregister = 0

FOR x = 0 to 3
crcregister = datastream(x) XOR crctable(crcregister)
PRINT crcregister
NEXT x



DATA 0,7,14,9,28,27,18,21
DATA 56,63,54,49,36,35,42,45
DATA 112,119,126,121,108,107,98,101
DATA 72,79,70,65,84,83,90,93
DATA 224,231,238,233,252,251,242,245
DATA 216,223,214,209,196,195,202,205
DATA 144,151,158,153,140,139,130,133
DATA 168,175,166,161,180,179,186,189
DATA 199,192,201,206,219,220,213,210
DATA 255,248,241,246,227,228,237,234
DATA 183,176,185,190,171,172,165,162
DATA 143,136,129,134,147,148,157,154
DATA 39,32,41,46,59,60,53,50
DATA 31,24,17,22,3,4,13,10
DATA 87,80,89,94,75,76,69,66
DATA 111,104,97,102,115,116,125,122
DATA 137,142,135,128,149,146,155,156
DATA 177,182,191,184,173,170,163,164
DATA 249,254,247,240,229,226,235,236
DATA 193,198,207,200,221,218,211,212
DATA 105,110,103,96,117,114,123,124
DATA 81,86,95,88,77,74,67,68
DATA 25,30,23,16,5,2,11,12
DATA 33,38,47,40,61,58,51,52
DATA 78,73,64,71,82,85,92,91
DATA 118,113,120,127,106,109,100,99
DATA 62,57,48,55,34,37,44,43
DATA 6,1,8,15,26,29,20,19
DATA 174,169,160,167,178,181,188,187
DATA 150,145,152,159,138,141,132,131
DATA 222,217,208,215,194,197,204,203
DATA 230,225,232,239,250,253,244,243


In this code the sample data (datastream) is hard coded to the example given in the app note, obviously this needs to be changed to read actual data streams. There are 2 ways of using this. If you proess a data stream with the crc byte, the variable crcregister should = 0 if there are no errors. If you process a data stream without the crc byte, then crcregister will equal the crc byte to be appended on the end of the data stream.

Greg

P.S. I finally understand the point of the DOS version of MMBasic. I used it to figure out this code.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024