Tuesday, November 10, 2015

CRC calculation in C

Here are some useful Internet resources when you have to deal with CRC calculation and checking. I found them handy and use occasionally. Some are online calculators, some gives also technical descriptions.
Below is some real working C source code. Borrowed from here!
It is tested and working. It calculates CRC CCITT16 with starting value 0xFFFF. It might be not as fast as table based CRC calculations, but occupies less RAM and code space which sometimes is essential for embedded systems.


#define POLY 0x1021

unsigned char i;
unsigned int crc = 0xFFFF;

while (wLength--) {
    wCrc ^= *(unsigned char *)pData++ << 8;
    for (i=0; i < 8; i++)
        wCrc = wCrc & 0x8000 ? (wCrc << 1) ^ POLY : wCrc << 1;
}
return wCrc & 0xffff;

Friday, November 6, 2015

uVision UDAS debugger connection problem

Recently I was getting strange error when trying to debug sample software on Infineon XC800 Starter Kit. Previously it was all ok, but now I got error messages in uVision output window:

Searching for DAS Server 'UDAS'...
DAS Server 'UDAS' is installed.
DAS Server 'UDAS' is not started yet. Trying to start it now...
DAS Server 'UDAS' has been started successfully.
Warning: Unknown JTAG ID=00000000. Assuming an XC866-4FR device with 16K flash

 I struggled for a while with the same problem but without success. Finally decided to search Internet and found some guidance here. I decided to switch mini-USB cable and problem disappeared immediately. Apparently I was using some random cheap low quality cable this time. Took another good thick cable and everything was fine.

Some lesson to learn. Always use good cables and check Internet after a moment if you are not succeeding to resolve problem soon.