Hi,
I use a K60 of MASK 2N22D and have probelms getting correct CRC-16 result using the built in hardware CRC generator.
I have byte string that I want to calculate CRC-16 using a common standard algorithm with polynomila 0xA001.
The table variant of this algorithm start with...
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
and end with...
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
The code looks like below...
CRC_CTRL = CRC_CTRL_WAS_MASK; /* 16bit CRC */
CRC_CRC = 0; /* Seed */
CRC_CTRL = 0; /* 16bit CRC */
CRC_GPOLY = 0x0000A001; /* Poly */
for ( numberOfBytes--)
CRC_CRC = *memPtr++;
result = CRC_CRC;
I also have tried with and without tranpose of bytes.
I can't get the correct CRC.
Does anyone know what I'm doing wrong?
Regards,
Anders
0xA001 is the reversed Polynomial. Do you get the answer you expect if you use 0x8005 for the Polynomial?
Also, while it standard for the seed to be zero for CRC-16, this will miss leading inserted zeros.
Internalizing to all ones will remove that problem if standard compliance is not required.
Thank you for the response! I appreciate the input.
Unfortunately it didn't solve my problem. I tried the above and also other combinations of manipulated Polynomial. All in combination with transpose of Byte and/or bit as well as without transpose. I have also tried with 0xFFFF seed.All wihtout luck.
Regarding the zero seed. It is for backward compatibility so no option really (in case that would have worked).
Regards,
Anders
Hi, Andersbergqvist
Now our demo code support following ploynomials.
0x1021,
0x8408,
0x8005,
0x04C11DB7L
But you can input your ploynomials and set different configuration of for your calculation tot,totr,fxor and tcrc.
Would you please help to tell your setting and correct result? Then I would like to check it for you.
Best Regards
Paul