Link to home
Create AccountLog in
Avatar of H7N9
H7N9Flag for South Africa

asked on

CRC16 checksum different to online calculators

Hi,
This is my first question on EE. I hope I have asked my question under the correct topics.

I have a problem with my CRC16 code, I think...
I have 2 senaiors:
1. My checksum byte 1 and 2 are swapped when compared to an excel CRC calculator I found online.. I tested this by entering different data and always found the same pattern.
2. Or my checksum is completely different to other online calculators.

Perhaps someone could point in the direction of a proven online CRC calulator.

For the life of me, I don't know which is correct or where my error could be.

My code:

[/i[i][code]int crc16_u16 (int currentCrc_u16, int Polynomial, int dataByte_u8)
  {
    currentCrc_u16 = currentCrc_u16 xor dataByte_u8; /* Exclusive Or */
    int i = 0;
    while (i<8)
      {
        if (currentCrc_u16 & 0x0001)  /* check for odd */
          {
		        /* ODD */
            // currentCrc_u16 = currentCrc_u16 >> 1; /* shift one bit out */
            currentCrc_u16 = currentCrc_u16 / 2; /* shift one bit out to right */
		        /* Ex Or with Polynom */
            //currentCrc_u16 = currentCrc_u16 ^ Polynomial; /* Exclusive Or */
            currentCrc_u16 = currentCrc_u16 xor Polynomial; /* Exclusive Or */
          }
        else {
		        /* EVEN */
                // currentCrc_u16 = currentCrc_u16 >> 1; /* shift one bit out */
                currentCrc_u16 = currentCrc_u16 / 2; /* shift one bit out to right */
              }
          i=i+1;
      }
return currentCrc_u16;
  }]

Open in new window


Start value: 0xFFFF
Polynomial: 0xA001
4 bytes Hex Data: 0xACA5F69C
Checksum: 0x9E76

Would you mind helping me figure this out.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of H7N9

ASKER

Thanks for the links Dave!
You're welcome, thanks for the points.