When I read the Tformat encoder using SCI, I made the CRC calculation as follows. The code before __flip() of the bit string was difficult to understand, and I thought that __flip() would not be necessary when reading from SCI, so I made it. If I have missed something, please let me know.
#include "device.h"
#include "driverlib.h"
void SCI_tformat_generateCRCTable(uint16_t *pTable)
{
uint16_t i, j;
uint16_t accum;
uint16_t polynomial = 0x0081;
for(i = 0; i < 256 ; i++)
{
accum = i;
for( j = 0; j < 8; j++)
{
if(accum & 0x0001)
{
accum = ((accum >> 1) & 0xFF) ^ polynomial;
}
else
{
accum = ((accum >> 1) & 0xFF);
}
}
pTable[i] = accum;
}
}
uint16_t SCI_tformat_getCRC( uint16_t * msg, uint16_t *crcTable, uint16_t rxLen)
{
uint16_t i;
uint16_t accum = 0;
int *pdata;
pdata = (int *)msg;
for (i = 0; i < rxLen; i++) {
accum = crcTable[(accum ^ __byte(pdata,i)) & 0xFF] ^ (accum >> 8);
}
return accum;
}
