Professional Documents
Culture Documents
By KANADE D G
Introduction
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..
5
4 3
2 Link 1 Physical
Master - Slave
RS485
MODBUS TCP/IP
It uses TCP/IP and Ethernet 10 Mbit/s or 100 Mbits/s to carry the MODBUS messaging structure.
7 Application 6 Preentation 5 4 3 2 1 Session Transport Network Link Physical
TCP
IP Modbus
MODBUS PLUS
It is a higher speed network 1 Mbit/s token passing derivative that uses the MODBUS messaging structure.
7 Application 6 Presentation
Modbus
5
4 3
2 Link 1 Physical
Types of MODBUS
The MODBUS protocol comes in 2 versions
Coding System:
Hexadecimal, ASCII characters 09, AF One hexadecimal character contained in each ASCII character of the message
RTU 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 than ASCII for same baud rate.
Coding System:
8bit binary, hexadecimal 09, AF Two hexadecimal characters contained in each 8bit field of the message
Address
Function
Data
Checksum
silence
3A Hex
0D Hex
ASCII Framing
Messages start with a colon ( : ) character
(ASCII 3A hex)
For all other fields are hexadecimal 09, AF. Networked devices monitor the network bus continuously for the colon character. When one is received, each device decodes the next field (the address field) to find out if it is the addressed device.
Intervals of up to one second can elapse between characters within the message. If a greater interval occurs, the receiving device assumes an error has occurred.
RTU Framing
In RTU mode, messages start with a silent interval of at least 3.5 character times. The first field then transmitted is the device address. The allowable characters transmitted for all fields are hexadecimal 09, AF. Networked devices monitor continuously the silent intervals. Each device decodes first field after silent intervals to find out if it is the addressed device.
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).
Address Field(continued..)
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.
Function Field
Address Function Data Checksum
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.
Data Field
Address Function Data Checksum
Data Field(continued)
Address
Function
Data
Checksum
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.
Checksum Field
Address Function Data Checksum
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.
Response :
1 byte 1 byte 2 bytes 2 bytes 2 bytes 2 bytes
Slave Address
Function code = 06
Word address
Value of word
CRC16
Response :
1 byte 1 byte 2 bytes 2 bytes 2 bytes
Slave Address
Function code = 06
Word address
Value of word
CRC16
Code
Function
15 (0x0F)
16 (0x10) 23 (0x17) 43 (0x2B)
The complete description of all Modbus request is freely available on the Modbus.org web site :
http://www.modbus.org
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
Exception Responses
Except for broadcast messages, when a master device sends a query to a slave device it expects a normal response.
Exception Responses
One of four possible events can occur from the masters query:
Slave device receives the query without a communication error. -Normal response Slave does not receive the query due to a communication error.-No response Slave receive the query with a communication error.(Parity,LRC or CRC)-No response Slave receives the query without a communication error, but cannot handle it.-Exception response.
Exception Response
The exception response message has two fields that differentiate it from a normal response:
Function Code Field: In a normal response, the slave echoes the function code of the original query. In an exception response, the slave sets the MSB of the function code to 1.
All function codes have a mostsignificant bit (MSB) of 0
Data Field: In a normal response, the slave may return data. In an exception response, the slave returns an exception code in the data field.
Exception Handling
Byte 1 2 3 4 5 6 7 Byte 1 2 3 4 Contents Slave Address Function Starting Address Hi Starting Address Lo No. of Coils Hi No. of Coils Lo LRC Contents Slave Address Function Exception Code LRC Example 0A 01 04 A1 00 01 4F Example 0A 81 02 73
Exception Codes
Exception Code 01 02 03 04 05 06 07 08 Exception ILLEGAL FUNCTION ILLEGAL DATA ADDRESS ILLEGAL DATA VALUE SLAVE DEVICE FAILURE ACKNOWLEDGE SLAVE DEVICE BUSY NEGATIVE ACKNOWLEDGE MEMORY PARITY ERROR
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.
Polarisation Line terminator Distribution of a reference potential Number of slaves Length of the bus
Master
650
650
120 1 nF
D1
120 1 nF
D0 Common
Slave 1
Slave 2
Maximum length of Bus Max. no of stations (without repeater) Max. length of Tap Link Bus polarization Line terminator Common polarity
1000m at 19200 bps 32 (31 slaves) 20m for one tab link 40 m divided by no. taps 650 at 5V and common for the Master 120 -0,25Wm in series with 1nF,10V Yes common connected to PG
Master
4,7 K
4,7 K
4,7 K
4,7 K
Slave 1
Slave 2
Maximum length of Bus Max. no of stations (without repeater) Max. length of Tap Link Bus polarization Line terminator Common polarity
1000m at 19200 bps 28 (27 slaves) 20m for one tab link 40 m divided by no. taps 4.7k at 5V and common for the Master and slave 120 -0,25Wm in series with 1nF,10V Yes (0 VL)High impedance between 0VL and ground in each station
L-(B/B )
150 L+(A/A ) 150
Slave 1
Slave 2
Maximum length of Bus Max. no of stations (without repeater) Max. length of Tap Link Bus polarization Line terminator Common polarity
1300m at 19200 bps 32 (31 slaves) 3m 470 at 5V and common for the Master 150 No
Master
Rp
Rp
120 1 nF
D1 D0 Common 5V 4,7 K
120 1 nF
Slave 1
4,7 K
Slave 2
If the master is fitted with a 470 polarisation, it s possible to connect a maximum of 18 slaves with 4,7 K polarisation
Maximum length of Bus Max. no of stations (without repeater) Max. length of Tap Link Bus polarization Line terminator Common polarity
1000m at 19200 bps At most 32 (depending upon Rp and no.of 4.7k) 20m for one tab link 40 m divided by no. taps 470 at 5V and common for the Master 120 -0,25Wm in series with 1nF,10V Yes common connected to PG
Thank You