CRC8 but not Maxim


the result is CRC8 Maxim, but how to get CRC8 ?

With value 01 02 03
result 0xD8 ok for Maxim but how to get 0x48 for CRC8?

char CRC8(uint8_t *data,int length) 
   char crc = 0x00;
   char extract;
   char sum;
   for(int i=0;i<length;i++)
      extract = *data;
      for (char tempI = 8; tempI; tempI--) 
         sum = (crc ^ extract) & 0x01;
         crc >>= 1;
         if (sum)
            crc ^= 0x8C;
         extract >>= 1;
   return crc;


With the posted code, I get crc = 0x70. If you modify your code to use unsigned char (or byte or uint8_t), then you get 0xD8

Thanks but it doesn't work. I get 0xD8 but it must be 0x48 !

no idea ? Thanks

Post up...

There are many, many CRC algorithms.

You need to choose the correct one for your application, which you forgot to mention.

Thanks Remington,

CRC8 (hex) alone... like here:

(first line, row result)


The CRC8 calculator page give a link to the source files, but the values associated with these parameters are the essential differences between the various CRC8 algorithms: (Poly, Init , RefIn, RefOut, XorOut)

Ok, but how to adapt my code to get the right value ? I'm not keen on Java or Php :frowning:

Unfortunately that is not so easy. You have to understand exactly how the code works, and I'm a bit puzzled because the code does not use the "Maxim" polynomial 0x31 (as claimed by the site you linked).

I would expect it to be this line, which is obviously using 0x8C instead. That could be because the shift in this implementation is to the right rather than to the left. Check out example C/C++ code for other CRC8 algorithms to learn more.

           crc ^= 0x8C;

You still have not told us what your application is.