This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CRC 8 bit Polynomial X^8 + 1

Hello,

I have to check CRC from external device via the SCI.

The CRC is computed to SCI 8bits data with the following CRC code G(X) = X^8 + 1

Then I have the following code to compute it:

static uint8_t DV_SmartAbs_iCaclCrc(uint8_t* Data, uint8_t Size)
{
  uint8_t j;
  uint8_t Carry;
  uint8_t Crc;
  
  Crc = 0;

  while (Size-- > 0)
  {
    Crc ^= *Data++;
    for (j = 8; j != 0; j--)
    {
      Carry = Crc & 0x80;
      Crc <<= 1;
      if (Carry != 0)
      {
        Crc ^= 0x01;  /* Polynome X^8 + 1  */
      }
    }
  }
  return (Crc & 0x00FF);
}

So with this If I have the following buffer:

0x001A, 0x0020, 0x00AF, 0x000A, 0x0001, 0x0011, 0x0002, 0x0000, 0x0000, 0x0080, (Size = 10) I have the following result:

Crc = 0x0D0D which is truncated to 8 LSB so 0x0D.

This is correct for my external device.

No I would use Crc library using VCU. But the datasheet indicate it is use Polynomial 0x7. This seems not correspond with my polynomial?

To check taht, I decided to implement My Algorithm which respect the 0x07 Polynomial and check if My algorithm found the same CRC than the library.

If in my algorithm I replace my polynomial 0x01 by 0x07 (Replace  Crc ^= 0x01;  by  Crc ^= 0x07; )

The result of Crc is 0x53B9, the result of CRC_run8bit is 0xAB and CRC_run8bitReflected is 0x29 (With Seed = 0) but not 0xB9..

So what I missed?

CRC_run8Bit

  • Hello

    I will apply the lookup table method.

    With the 0x01 polynomial, the CrcTable[i] = i !

    Then the CRC algorithm is reduce only to make an Logical XOR with all byte to check!..

    Crc = 0;
      while (Size-- != 0)
      {
    	  Crc = ((*Data++) ^ Crc);
        /* Crc = crc8_table[Crc]; */
      }
    

  • Hi,

    The VCU CRC expects the bytes to be packed, i.e. 0x201A,  0x0AAF, 0x1101, 0x0002,  0x8000 

    I have posted an unpacked CRC algorithm here: 

    you will need to change the VCRC16L_Px instruction in the assembly to VCRC8L

  • Hello,

    Thank for your back,

    I will test, but this is strange because, I well seen the MSB byte of 16 bits value change the result of CRC, But I also seen the 6, 7, 8, 9 and 10th 16 bits values change the result. This mean the size (10) is in word, not in byte?

  • The size is always the number of bytes.

    Lets assume that the seed value to the CRC is 0x0, then all leading zeros will result in a 0 CRC. When you hit the first non zero value 0x1A, it changes the CRC. Any subsequent 0's will also change the CRC which is why the CRC value changes as it processes the high byte of the first word, 0x001A.

    When you run the normal CRC function in the VCU library with 10 as the size_in_bytes argument you are only running the CRC on 0x001A, 0x0020, 0x00AF, 0x000A, 0x0001. So you have to use the alternate function in the E2E post which only takes the low byte of each word.