Rtu mode, Example of crc-16 calculation – Yokogawa PR300 Power and Energy Meter User Manual

Page 84

Advertising
background image

<Toc> <Ind>

<5. Modbus/RTU and ASCII Communication Protocols>

5-5

IM 77C01E01-10E

RTU Mode

In the RTU mode, errors are checked by means of a CRC-16 cyclic redundancy check.
The CRC-16 value is the 16-bit remainder when the value obtained by concatenating the 8
bits of all blocks (from the station number to the last data item) of a message, excluding the
start bit, stop bit and parity bit, is divided by a predetermined 17-bit binary number.

Example of CRC-16 Calculation

When executing function code 03 (reads data from multiple D registers) to read the status
from the slave at station number 11 “0B”, send the 0B03002A0004 command.

[1]

The initial value is FFFF. Find the XOR value of this initial value and the first character
(= station number 11).

[2]

Refer to the lower byte of the result of executing the function code (or the upper byte, if
the result is regarded as a block of text). From the table, obtain the value correspond-
ing to that byte. Since the result is “F4” in this example, you refer to the 244th value in
the table and obtain “8701”.

[3]

Find the XOR value of the upper byte of the XOR operation in step [1] and the result of
step [2]. This value is the first character of the CRC-16 calculation.

[4]

Using the result of step [3] (remainder) as the next initial value, make the same calcu-
lation to evaluate the second character (function code 03).

Initial value

FF FF

Station number

0B
---------

XOR

FF F4

Reference to table

87 01
--------

XOR

87 FE

Function code

03
--------

XOR

87 FD

Reference to table

81 C1
--------

XOR





81 46

XOR

E5 9E

Last character

04
--------

XOR

E5 9A

Reference to table 6B 80

--------

Resulting error

6B 65

Convert the hex value to a decimal
value, find the corresponding number
in Table 5.2, and substitute the number
into the formula.
In the example shown on the left,
hex value “F4” is converted to decimal
value 244. From Table 5.2, the number
corresponding to 244 proves to be “8701”.
This number is substituted into the formula.

[5]

Repeat steps [1] to [4] to perform the calculation up to the last character string 04.

[6]

Reverse the order of the upper and lower bytes of 6B65 and append 656B to the end
of the character string as the error code.
0B03002A0004656B

First reverse the order of the upper and lower bytes of the calculated result, then compare the value with the received data or
store the value in the transmission buffer.

* Numbers in quotation marks are hexadecimal.

Advertising