I am trying to communicate an industrial type counter using Modbus. I have to calculate CRC16 value as two byte for send it. I previously googled for few Arduino libraries and I get a same function as below. But, I couldn't understand the function well.
I need CRC as two bytes and as input I have 6 bytes.
Can someone explain the below function and what are the argument I need to provide.
uint16_t crc16_update(uint16_t crc, uint8_t a)
{
int i;
crc ^= a;
for (i = 0; i < 8; ++i)
{
if (crc & 1)crc = (crc >> 1) ^ 0xA001;
else crc = (crc >> 1);
}
return crc;
}