0
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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? \$\endgroup\$
    – Justme
    Mar 14, 2023 at 16:17
  • \$\begingroup\$ 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. \$\endgroup\$
    – asiemasz
    Mar 14, 2023 at 16:26
  • 2
    \$\begingroup\$ In 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? \$\endgroup\$
    – Justme
    Mar 14, 2023 at 16:34

1 Answer 1

0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – asiemasz
    Mar 14, 2023 at 18:19
  • 1
    \$\begingroup\$ @asiemasz Then don't do it like that. Doesn't the MCU support DMA? And what does "fast" even mean? \$\endgroup\$
    – Justme
    Mar 14, 2023 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.