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.

HDC3020: CRC C++ Calculation

Part Number: HDC3020

I have tried a few different C++ CRC-8 examples on the web to recreate the CRC example given in the HDC3020 data sheet and am unable to replicate the value. I am writing the routine on a TMS 320F2837xS processor in C++. If anyone has an example it would be greatly appreciated!

  • Hi John,

    Please see the below code to implement the CRC algorithm for this device:

    #include <stdio.h>
    void main (int argc, char* argv[]) {
     	unsigned char crc = 0xFF;
     	unsigned int msg[20];
     	int msglen = (argc > 1) ? (argc - 1): 2;
     	msg[0] = 0xAB;
     	msg[1] = 0xCD;
     	for (int i = 1; i < argc; i++) {
     		sscanf(argv[i], "%X", &msg[i - 1]); //Enter the MSB and the LSB hex values
     	}
     	for (int byte = 0; byte < msglen; byte++) {
     		crc ^= msg[byte];
     		for (int bit = 0; bit < 8; bit++) {
     			if (crc & 0x80)
     				crc = (crc << 1) ^ 0x31;
     			else
     				crc = (crc << 1);
     		}
     	}
     	printf ("crc: 0x%X\n", crc);
    }

    Regards,
    Pavani Tenneti