SBAA106A June   2020  – August 2021 ADS112C04 , ADS112U04 , ADS114S06 , ADS114S08 , ADS122C04 , ADS122U04 , ADS1235 , ADS1235-Q1 , ADS124S06 , ADS124S08 , ADS1259 , ADS1259-Q1 , ADS125H01 , ADS125H02 , ADS1260 , ADS1260-Q1 , ADS1261 , ADS1262 , ADS1263 , ADS127L01 , ADS131A02 , ADS131A04 , ADS131M04 , ADS131M06 , ADS131M08

 

  1.   Trademarks
  2. 1Introduction
  3. 2Simple Checksum
    1. 2.1 Checksum Code Example
  4. 3CRC
    1. 3.1 CRC Generic Computations
      1. 3.1.1 Using XOR Bitwise Computation
      2. 3.1.2 Using Lookup Tables
        1. 3.1.2.1 Table Initialization
        2. 3.1.2.2 CRC Computation
      3. 3.1.3 CRC Computation Differences Between the ADS122U04 and ADS122C04
        1. 3.1.3.1 Byte Reflection Example
        2. 3.1.3.2 Reassembling Data Using Byte Reflection for CRC Computation
  5. 4Hamming Code
    1. 4.1 Hamming Code Computation
      1. 4.1.1 Hamming Code Computation Example
        1. 4.1.1.1 Counting Bits for Parity and Checksum Computations
          1. 4.1.1.1.1 Example of Counting Set Bits in the Data
          2. 4.1.1.1.2 Example of Counting Set Bits Using a Lookup Table
      2. 4.1.2 Validation of Transmitted Data
        1. 4.1.2.1 Hamming Validation
        2. 4.1.2.2 Checksum Validation
        3. 4.1.2.3 Error Correction
  6. 5Summary
  7. 6References
  8. 7Revision History

Table Initialization

The memory size of the table array will depend on the size of the CRC value to be returned. For efficiency, the table boundary should be set to byte alignment. The table consists of 256 16-bit entries for 16-bit CRC or 256 8-bit entries for 8-bit CRC .

typedef crc_t uint16_t;          // for 8 bits, use uint8_t
#define POLYNOMIAL 0x1021        // CRC16-CCITT, but for 8 bits use CRC-8-ATM(HEC),
                                 //     and the polynomial value 0x07
#define REMAINDER_INIT 0xFFFF    // CRC16-CCITT, but for 8 bits use CRC-8-ATM(HEC),
                                 // 0xFF for 8 bit CRC on ADS1260, ADS1261, ADS1235
                                 // 0x00 for 8 bit CRC on ADS124S0x, ADS114S0x, ADS1262, ADS1263
#define WIDTH (8 * sizeof(crc_t))
crc_t crcTable[256];
/**
 * Initialization for CRC lookup table to be stored in memory.
 *
 * \details CRC computation for each possible combination contained in a single byte
 * which is then stored to a crcTable array where each array element pertains to a 
 * specific byte value.
 *
 *
 * \returns  void.
 */
void  initCRCtable(void)
{
    crc_t remainder;
    uint32_t byte, bit;
                                                     // For each byte in data packet, perform long
                                                     //    division of polynomials
    for(byte = 0; byte < 256; byte++)
    {
        remainder = (byte << (WIDTH - 8));           // Get next byte into remainder
        for(bit = 8; bit > 0; bit--)                 // For each bit in the remainder
        {
            if(remainder & (1 << (WIDTH - 1)))
                remainder = (remainder << 1) ^ POLYNOMIAL; // If the top bit is set, left shift 
                                                           //   the remainder and XOR it with the 
            else                                           //   divisor and store the result in 
                                                           //   the remainder
                remainder = (remainder << 1);              // If the top bit is clear, left shift 
                                                           //   the remainder
        }
        crcTable[byte] = remainder;
    }
}