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.

CRC16 issue

Other Parts Discussed in Thread: CONTROLSUITE

Dear All, I am using CRC to checksum my SCI downstream data. I am testing a sample code to run Poly 0x1021, initial 0xFFFF 16bit checksum code.

I tested the code though C simulator. Here is the link:http://cpp.sh/3f3x

The after I run the code, the output is 0x89C3, my testing data is test[4]={0x01,0x02,0x03,0x04};


However, when I load this code into my F28069 DSP processor. The output is totally different.


Here is my C code.

//=============================================================================
//=============================================================================
#include "DSP28x_Project.h"
//#include "crc.h"
#include "stdint.h"
#include "stdio.h"

typedef unsigned short  crc;
#define WIDTH    (8 * sizeof(crc))
#define TOPBIT   (1 << (WIDTH - 1))
#define POLYNOMIAL			0x1021


int 		   nbyte = 4;
crc            remainder = 0xFFFF;
int            byte;
unsigned char  bit;

//-----------------------------------------------------------------------------
// start of main()
//-----------------------------------------------------------------------------
int main()
{


    unsigned char test[4]={0x01,0x02,0x03,0x04};
    InitSysCtrl();


       /*
        * Perform modulo-2 division, a byte at a time.
        */
       for (byte = 0; byte < 4; ++byte)
       {
           /*
            * Bring the next byte into the remainder.
            */
           remainder ^= test[byte] << (WIDTH - 8);

           /*
            * Perform modulo-2 division, a bit at a time.
            */
           for (bit = 8; bit > 0; --bit)
           {
               /*
                * Try to divide the current data bit.
                */
               if (remainder & TOPBIT)
               {
                   remainder = (remainder << 1) ^ POLYNOMIAL;
               }
               else
               {
                   remainder = (remainder << 1);
               }
           }
       }
       printf("CRC is: %X\n",remainder);

} // End of main()


Did someone has the same issue ever before? I checked this thing for almost two days without no sucesses...