17 / 74
FG_F6_MODBUS_EN_01 / 2020-06-17
CRC CALCULATION
Definition
In Modbus RTU, the
Cyclic Redundancy Check
is calculated on 16 bits. It is therefore called
CRC16
.
The CRC16 is a calculation based on the binary value of each character composing the frame. This
function translates the frame into a 16-bit binary word; this binary word is inserted at the end of the
frame.
When the master or the slave receives a frame, it calculates the CRC16 of this frame and compares
the result with the value of CRC16 contained in the frame (last word), in order to check that the
exchange has been correctly undertaken:
—
If the CRC16 corresponds, the slave responds.
—
If the CRC16 is false:
o
The slave that receives the erroneous frame does not respond,
o
The master having not received a response restarts the same request for the slave.
If the exchange is not accomplished after 2 attempts, the master declares a communication error in
the network and stops the exchanges.
CRC16 calculation algorithm
CRC16 = 0FFFFh
// Initialization at the start of each new data frame
As long as (NO(End of frame))
CRC16=(CRC16 OR exclusive character received)
for (i=0;i<8;i++)
{
CRC16=CRC16/2
If there are remainders to the division then
CRC16= (CRC16 XOR 0A001h)
}
FTQ