Está en la página 1de 27

Modbus training

Part 1 : Reference documents - WEB sites

Part 2 : Definitions

Part 3 : Modbus frame description

Part 4 : Security of transmission

Part 5 : Physical layer

Part 6 : Main characteristics resume

P&T - GPS - Training Section 6 - Slide 1 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 1 : Reference documents - WEB sites

Schneider documents

Modbus User guide


Reference : TSX DG MOD *

Detailed description of the Modbus protocol.

X-WAY communication user guide


Reference : TSX DR NET *

This guide gives common characteristics to X-WAY Schneider networks.

Communication application specific functions PL7 Micro/Junior/Pro


Reference : TLX DS COM PL7 42 *

Volume 1 : Common communication application


Volume 2 : Modbus bus

P&T - GPS - Training Section 6 - Slide 2 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 1 : Reference documents - WEB sites

WEB sites

Modbus.org :
http://www.modbus.org
Modicon site for Modbus users.

Transparent Factory :
http://www.transparentfactory.com
Schneider Electric site for Transparent Factory users.

Modbus Plus :
http://www.modicon.com/techpubs/toc6.html
Modbus Plus Planning and installation.

P&T - GPS - Training Section 6 - Slide 3 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 2 : Définitions

Modbus protocol

MODBUS Protocol is a messaging structure created by MODICON


company to connect PLC to programming tools.

It is now widely used to establish master-slave communication between


intelligent devices.

MODBUS is independent of the physical layer.

It can be implemented using RS232, RS422, or RS485 or over a variety


of media (e.g. fiber, radio, cellular, etc...).

P&T - GPS - Training Section 6 - Slide 4 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 2 : Définitions

Modbus Serial line RS485

MODBUS Serial line RS485 is a low cost network using a master/slave


medium access with a transmission speed from 1,200 to 115 Kbits/s.

7 Application Modbus

6 Presentation
5 Session

4 Transport

3 Network

2 Link Master - Slave


1 Physical RS485
P&T - GPS - Training Section 6 - Slide 5 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 2 : Définitions

Modbus TCP/IP

MODBUS TCP/IP uses TCP/IP and Ethernet 10 Mbit/s or 100


Mbits/s to carry the MODBUS messaging structure.

7 Application Modbus

6 Préeentation
5 Session

4 Transport TCP

3 Network IP

2 Link CSMA / CD
ETHERNET V2 ou 802.3
1 Physical

P&T - GPS - Training Section 6 - Slide 6 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 2 : Définitions

Modbus Plus

MODBUS PLUS is a higher speed network 1 Mbit/s token passing derivative


that uses the MODBUS messaging structure.

7 Application Modbus

6 Presentation
5 Session

4 Transport

3 Network

2 Link 802.4 Token passing


1 Physical RS485

P&T - GPS - Training Section 6 - Slide 7 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 2 : Définitions

Modbus ASCII and Modbus RTU

The MODBUS protocol comes in 2 versions :

 ASCII transmission mode


Each eight-bit byte in a message is sent as 2 ASCII characters.

 RTU transmission mode


Each eight-bit byte in a message is sent as two four-bit hexadecimal
characters.

The main advantage of the RTU mode is that it achieves higher throughput.

ASCII mode allows time intervals of up to 1 second to occur between


characters without causing an error.

P&T - GPS - Training Section 6 - Slide 8 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Modbus frame structure

The Modbus frame structure is the same for requests (master to slave
messages) and responses (slave to master messages).

Modbus RTU

silence Address Function Data Checksum silence

Silence >= 3,5 characters

Modbus ASCII

: Address Function Data Checksum CR LF

3A Hex 0D Hex 0A Hex


P&T - GPS - Training Section 6 - Slide 9 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Address field

Address Function Data Checksum

Valid slave device addresses are in the range of 0 ... 247 decimal.
The individual slave devices are assigned addresses in the range of 1 ... 247.
Value 0 is reserved for broadcast messages (no response).
Request :
A master addresses a slave by placing the slave address in the address field of
the message.

Response :
When the slave sends its response, it places its own address in this address field
of the response to let the master know which slave is responding.

P&T - GPS - Training Section 6 - Slide 10 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Function field

Address Function Data Checksum

Valid codes are in the range of 1 ... 255 decimal.

Request :
The function code field tells the slave what kind of action to perform.

Response :
For a normal response, the slave simply echoes the original function code.

For an exception response, the slave returns a code that is equivalent to


the original function code with its most significant bit set to a logic 1.
P&T - GPS - Training Section 6 - Slide 11 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Data field

Address Function Data Checksum

Valid codes are in the range of 0 ... 255 decimal.

Request :
The data field contains additional information which the slave must use to take
the action defined by the function code. This can include items like register
addresses, quantity of items to be handled, etc...

Response :
If no error occurs, the data field contains the data requested.

If an error occurs, the field contains an exception code that the master
application can use to determine the next action to be taken.
P&T - GPS - Training Section 6 - Slide 12 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Checksum field

Address Function Data Checksum

Valid codes are in the range of 0 ... 255 decimal.

Modbus RTU uses CRC : Cyclycal Reduncy Check (2 byte)


Modbus ASCII uses LRC : Longitudinal Redundancy Check (1 bytes)

Request :
The checksum is calculated by the master and sends to the slave.

Response :
The checksum is re-calculated by the slave and compared to the value sent
by the master.
If a difference is detected, the slave will not construct a response to the master.
P&T - GPS - Training Section 6 - Slide 13 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Frame exemple in RTU mode

 Function code = 03 : Read Holding Registers

Request :

1 byte 1 byte 2 bytes 2 bytes 2 bytes


Slave Function First word Number of
CRC16
Address code = 03 address words to read

Response :

1 byte 1 byte 2 bytes 2 bytes 2 bytes 2 bytes


Slave Function Number of Value of the Value of the
CRC16
Address code = 03 bytes read first word last word

P&T - GPS - Training Section 6 - Slide 14 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Frame exemple in RTU mode

 Function code = 06 : Write Single Register

Request :

1 byte 1 byte 2 bytes 2 bytes 2 bytes


Slave Function Word Value of
CRC16
Address code = 06 address word

Response :

1 byte 1 byte 2 bytes 2 bytes 2 bytes


Slave Function Word Value of
CRC16
Address code = 06 address word

P&T - GPS - Training Section 6 - Slide 15 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Frame exemple in RTU mode

 Function code = 16 (décimal) : Write Multiple Registers

Request :

1 byte 1 byte 2 bytes 2 bytes 1 byte 2 bytes 2 bytes


Slave Function First word Number of Number of Value of the
CRC16
Address code = 16 address words to write bytes first word

Response :

1 byte 1 byte 2 bytes 2 bytes 2 bytes


Slave Function First word Number of
CRC16
Address code = 16 address words to write

P&T - GPS - Training Section 6 - Slide 16 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 3 : Modbus frame description

Function code exemples

Code Function

01 (0x01) Read Coils


02 (0x02) Read Discrete Inputs
03 (0x03) Read Holding Registers
04 (0x04) Read Input Registers
05 (0x05) Write Single Coil
06 (0x06) Write Single Register
15 (0x0F) Write Multiple Coils
16 (0x10) Write Multiple Registers
23 (0x17) Read/Write Multiple Registers
43 (0x2B) Read Device Identification

The complete description of all Modbus request is freely available on the


Modbus.org web site : http://www.modbus.org

P&T - GPS - Training Section 6 - Slide 17 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 4 : Security of transmission

Error checking methods

 Parity checking
Even or odd can be optionally applied to each character.

 Frame checking
LRC or CRC is applied to the entire message.

 Continuous stream
The entire message frame must be transmitted as a continuous stream.
If a silent interval (more than 1.5 character times RTU mode or 1 second ASCII mode) occurs
before completion of the frame, the receiving device flushes the incomplete message and
assumes that the next byte will be the address field of a new message.

P&T - GPS - Training Section 6 - Slide 18 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 4 : Security of transmission

Error checking methods

The master is configured by the user to wait for a predetermined timeout


interval before aborting the transaction.

This interval is set to be long enough for any slave to respond normally.

If the slave detects a transmission error, the message will not be acted upon.
The slave will not construct a response to the master.
Thus the timeout will expire and allow the master's program to handle the error.

P&T - GPS - Training Section 6 - Slide 19 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 5 : Physical layer

RS485 physical layer

RS485 is the most common physical layer used on Modbus.

The RS485 standard allows variants of different characteristics :

 polarisation
 line terminator
 distribution of a reference potential
 number of slaves
 length of the bus

P&T - GPS - Training Section 6 - Slide 20 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 5 : Physical layer

The various versions of the RS485 physical layer

The new Telemecanique devices conform to the Modbus specification


published in 2002 on the Modbus.org web site.

But some Schneider older devices comply with earlier specifications :

 Uni-Telway
 Jbus

P&T - GPS - Training Section 6 - Slide 21 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 5 : Physical layer

New Modbus RS485 standard schematic

5V
Master 650 

650 

D1
120  120 
1 nF 1 nF
D0
Common

Slave 1 Slave 2

Maximum length of bus 1000 m at 19200 bps


Maximum number of stations (without repeater) 32 (31 slaves)
Maximum length of tap links 20 m for one tap link
40 m divided by the number of tap links
Bus polarisation 650  at 5V and common for the master
Line terminator 120  - 0,25Wm in series with 1nF 10V
Common polarity Yes (Common) connected to the PG
P&T - GPS - Training Section 6 - Slide 22 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 5 : Physical layer

Uni-Telway RS485 schematic

5V
Master 4,7 K
4,7 K

D(B)
120  120 
1 nF D(A) 1 nF
0 VL

5V 5V

4,7 K 4,7 K 4,7 K 4,7 K

Slave 1 Slave 2

Maximum length of bus 1000 m at 19200 bps


Maximum number of stations (without repeater) 29 (28 slaves)
Maximum length of tap links 20 m for one tap link
40 m divided by the number of tap links
Bus polarisation 4,7 K at 5V and common for the master and slaves
Line terminator 120  - 0,25Wm in series with 1nF 10V
Common polarity Yes (0 VL) and high impedance place between 0 VL
and the ground in each station
P&T - GPS - Training Section 6 - Slide 23 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 5 : Physical layer

Jbus RS485 schematic

5V
Master
470 
470 

L-(B/B ’)
150  150 
L+(A/A ’)

Slave 1 Slave 2

Maximum length of bus 1300 m at 19200 bps


Maximum number of stations (without repeater) 32 (31 slaves)
Maximum length of tap links 3m
Bus polarisation 470  at 5V and common for the master
Line terminator 150 
Common polarity No

P&T - GPS - Training Section 6 - Slide 24 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 5 : Physical layer

Mixed RS485 schematic


Suitable polarization Rp
5V must be calculated
Master Rp

Rp

120  D1
120 

1 nF D0 1 nF
Common

5V If the master is fitted with a 470  polarisation,


4,7 K
4,7 K
it ’s possible to connect a maximum of
Slave 1 Slave 2 18 slaves with 4,7 K polarisation

Maximum length of bus 1000 m at 19200 bps


Maximum number of stations (without repeater) At most 32 stations (depending on Rp and the number of
4,7 K
Maximum length of tap links 20 m for one tap link
40 m divided by the number of tap links
Bus polarisation Rp should be validated by calculating the equivalent polarisation Re
according to the polarisation of the master and slave stations. Re
must be between 162  and 650 
Line terminator 120  - 0,25Wm in series with 1nF 10V
Common polarity Yes (Common) connected to the PG
P&T - GPS - Training Section 6 - Slide 25 / 27
PhW - 06_TECH_Modbus_en 06/ 2004
Part 6 : Main characteristics resume

Main characteristics resume

Topology: Bus with line terminations

Maximum distance: With RS485 : 1000 m without repeater

Data rate: From 1,200 to 115 Kbits/s

Max. no. of devices: With RS485 : 32 master included

P&T - GPS - Training Section 6 - Slide 26 / 27


PhW - 06_TECH_Modbus_en 06/ 2004
Part 6 : Main characteristics resume

Main characteristics resume

Method of accessing the medium: Master slave

Transmission method: Messaging

Max. useful data size: 120 words

Transmission security: LRC or CRC


Start and stop delimiters
Parity bit
Continuous stream

P&T - GPS - Training Section 6 - Slide 27 / 27


PhW - 06_TECH_Modbus_en 06/ 2004