Dear All,
I am working on the CRC check sum. I am using Poly 0x1021 and Initial Value 0xFFFF.
The hardware is F28069 sticker. I write a sample code to do the checksum work. The code works perfect in the simulater: here is the link:
The check sum results for test[4]={0x01,0x02,0x03,0x04}; should be 0x89C3, http://www.lammertbies.nl/comm/info/crc-calculation.html
However, when I load this code into DSP, the output results totally changed...
//=============================================================================
//=============================================================================
#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()
Someone has this issue before? I am testing VCU code as well, the output results is different with online CRC calculator's results...