SNAU265C june   2021  – july 2023 HDC3020 , HDC3020-Q1 , HDC3021 , HDC3021-Q1 , HDC3022 , HDC3022-Q1

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1HDC302x Devices
    1. 1.1 HDC3020 in WSON
    2. 1.2 HDC3021 in WSON
    3. 1.3 HDC3022 in WSON
  5. 2Storage and Handling Guidelines
    1. 2.1 Exposure to Contaminants
    2. 2.2 Chemical Analysis
      1. 2.2.1 Saturation and Recovery Tests
      2. 2.2.2 Long-Term Exposure
    3. 2.3 Packaging and Storing
      1. 2.3.1 Assembly
      2. 2.3.2 Application in Extreme Environment
  6. 3Programming the HDC3020
    1. 3.1 Trigger-On Demand
    2. 3.2 Auto Measurement
    3. 3.3 Programming the CRC
      1. 3.3.1 CRC C Code
    4. 3.4 Condensation Removal
    5. 3.5 Offset Error Correction
      1. 3.5.1 Offset Error Correction Example With a Fingerboard
  7. 4References
  8. 5Revision History

CRC C Code

The following code snippet describes how to generate an 8-bit CRC code in C for the HDC3x devices.

#include <stdio.h>
unsigned char crcHDC3 (unsigned char msg[], int msglen) {
    unsigned char crc = 0xFF;
    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);
        }
    }
    return crc;
}
void main(int argc, char *argv[]) {
    unsigned char 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]);
    }
    printf("crc" 0x%X\n", crcHDC3(msg, msglen));
}