12: M
ODBUS
ASCII/RTU C
OMMUNICATION
12-16
FC5A M
ICRO
S
MART
U
SER
’
S
M
ANUAL
FC9Y-B1268
LRC and CRC
ASCII mode uses LRC check codes and RTU mode uses CRC check codes.
Modbus ASCII Mode — Calculating the LRC (longitudinal redundancy check)
Calculate the BCC using LRC for the range from the slave number to the byte immediately before the BCC.
1.
Convert the ASCII characters in the range from the
slave number
to the byte immediately before the BCC, in units of two
characters, to make 1-byte hexadecimal data. (Example: 37h, 35h
75h)
2.
Add up the results of step
1
.
3.
Invert the result bit by bit, and add 1 (2’s complement).
4.
Convert the lowest 1-byte data to ASCII characters. (Example: 75h
37h, 35h)
5.
Store the two digits to the BCC (LRC) position.
Modbus RTU Mode — Calculating the CRC-16 (cyclic redundancy checksum)
Calculate the BCC using CRC-16 for the range from the slave number to the byte immediately before the BCC. The gener-
ation polynomial is: X
16
+ X
15
+ X
2
+ 1.
1.
Take the exclusive OR (XOR) of FFFFh and the first 1-byte data at the
slave number
.
2.
Shift the result by 1 bit to the right. When a carry occurs, take the exclusive OR (XOR) of A001h, then go to step
3
.
If not, directly go to step
3
.
3.
Repeat step
2
, shifting 8 times.
4.
Take the exclusive OR (XOR) of the result and the next 1-byte data.
5.
Repeat step
2
through step
4
up to the byte immediately before the BCC.
6.
Swap the higher and lower bytes of the result of step
5
, and store the resultant CRC-16 to the BCC (CRC) position. (Example:
1234h
34h, 12h)
Phone: 800.894.0412 - Fax: 888.723.4773 - Web: www.clrwtr.com - Email: [email protected]