
24
The assignment of the CRC sum through table indexing is further
more rapid than the calculation of a new CRC value for each sign of
the communication buffer.
Note
: The below function represents bytes of the sum
CRC higher/lower, and this way the CRC value returned
by the function can be directly placed in the communi-
cation buffer.
The function serving to calculate CRC has two arguments:
unsigned char *puchMsg;
Pointer for the communication
buffer, including binary data from
which one must calculate LRC.
unsigned short usDataLen;
Number of bytes in the
communication buffer.
The function returns CRC of
unsigned short type
.
unsigned short CRC16(puchMsg, usDataLen)
unsigned char *puchMsg;
/* buffer to calculate CRC */
unsigned short usDataLen;
/* Number of bytes in the buffer */
{
unsigned char uchCRChi = 0xFF; /* initialisation of the
higher CRC byte CRC */
unsigned char uchCRClo = 0xFF; /* initialisation of the
lower CRC byte */
while (usDataLen- -)
{ uIndex =uchCRChi ^ *+; /*
CRC
calculation */
uchCRChi = uchCRClo ^ crc_hi[uIndex];
uchCRClo = crc_lo[uIndex];
}
return(uchCRChi<<8 | uchCRClo);
}
Summary of Contents for RE15
Page 1: ...1 USER S MANUAL SERIAL INTERFACE WITH MODBUS PROTOCOL MICROPROCESSOR CONTROLLER RE15...
Page 2: ...2...
Page 27: ...27...