I'm having problems with my CRC calculations on PIC24FV32KA301. I have tried two different CRC-16 computation methods using 1, 2, and 3 bytes of data and only 1 of them is resulting in the correct answer. Does anyone know wtf I'm doing wrong? I'd appreciate any help. Here is the relevant code, //Code borrowed from: http://ww1.microchip.com/downloads/en/DeviceDoc/CE312%20CRC.zip #define uint unsigned int #define uchar unsigned char unsigned int crc_calc(uchar * data, uint datalen, uint poly, uint polylen, uint datawidth, uint prevcrc) { CRCCON1bits.CRCEN =3D 1; CRCXOR =3D poly; CRCCON2bits.PLEN =3D polylen - 1; //Poly length =3D PLEN + 1 CRCCON2bits.DWIDTH =3D datawidth - 1; //Data word width =3D DWIDTH + 1 CRCCON1bits.LENDIAN =3D 0; //MSb big endian CRCCON1bits.CRCISEL =3D 0; CRCWDAT =3D prevcrc; CRCCON1bits.CRCGO =3D 1; //Start CRC serial shifter do { while(CRCCON1bits.CRCMPT =3D=3D 0); while((CRCCON1bits.CRCFUL =3D=3D 0) && (datalen > 0)) { CRCDAT =3D *data; data++; datalen--; } } while (datalen > 0); while(CRCCON1bits.CRCFUL =3D=3D 1); //Wait if FIFO is full CRCDAT =3D 0x0000; while(CRCCON1bits.CRCMPT =3D=3D 0); //Wait FIFO empty CRCCON1bits.CRCGO =3D 0; //CRC serial shifter turned off return (CRCWDAT); } void main(void) { uchar data[10] =3D "abcdefg"; //Results compared to: //http://www.lammertbies.nl/comm/info/crc-calculation.html // Result uint crc1 =3D crc_calc(data, 1, 0x1021, 16, 8, 0); //0x7C87 =3D RIGHT uint crc2 =3D crc_calc(data, 1, 0x8005, 16, 8, 0); //0x8145 =3D WRONG -> should be 0xA87E uint crc3 =3D crc_calc(data, 2, 0x1021, 16, 8, 0); //0xE0BF =3D WRONG -> should be 0X74FF uint crc4 =3D crc_calc(data, 2, 0x8005, 16, 8, 0); //0x06D8 =3D WRONG -> should be 0xC9A9 uint crc5 =3D crc_calc(data, 3, 0x1021, 16, 8, 0); //0x1A43 =3D WRONG -> should be 0x9DD6 uint crc6 =3D crc_calc(data, 3, 0x8005, 16, 8, 0); //0x179A =3D WRONG -> should be 0x9738 } --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .