Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Modbus RTU

Not open for further replies.


Full Member level 1
Apr 7, 2017
Reaction score
Trophy points
Activity points
Hello All,

In Modbus RTU mode, messages start with a silent interval of at least 3.5 character times.
I want to make it ( idle mode in interval of 3.5 character times ) using uart of PIC microcontroller.
How Master/Slave recognizes the silent interval when the stream of data receives to RX ?
How can i make a logic for the same in MPLAB X IDE ?



On any UART transfer the last bit should be the STOP bit ("0").
So you can (re)start a timer on every "0" ... with a timeout of 3.5 charater times. (Probably my choice).

Other SW option:
If you use a UART_receive_ISR then you might trigger the timer here.

Or you can build a retrtiggerable monoflop (hardware), to trigger an interrupt.

All these options will trigger an interrupt after the 3.5 characters idle time.

But I think the 3.5 character times does not have to be exact 3.5 character times but >=3.5ct.
If so, you don´t need an 3.5ct interrupt, but simply a "clear to send flag".
Then, just before sending a new message you have to poll and "wait for the cts flag".

Depending on the microcontroller .. it may have supporting hardware for this.
I´ve used this feature on an STM32F10x


Actually, the MODBUS interoperability lab tests for an RTU interframe gap of 3.5 character's' duration at 19200 bps and below, but at 38Kbps and above they only need ~ 1.75milliseconds (I use 2 milliseconds). This is what I have implemented in shipping product and it has passed MODBUS-compliance lab certification with these recommendations, worked through gateways, etc..

What I found to be the simplest code implementation, was to simply run a 1 millisecond free-running timer interrupt (you could choose 2 millisecond on really constrained MCU) that increments a tick count.. Then, in your code where you process a received MB-RTU msg frame to see if it is for you or not, you just grab the tick count when you determine the msg is valid for you. When you have a response ready in queue to send, just grab the current value of the tick counter and compare/subtract the tick count from the "msg is for me" tick count. If the difference is >= the required number of millisecond ticks then your code starts the transmission of the response. Just be sure to handle the rollover of the tick count properly in your checking.

MODBUS has two idle specifications, t1.5 and t3.5. Messages must be transmitted continuously with not more than t1.5 inter-character space. Between messages, at least t3.5 idle time must be kept.

Respectively a receiver checks for > t1.5 gaps to reset the state machine to idle state. The actual detection threshold would be set somewhere between t1.5 and t3.5.

Not open for further replies.

Part and Inventory Search

Welcome to