SBAA106A June   2020  – August 2021

2. 1Introduction
3. 2Simple Checksum
4. 3CRC
1. 3.1 CRC Generic Computations
1. 3.1.1 Using XOR Bitwise Computation
2. 3.1.2 Using Lookup Tables
3. 3.1.3 CRC Computation Differences Between the ADS122U04 and ADS122C04
5. 4Hamming Code
1. 4.1 Hamming Code Computation
1. 4.1.1 Hamming Code Computation Example
2. 4.1.2 Validation of Transmitted Data
6. 5Summary
7. 6References
8. 7Revision History

#### 4.1.2.1 Hamming Validation

Hamming bits are computed by taking the received data and computing the Hamming bits and then comparing to Hamming bits received as a bitwise XOR.

/**
* Verification of the Hamming/Data by recomputing and comparing by XOR to the transmitted data.
*
* \details Computation of Hamming bits using a bit mask for each Hamming bit then
* counting of the number of bits set in the masked value.  This is completed 5 times
* once for each Hamming bit. The checksum is also computed returning the complete byte
* that is appended to the 24-bit data. The 'in' value used for the computation assumes
* the data transferred is not including a hamming byte. When the computation is made the
* Hamming byte is added to the input value which is accomplished by shifting the 24-bit
* value left by 8 bits.
*
* \param    uint32_t in of the value to be computed and compared.
*
* \returns  uint32_t ham returns 0 if a match or the computation from the Hamming bits/checksum.
*/
uint32_t checkHamming(uint32_t in)
{
// When validating the hamming, take the input data and compute the hamming less the
//    hamming byte
// So take 'in' and right shift 8 and then compute the hamming
uint32_t ham = calcHamming((in & 0xFFFFFF00) >> 8);
// The computed hamming byte is XORed with the hamming byte returned from the data which
//    ideally would be 0 for hamming code plus checksum
//    as the ham value is the complete 32-bit word with hamming that was computed from
//    the data and compared to what was actually transmitted
uint32_t res = ham ^ in;
if(res == 0) return res;
else return (ham & 0x000000FF);
}