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
The checksum is computed from the received data and compared to the checksum value transmitted by using a bitwise XOR. A checksum error occurs if a nonzero value is computed from the XOR. The checksum used for the ADS131A0x differs from the computation for the ADS1259 discussed in Section 2.1.
/**
* Computation and verification of the checksum from the Hamming byte.
*
* \details Computation of checksum bits using a checksum bit mask and counting
* the number of bits set in the masked value.
*
* \param uint32_t in of the value to be computed and compared.
*
* \returns uint32_t Returns 0 if a match or non-zero for a failure.
*/
uint32_t checkSum(uint32_t in)
{
// Compute the checksum for the data after stripping out the hamming/checksum byte
// compare the the computed checksum with the hamming/checksum byte by XORing
// the result should be '0' for a proper checksum. Remember to compare after moving
// the checksum left by 1 to place the checksum in the proper position. Also remove
// all other bits in the compare that are not checksum by ANDing with
// 0x06 (0x03 shifted left by one)
return (in ^ ((countBits(in & CHECKSUM_BIT_MASK) << 1))) & 0x06;
}