RS-485 flow control for Modbus RTU

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
uCTRL
Posts: 47
Joined: Fri Oct 12, 2018 11:50 pm

RS-485 flow control for Modbus RTU

Post by uCTRL » Sat Nov 24, 2018 7:34 am

Had a look at couple of other topics that have touched on the subject but there appears to be no solution to micropython implementation.

Modbus RTU with RS-485 interface is a half duplex serial uart based protocol and is widely used in the industrial remote control and sensing applications.

Important aspect that needs to be implemented ideally in the micropython firmware is:

1. Hardware flow control pin for the RS-485 transceiver.
2. End of transmission (TX buffer empty) interrupt, before the flow control pin can change from Transmit to Receive mode.

I guess it would be possible to perform a timing calculation and estimate when the TX buffer
should be
empty based on baudrate and buffer length, but it would be inefficient.
Ideally it should be done using hardware UART TX interrupt.

I would like to hear if anyone has found a solution, particularly for the pyboard.

Not sure if there is any further new development happening at the current pyboard level, but the UART class would benefit with the inclusion of RS-485 support as well as callbacks for RX and TX.

I see that Pycom have implemented Modbus RTU for their micropython ESP32 modules.

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: RS-485 flow control for Modbus RTU

Post by chrismas9 » Sun Nov 25, 2018 6:52 am

What is your target MCU? The STM32L4 series (L476, etc) have built in Driver Enable mode for the RTS pin. It's not supported in MicroPython but you could probably enable it with direct MCU register access.

Post Reply