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
Reassembling the data can be done in various ways while accomplishing the same result. One method is to use a pointer to an array of data and then store the contents to another array in reflected order both by bit and byte order.
/**
* Reconfigures the data for CRC computation when comparing to LSB first transmissions.
*
* \details Reorders the bits in reverse order of byte submitted
* and changes the order of bytes computed for CRC. This is required as the data is always
* transmitted out the UART lsb first.
*
* \param uint8_t *data pointer to data array.
* \param uint32_t length of data array.
*
* \returns crc_t CRCvalue from computation.
*/
crc_t formatCRCdata(uint8_t *data, uint32_t length)
{
uint32_t u32i, u32j;
uint8_t checkCRC[length];
crc_t dataCRC;
// Start copying with LSB as first element in the CRC array
u32j = length - 1;
for(u32i = 0; u32i < length; u32i++) // For each byte in the data packet
{
checkCRC[u32i] = revByte((data[u32j])); // Reverse the byte
u32j--;
}
dataCRC = crcBitwise(checkCRC, length); // or TableCRCcalc(checkCRC, length)
return dataCRC;
}