I need to implement Modbus messages reception over UART. For RTU it's easy because UART on my uC has configurable idle receive line detection. However, for ASCII the task is tricky - the delimiter is based only on characters, then I'm not sure if timeout detection is enough - is it possible that two messages would come one just after another without any break? How is it implemented usually? This far my approach was to set timeout to 1.5 char and then use some counter for maximum 1s intercharacter delays and in every timeout event to check if the delimiter is there at the last 2 bytes of receive buffer. Unfortunately, it's late to change the uC.
Asked
Active
Viewed 49 times
0
-
Which MCU you are using and how are you receiving the data? Just to be sure, your MCU needs to be the ModBUS controller or the device? Why not receive the data so that you know how much data there should be and if it has been received properly? – Justme Mar 14 '23 at 16:17
-
Zynq 7000, should be able to be both master and slave. I'm receiving RTU data by waiting for rx idle line timeout configured to 4 character times. The key is that incoming message length is not known in advance. – asiemasz Mar 14 '23 at 16:26
-
2In the ASCII mode, the frame starts and ends with specific characters. Surely the Zynq which is a super fast ARM with programmable logic can do such a simple task? And the time between messages is mandated by the specs. Do you need to receive anything outside the specs? – Justme Mar 14 '23 at 16:34
1 Answers
0
ASCII Modbus is delimited with :
for start-of-frame and CRLF for end-of-frame. There's no need to do idle time detection at all.
In fact, the whole point of ASCII Modbus was to make it easy to receive on MCUs where idle time detection was a hassle.
Your MCU is so powerful that dealing with any Modbus format will not be a slightest problem.

Kuba hasn't forgotten Monica
- 32,734
- 1
- 38
- 103
-
Yes, but it's not the only MCU task and I guess that causing interrupts every single byte on a fast baudrate to check for delimiters would not be good for performance. – asiemasz Mar 14 '23 at 18:19
-
1@asiemasz Then don't do it like that. Doesn't the MCU support DMA? And what does "fast" even mean? – Justme Mar 14 '23 at 18:28