65
User Manual
9.4.4 CRC Mode
RTU frame format is mainly applied to CRC (Cyclical Redundancy Check), error detecting field based
on CRC is included in the message. CRC domain can detect all the information of message, which is
two bytes with 16-bit binary value included. It will be added into the message after the calculation of
transmission devices. The receiver
will recalculate the CRC receiving the message, and compare it with the values in the CRC domain
received by devices; if the CRC value is not equivalent to another one, it proves that there is error in
the transmission
CRC will write 0xFFFF in superior host, and call a program to process the consecutive 8 bytes in the
message as well as the values in the register. Only 8-bit data of each character is valid to CRC, the
others are all invalid, including start bit, stop bit and parity check bit.
When CRC is added into the message, lower byte will be added first, then the high byte. The simple
function of CRC is as follows:
During the operation of CRC, each of 8-bit character is exclusive (XOR) with register content
separately; result will be inclined to the least significant bit(LSB) while the most significant bit will be
filled with Zero. LSB will be extracted from the data for checking; if LSB is one, register will be
exclusive(XOR) with preset value separately; if LSB is zero,
calculation will not be conducted. This instruction of process will repeat for 8 times; when it comes to
the last bit (8th bit), the next 8-bit bytes will be exclusive(XOR) with register value again. The final
value in the register is the CRC value after the calculations of all the bytes in the message.
{
{
while(length--)
}
unsigned int crc_chk_value(unsigned char *data_value,unsigned char length)
unsigned int crc_value=0xFFFF;
int I;
crc_value ^= *data_value++;
for(i=0;i<8;i++)
{
if(crc_value&0x0001)
{
crc_value=(crc_value>>1)^0xa001;
else
}
}
return(crc_value);
}
crc_value =(crc_value>>1);
{
}