71
6
. Detailed settings for communications
6.2 Modbus (continued)
■
Response frame when there is an error
■
An example for CRC-16 calculation
The work for calculation (16 bit register: CRC register hereunder) is processed byte by byte in the message.
1
Make the initial value of the CRC register H'FFFF
2
Use an XOR on the lower 8 bits of the CRC register and the first byte of data, return that result to the CRC register, then
while embedding the "0", move the CRC register 1 bit to the right
3
If the bit shifted from the LSB is "0", repeat step
3
(the following bit shift process). If the bit shifted from the LSB is a "1",
use an XOR calculation on the CRC register and H'A001, returning that result to the CRC register
4
Repeat steps
3
and
4
until 8 bits worth of data has been shifted
5
If the end of the message is not reached, use an XOR on the CRC register and the next byte of data, return that result to
the CRC register and repeat step
3
6
The calculated result (the value of the CRC register) is appended to the message starting from the lower byte
Example of appending the calculated result
If the calculated CRC value is H'1234, it is appended to the command frame as below.
Commun
ication
address
Function
code
Error
code
CRC-16
1
1
1
2
Communication address
The number specified by the command from is inserted as is.
This is the communication address that returned the response.
Function code
In the response frame when an error occurs, the addition of "H'80" to the
received function code indicates that it is an error response.
For example: If the response is H'03 normally, then a response when there is
an error would be H'83.
Error code
An exit code to describe an error.
CRC-16
Cyclical Redundancy Check
This check code is for the communication address until the end of the data.
Commun
ication
address
Function
code
Data
CRC-16
Low
High
H’34
H’12
1
1
2
Range of CRC-16 calculation