CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Modbus 3,5 byte length at beginning and end of ADU

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lisek_lichu



Joined: 27 Aug 2012
Posts: 23

View user's profile Send private message

Modbus 3,5 byte length at beginning and end of ADU
PostPosted: Mon Sep 02, 2013 11:19 am     Reply with quote

Hello,

Can somebody explain me how we handle receiving this 3,5 length at front of ADU and at end of ADU?

if master sends request, at the beginning minimum 3,5 Tz should be sent, so how we handle receiving this by slave?

In RDA interrupt first byte we receive is used as address to which slave message is sent so where we receive or calculate 3,5Tz?

Or this time is only logical 1 instead of zero?

thanks for help
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Sep 02, 2013 12:29 pm     Reply with quote

t3.5 is a required idle time between meassages. A slave should observe it in two regards;
- keep the idle time before answering to a master's request
- reset the receive state machine if a pause of more than 1.5 character time is detected in received data

The CCS provided MODBUS example code implements both requirements by a timer.
lisek_lichu



Joined: 27 Aug 2012
Posts: 23

View user's profile Send private message

PostPosted: Mon Sep 02, 2013 1:05 pm     Reply with quote

hi,

thanks for answer. I see that during this 3,5Tz nothing is received by slave because line is in logic one during this time.

But how we handle this:
Quote:
reset the receive state machine if a pause of more than 1.5 character time is detected in received data

?

What i see is that in init() we set up timer 2 to 20ms. In timer2 interrupt routine at the end it turns off itself by "modbus_enable_timeout(FALSE);"

Then in RDA interrupt after we receive first byte of data, at the end we enable timer2 with "modbus_enable_timeout(TRUE);" so 20ms starts to count.

But baudrate is set to 9600bits/s so it means that one bit of data takes about 104us so whole byte takes about 832us + stopbit +max1,5Tz so why we count 20ms and why it set permanently to 20ms regardless baudrate?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Sep 03, 2013 12:56 am     Reply with quote

Apparently the 1.5 character frame timeout isn't correctly implemented in some modbus.c versions.
Ttelmah



Joined: 11 Mar 2010
Posts: 19395

View user's profile Send private message

PostPosted: Tue Sep 03, 2013 1:54 am     Reply with quote

Two things. First, 'Modbus over serial' doesn't have it....
On this format, the time-out's are left much more 'open'. Up to several seconds!....

Then the problem is that the driver supports modbus over serial, and modbus RTU. RTU, is meant to have the <3.5 character time assumption, to ensure the state machine restarts in the 3.5 character gap. Then there is also meant to be a 'message timeout' beyond this (which would need to be added by the user resetting the interface if a message has not been received after several seconds).

The 'official' RTU spec on this timeout, is one of the most 'ignored' parts of modbus, because it has to be... You have the problem that the modems etc., may introduce pauses. The comment made by Lantronix in their user guide, 'says it all':

"Character Timeout (10-7050 msec)
This sets the timeout between characters received. Official Modbus/RTU
defines a 3.5 character time-out, but complex devices have various
interrupts that can cause 5 to 10 character “pauses” during transmission.
A safe value for general use with Modbus is 50 msec. Note: Setting this
value lower than 50 msec will not improve performance and may even
make performance worse."

So their 'timeout', won't even go down to the 3.5 character time value, let alone 1.5 character times!. This is the way CCS have implemented things as well.

The only times I've had to 'tweak' the CCS implementation, in this regard, when using it, to receive from other kit, has been to increase the timeout over some links.

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Sep 03, 2013 4:59 am     Reply with quote

The official MODBUS is clear in this regard, I think.

MODBUS RTU format specification in "Modbus_over_serial_line_V1_02"
Quote:
The entire message frame must be transmitted as a continuous stream of characters.

If a silent interval of more than 1.5 character times occurs between two characters, the message frame is declared incomplete and should be discarded by the receiver.


MODBUS ASCII allows up to 1 sec pauses within a message.
Ttelmah



Joined: 11 Mar 2010
Posts: 19395

View user's profile Send private message

PostPosted: Tue Sep 03, 2013 7:16 am     Reply with quote

Totally agreed.
However it doesn't work, and every unit I have used with Modbus RTU, has extended it, or allows you to extend it.
The problem is that it only works if you are using modbus RTU over a direct wire link. Few process control application actually have this being the case....
As I said, it is one of the most 'ignored' parts of modbus.

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Sep 03, 2013 12:34 pm     Reply with quote

I see the problem. The idea of t1.5 is to allow a safe recover from transmission faults and resynchronization
to next message start. If you increase the timeout above t3.5 (or the actual inter-message delay) recover
may take long on a busy bus.

A number of fieldbusses involve real-time requirements for the serial interfaces. MODBUS isn't the worst
in this regard.
Ttelmah



Joined: 11 Mar 2010
Posts: 19395

View user's profile Send private message

PostPosted: Tue Sep 03, 2013 1:03 pm     Reply with quote

Very much The Truth....

The only reason I met this, was quite a while ago, I wrote my own Modbus RTU slave on the PIC, and was 'scrupulous' to follow the timings. Worked fine in the lab, but on over 90% of real systems, it gave problems. Ended up having to extend the timeout.
The 'solution', was to only use timeout for long breaks. Instead look at the data stream, and if the packet is unrecognised, switch to a 'search' mode and look for the start of packet.

Best Wishes
lisek_lichu



Joined: 27 Aug 2012
Posts: 23

View user's profile Send private message

PostPosted: Wed Sep 04, 2013 1:30 pm     Reply with quote

Ok thanks a lot for answers,

In my system everybody uses exactly Modbus_over_serial_line_V1_02 spec so i will try to do it like it is described in this document.

Quote:
I see the problem. The idea of t1.5 is to allow a safe recover from transmission faults and resynchronization to next message start. If you increase the timeout above t3.5 (or the actual inter-message delay) recover may take long on a busy bus.


Here I don't understand it clearly. You are saying about t1.5 and t3.5 like it was the same thing or my English is not so good and I don't get it Smile? In specification it is written that time between each BYTE in one message can not be longer than 1,5 byte time but more than 3,5 byte time is needed only at the beginning of whole ADU and at the end of ADU.

as it is written in "2.5.1.1 MODBUS Message RTU Framing" chapter fo this document.

"In RTU mode, message frames are separated by a silent interval of at least 3.5 character times." and "The entire message frame must be transmitted as a continuous stream of characters. If a silent interval of more than 1.5 character times occurs between two characters, the message frame is declared incomplete and should be discarded by the receiver. "

Quote:
Totally agreed.
However it doesn't work, and every unit I have used with Modbus RTU, has extended it,


So You are saying that normally when You use modbus implementation to communicate with other devices You increase time between two BYTES in message more than 1,5byte time?
Ttelmah



Joined: 11 Mar 2010
Posts: 19395

View user's profile Send private message

PostPosted: Thu Sep 05, 2013 12:51 am     Reply with quote

No.

The simple 'time' criterion for a packet failure has to be extended.
Instead use a data criterion, based upon:
1) data arriving that is incorrect.
2) framing error on the bytes.

The simple 1.5 byte time timeout, only works successfully with direct wire links over short runs. As soon as data goes 'through' another transport medium (modem, packeted over ethernet etc.), the medium starts introducing time delays that can incorrectly trigger the simple timeout.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group