AnsweredAssumed Answered

Std CRC-16 bytewise with 0xA001 polynomial

Question asked by andersbergqvist on May 15, 2013
Latest reply on Jun 5, 2013 by Zhe Tian



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?