-16-
5.3.5 Error check
Error check for transmission frames is different between the transmission modes.
RTU mode: CRC-16
ASCII mode: LRC
5.3.5.1 Calculation of CRC-16
In the CRC system, the information to be transmitted is divided by a generating polynomial, the resulting
remainder being added to the end of the data. The generation polynomial is as follows.
1 + X
2
+ X
15
+ X
16
The data from its slave address to its end is calculated in the following procedure.
1) Initialize the CRC-16 data (assumed as X) (= FFFFH)
2) Exclusive logical sum (EX - OR) between data 1 and X X
3) Shift X one bit to the right X
4) When a carry is generated, take A001H and EX-OR. If not, go to 5). X
5) Repeat 3) and 4) until shifting 8 times.
6) EX-OR between the next data and X X
7) Same as 3) to 5)
8) Repeat up to the last data
9) Create a message in the sequence from lower to upper orders of the calculated 16-bit data (X).
Example) Since CRC-16 is 1241H for the data 01H
07H , the error check data will be 41H 12H.
Reference: CRC-16 Calculation Program
10 D(1) = &H2 : D(2) = &H7 : N = 2
20 GOSUB *CRCMAKE
30 END
40
100 *CRCMAKE
110 CRC = &HFFFF
120 FOR I = 1 TO N
130 CRC = CRC XOR D(I)
140 FOR J = 1 TO 8
150 CY = CRC AND &H1
160 IF CRC < 0 THEN P = &H4000 ELSE
P = 0 : GOTO 180
170 CRC = CRC AND &H7FFF
180 CRC = CRC 2
190 CRC = CRC OR P
200 IF CY = 1 THEN CRC = CRC XOR
&HA001
210 NEXT J
220 NEXT I
230 IF CRC < 0 THEN P = &H80 ELSE
P = 0 : GOTO 250
240 CRC = CRC AND &H7FFF
250 C1 = CRC AND &HFF
260 C2 = ( CRC AND &H7F00 ) 256
270 C2 = C2 OR P
280 D (N+1) = C1 : D(N+2) = C2
290 RETURN