CHAPTER 13 RS-485 COMMUNICATIONS
13-28
Modbus RTU Communications
13
6. CRC-16
(1) Outline of CRC
CRC (Cyclic Redundancy Check) is a system to check if communications data are correct.
In the CRC calculation, data expressed as a polynomial are divided by a generating polynomial,
and the residue is used as CRC data.
Modbus RTU uses the CRC-16 which performs calculation using X
16
+ X
15
+ X
2
+ 1 as the
generating polynomial.
(2) CRC-16 calculation algorithm
The algorism for calculating CRC-16 on the data (N bytes) from the station number field to the
information field is as follows:
CRC ・・・ Calculated value of CRC-16
POLY ・・・ Generating polynomial
dtn ・・・ Data counter
sft ・・・ Shift counter
DT[dtn] ・・・ Nth data (one byte)
N ・・・ Number of data bytes
XOR ・・・ exclusive OR
DT[0] is station number, DT[1] is FC, and
DT[2]-DT[N-1] are data in the information
field.
START
Default settings
CRC
= FFFFh
POLY
= A001h
dtn
= 0
Shift carry available?
No
Yes
No
CRC = CRC XOR DT[dtn]
Shift CRC to the right by one bit
CRC = CRC XOR POLY
Yes
sft = sft + 1
sft = 0
sft < 8
dtn < N ?
dtn = dtn + 1
Yes
No
END