Friday, December 2, 2016

Modbus Protocol part 2

In this post I will try to describe about master/slave configuration, Serial interface, Query-response cycle and transmission modes in the Modbus protocol.

What is master/slave technique?
There is only one device (master) which is requesting information and there can be many devices (Modbus slaves) that can supply requested information. In standard Modbus protocol there is a master and up to 247 slave device. Also master device can send information to slave devices. Each slave device has unique address from 1 to 247.

Examples for master and slaves
·         Master devices-Monitoring panels, servers
·         Slave devices-Mainly PLCs, VSDs


As I told earlier Modbus protocol defines structure of messages transmitting between master and slaves. The message send by master to any slave is called query and the message send by slave to master is called response.

A-What kind of action should be performed by the slave device
B-Any additional data needed to perform the function
C-To validate message contents
D- What kind of action should be performed by the slave device? If any error occurred the    function code of that error will be sent
E-Collected data
F- To validate message contents.

Transmission modes
We know that queries and responses are transmitting serially. But how does information pack in those messages and how to decode them???

There are two serial transmission modes
1.      ASCII mode
2.      RTU(Remote Terminal Unit) mode

ASCII mode
Before talking about this it is helpful to know about Modbus message framing. Above both transmitting modes Modbus message is framed. In this frame the beginning point and ending points are known. This frame has 8 bits.

Now let’s move into ASCII...We know that ASCII characters are represented by Hexadecimal Numbers. It is clear that 8 bits can represent 2 hexadecimal numbers. So There are two ASCII characters in one message. In this ASCIII transmission mode the time delay between there ASCII characters can be take time up to 1 second. That is main advantage of this method. If a greater interval occurs, the receiving device assumes an error has occurred.

Coding System: Hexadecimal, ASCII characters 0–9, A–F
One hexadecimal character contained in each
ASCII character of the message
Bits per Byte: 1 start bit
7 data bits, least significant bit sent first
1 bit for even/odd parity; no bit for no parity
1 stop bit if parity is used; 2 bits if no parity
Error Check Field: Longitudinal Redundancy Check (LRC)  *This will be discussed later.

In ASCII mode, messages start with a ‘colon’ ( : ) character (ASCII 3A hex), and
End with a ‘carriage return – line feed’ (CRLF) pair (ASCII 0D and 0A hex).




RTU Mode
Each 8 bit byte in a message contains two 4 bit hexadecimal characters.

Coding System: 8–bit binary, hexadecimal 0–9, A–F
Two hexadecimal characters contained in each
8–bit field of the message
Bits per Byte: 1 start bit
8 data bits, least significant bit sent first
1 bit for even/odd parity; no bit for no parity
1 stop bit if parity is used; 2 bits if no parity
Error Check Field: Cyclical Redundancy Check (CRC) *This will be discussed later

Let’s move into RTU framing
In RTU mode messages start with a silent interval of at least 3.5 character time. The entire message is transmitted in continuous stream. The figure shows the RTU frame. One frame should transmit without having time interval of less than or equal  1.5 character time between each fields(slave address, data Error check, Function code).If this condition is not satisfied received data will be discarded.

Important – It can be seen that in RTU mode there no dedicated bits to indicate start and end of a message. That is indicated by using specific time interval (3.5 character time).Therefore RTU mode has greater character density and hence has more data throughput.

The fields in a Modbus message will be discussed in next post.



2 comments:

  1. Nice post... I read your blog posts on Modbus protocol. You shared complete information on Modbus protocol. Very useful content. Thanks for sharing.

    ReplyDelete