Data Communication
and
Networking
Dr. –Ing.
Vo Que Son
Email:
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
1
Content
Chapter 3: Data Link Layer Protocols
Flow Control
Error Control
Connection Management
Data link layer Protocols
Chapter 4: Industrial Networks
MODBUS
Controller Area
Network
Applications
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
2
MODBUS
MODBUS Protocol is a Serial Communication Protocol created
by MODICON company to connect PLC to programming tools.
It is now widely used to establish master-slave communication
between intelligent devices.
It can be implemented using RS232, RS422, or RS485
variety
(e.g. fiber,
MODBUSofismedia
independent
of the radio,
physicalcellular,
layer. etc...).
Telecomm. Dept.
Faculty of EEE
or over a
DCN-2013
HCMUT
3
MODBUS
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
6
5
4
3
2
1
Telecomm. Dept.
Faculty of EEE
Applicatio
Application
Modbus
Presentation
Session
Transport
Network
Link
Physical
Maste
Slave
r -
RS485
DCN-2013
HCMUT
4
MODBUS
MODBUS TCP/IP uses TCP/IP and Ethernet 10 Mbit/s
or 100 Mbits/s to carry the MODBUS messaging
structure.
7
Applicatio
Application
6
Préee
Préeentation
5
Session
4
3
2
Modbus
Transport
TCP
Network
Link
IP
CSMA / CD
ETHERNET V
1
Telecomm. Dept.
Faculty of EEE
2
o 802.3
r
Physical
DCN-2013
HCMUT
5
MODBUS
MODBUS PLUS is a higher speed network 1 Mbit/s
token passing derivative
that uses the MODBUS
messaging structure.
7
6
5
4
3
2
1
Telecomm. Dept.
Faculty of EEE
Applicatio
Application
Modbus
Presentation
Session
Transport
Network
Link
Physical
802.4 Token passing
RS485
DCN-2013
HCMUT
6
MODBUS ASCII and 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.
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
7
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
0x3A
Telecomm. Dept.
Faculty of EEE
Function
Data
Checksum
CR
0x0D
LF
0x0A
DCN-2013
HCMUT
8
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
Telecomm. Dept.
slave is responding.
Faculty of EEE
DCN-2013
HCMUT
9
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
Telecomm. Dept.
code with its most significant bit set to a logic 1.
Faculty of EEE
DCN-2013
HCMUT
10
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 an error occurs, the field
contains an exception code that
If no error occurs, the data field contains the data
the master application can
requested.
use to determine the next
action to be taken.
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
11
Data field
Address
Function
Data
Checksum
Valid codes are in the range of 0 ... 255 decimal.
Modbus RTU uses CRC :
Cyclic Redundancy 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
Telecomm. Dept.
response
to the master.
Faculty of EEE
DCN-2013
HCMUT
12
Frame example in RTU mode
Function code
= 03 : Read
Holding
2 bytes
2 bytes
Registers
Request :
1 byte
1 byte
Slave
Address
Function code =
03
First word
address
Number of words to
read
2 bytes
CRC16
Response :
1 byte
1 byte
Slave
Address
Function code =
03
Telecomm. Dept.
Faculty of EEE
2 bytes
Number of bytes
read
2 bytes
2 bytes
Value of the first
Value of the last
word
word
2 bytes
CRC16
DCN-2013
HCMUT
13
Frame example in RTU mode
Function code
= 06 : Write
Single
Register
Request
1 byte
1 byte
Slave
Address
Function code =
06
2 bytes
Word
2 bytes
Value of word
address
2 bytes
CRC16
Response:
1 byte
1 byte
Slave
Address
Function code =
06
Telecomm. Dept.
Faculty of EEE
2 bytes
Word
address
2 bytes
Value of word
2 bytes
CRC16
DCN-2013
HCMUT
14
Frame example in RTU mode
Function code = 16 (decimal) :
Write Multiple Registers
Request :
1 byte
1 byte
Slave
Address
Function code =
16
2 bytes
First word
address
2 bytes
Number of words to
1 byte
Number of bytes
write
2 bytes
Value of the first
word
2 bytes
CRC16
Response :
1 byte
Slave
Address
1 byte
Function code =
16
Telecomm. Dept.
Faculty of EEE
2 bytes
First word
address
2 bytes
Number of words to
2 bytes
CRC16
write
DCN-2013
HCMUT
15
Function Code Example
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
(0x06)
Write
Single Register Multiple Coils
(0x0F)
Write
Multiple Registers
(0x10)
Write
06
15
16
23
43
(0x17)
(0x2B)
Read/Write Multiple Registers
Read Device Identification
The complete description of all Modbus request is freely
the Modbus.org
Telecomm. Dept.
Faculty of EEE
web site
:
available on
DCN-2013
HCMUT
16
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
Telecomm. Dept.
Faculty of EEE
byte will be the address field of a new message.
DCN-2013
HCMUT
17
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
program to handle the error.
Telecomm. Dept.
Faculty of EEE
allow the master's
DCN-2013
HCMUT
18
RS485 physical layer
RS485 is the most common physical layer used
Modbus.
The RS485 standard allows variants
on
of different
characteristics :
polarization
line terminator
distribution of a reference
potential
number of slaves
length of the bus
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
19
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
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
20
MODBUS Protocol
Master polls slave for
communication by sending
Master
Slave
requests
Slave replies responses to
Master
the behaviors
Function code will define
of selected
slave
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
21
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
Method of accessing the
medium: Master slave
Max. no. of devices: with RS485 : 32 master included
Transmission method:
Messaging
120 words
Max. useful data size:
Transmission security:
LRC or CRC
Continuous stream
Start and stop delimiters
Telecomm. Dept.
Faculty of EEE
Parity
bit
DCN-2013
HCMUT
22
MODBUS TCP
The MODBUS continues to survive in automation
world more interested with interconnecting to
Ethernet networks and more specially, IP/Ethernet
networks
Using MODBUS TCP
and Client/Server
model for
communication
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
23
MODBUS TCP - Interconnection
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
24
MODBUS TCP Operation
A Request is sent by the client to initiate a transaction
An Indication is sent by the server to confirm that the request
was received
A Response is sent by the server to comply with the client
A Confirmation is sent by the client to acknowledge receipt of
request
response
Telecomm. Dept.
Faculty of EEE
DCN-2013
HCMUT
25