4. Error checking code (CRC check)
A master or slave can use the check code to verify the correctness of the
received data.
Due to noise or other interference, errors can occur in the data transmission.
The error checking code (CRC) can be used to verify that the data
transmission has proceeded correctly and allows erroneous data to be
discarded, thus increasing security and system performance.
The CRC code in Modbus communications contains 2 bytes.
The younger 8 bits are in the front and the older 8 bits are in the back,
resulting in a 16 bit binary number.
The CRC code is calculated by the sending device (host), it is in the last
position in the information frame. The receiving device (slave) calculates the
CRC code again and compares whether the designated and received codes
are the same.
If the codes differ, an error has occurred during data transmission.
5. CRC code calculation method
The CRC calculation method is as follows:
a) A 16-bit register is set hexadecimal as FFFF. This register is called the CRC
register.
b) Performing an XOR operation on the first byte of data (from the frame)
and the younger byte of the CRC register.
The result of the operation is placed in the CRC register.
c)
Shift the content of the CRC register one bit to the right (towards the
younger bit), set the value of the oldest bit to 0, and then check the
shifted bit.
d) If the output bit is 0, step (c) is repeated; if the bit is 1: the XOR
operation of the CRC register with the polynomial A001 (1010 0000 0000
0001) is performed.
e) Repeat steps c) and d) up to eight times, which corresponds to
processing 8 bits (1 byte) of data.
f)
Perform steps b) through e) for the next byte of the communication
frame.
g) After all bytes of the communication frame have been converted
according to the above steps, the younger and older bytes of the
resulting 16-bit CRC register are exchanged.
h) The final content of the CRC register is the value of the CRC code.
3.4.
Cleaning and maintenance