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 following code example can be used for devices such as the ADS1259 and ADS1262 that have the checksum data integrity feature. The checksum can be computed by sending a pointer to the data along with the length of the data packet to be considered. The data bytes are summed together along with the constant to create the checksum byte. The computed checksum byte is then compared with the checksum transmitted with the data. The byte values should match otherwise an error occurred.
/**
* Computes a checksum for an array of data bytes.
*
* \details Computes a series of bytes pointed to
* by an array of data for a specified length. A constant 0x9B is also added.
*
* \param uint8_t *data, pointer to data array.
* \param uint32_t length, of data array.
*
* \returns uint8_t result.
*/
uint8_t calcChecksum(uint8_t* data, uint32_t length)
{
uint32_t result = 0;
uint32_t i;
for(i = 0; i < length; i++)
result += data[i]; // Add conversion data bytes together
result += 0x9B; // Add constant
return (uint8_t) result;
}