PD Series - Modbus-Rtu - Protocolo de Comunicación

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

MODBUS-RTU Communication Protocol

A.1 Communication format


Information transmission adopts asynchronous mode, taking byte as the unit. The
communication date transmitted between the host and slave computer is the format of
10-digit characters, including one start bit(0), 8 data bits without check bit, two stop
bits(1)(other format can be customized).
Format of information frame:
Table A.1

Address Function CRC check


Start Data field End
code code code
More than More than
1 n 2
3.5-character 1 character 3.5-character
character characters characters
dead time dead time
A.2 Communication information transmitting procedure
When communication command is transmitted from the host computer to the slave
computer, the slave computer which matches the address code sent by the host
computer receives the communication command. If CRC checks without any fault, then
the corresponding operation will be carried out, after that the implement result (date) is
returned to the host computer. The returned information contains address code, function
code, implement date and CRC check code.
A.2.1 Address code
Address code is the first byte of each communication frame, with the range from 1 to
247. Each slave must have an exclusive address code in the bus, only the slave computer
which matches the address code sent by the host computer can respond returned
information. When the slave computer returns the information, the returned data will
begin with their respective address codes. The address code sent from the host computer
indicates the slave address, the returned address code from the slave computer indicates
the slave address, while the corresponding address code indicates where the information
comes from.
A.2.2 Function code
It’s the second byte of each communication frame. It’s sent by the host and tells the
slave computer what actions should be carried out through function code. The slave
will respond, and the functional code is the same as that sent by the host computer,
which indicates that the slave computer has responded the host and complemented the
relative operation.
The instrument supports the following two function codes:
Table A.2
Function
Definition Operation
code
03H Read register Read one or several register data
Write multichannel Write n 16-bit binary data into n continuous
10H
register registers
A.2.3 Data area
The data field will be different based on different function codes. These data can
be numerical values, reference addresses and so on. For different slave computers, both
the address and data information are different, and the communication information table
should be provided.
The host utilizes communicate command (function code 03H and 10H) to read and
modify the data registers of the slave freely. But the data length which is read or write
at one time should not be out of the effective range of the data register’s address.
A.3 Brief introduction of function code
A.3.1 Function code 03H:Read register
For example: The slave address which the host intends to read is 01H, the start register
address is two register data of 0CH, sent by the host:
Table A.3
The host sends Send message
Address code 01H
Function code 03H

Start register High byte 00H


address low byte 0CH
High byte 00H
Register number
low byte 02H
low byte 04H
CRC 校验码
High byte 08H

If the data of the slave register 0CH, 0DH is 0000H, 1388H, the slave will return:
Table A.4
The slave returns Return message
Address code 01H
Function code 03H
Bytes 04H
Register 0CH data High byte 00H
low byte 00H
High byte 13H
Register 0DH data
low byte 88H

low byte F7H


CRC check code
High byte 65H

A.3.2 Function code 10H:Write multi-port register


For example:The host intends to save data of 0002H, 1388H, 000AH into the
slave address of 01H,the start register address is the three registers of 00H, sent by the
host:
Sent by the host:
Table A.5
The host sends Send message
Address code 01H
Function code 10H

High byte 00H


Start register address
low byte 00H
High byte 00H
Register number
low byte 03H
Write bytes 06H
The data to be High byte 00H
written in 00H
low byte 02H
register

The data to be High byte 13H


written in 01H
low byte 88H
register
The data to be High byte 00H
written in 02H
low byte 0AH
register
CRC check code low byte 9BH
High byte E9H
Returned by the slave
Table A.6
The slave returns Return message

Address code 01H


Function code 10H
High byte 00H
Start register address
low byte 00H
High byte 00H
Register number
low byte 03H

low byte 80H


CRC check code
High byte 08H
A.4 16-digit CRC check code
The host or slave computer can be judged by the check code to see if the
received information is correct or not. The interruption by electronic noises or other
factors may cause errors during information transmission.
16-digit CRC check code is calculated by the host, located at the end of the
transmit information frame. The slave recalculates the received information of CRC
and compares if the calculated CRC goes in line with the received CRC, if not, there
is an error. Only 8 data bits are used during CRC calculation, both the start bits and
the stop bits are not involved in the calculation.
The calculation method of CRC check code is stated as follows:
1) Pre-arrange one 16-digit register as a hexadecimal FFFF ( i.e. fully 1), the
register is called CRC register;
2) Make the first 8-digit binary data ( the first byte of the communication
information frame) with the lower 8 digits of the 16-digit CRC register by XOR
calculation, the result is placed in CRC register;
3) Shift the content of CRC register rightward by one digit (towards the lower
digit) and fill in the highest digit with 0, check the shift-out digit after rightward
shifting;
4) If the shift-out digit is 0: repeat step 3) (shift rightward one digit again);
If the shift-out digit is 1: make CRC register with multinomial A001 by XOR
calculation
5) Repeat step 3) and 4) until shift rightward for 8 times, then all the 8 digits are
processed;
6) Repeat step 2) and 5), process the next byte of the communication information
frame;
7) After calculating all the bytes of the communication information frame (exclude
CRC check code) according to the above steps, the content of the CRC register to be
get is: 16-digit CRC check code.
A.5 Error handling
When the meter detects other errors except the error of CRC check code, the
information will be returned to the host, the highest digit of the function code is 1, i.e.
the function code returned to the host from the slave is adding 128 base on the
function code sent from the host. The error returned from the slave is as follows:
Table A.7
Address Function code Error CRC check CRC check code
code (top digit is 1) code code low byte High byte
1 byte 1 byte 1 byte 1 byte 1 byte

Error code is as follows:


Table A.8

Illegal function The function code received is not supported by the


01H
code instrument
Illegal register The register address received is out of the register
02H
address address range
Illegal data value The data value received is out of the corresponding
03H
address data range

You might also like