Using RS485 in the serial ports

I have been reading the documentation for the TI microprocessors and I
haven't been able to figure out if the serial ports can be used for
RS485. It seems to me that there is no integrated support for RS485
Transmit enable generation, has anybody tried this? You can always
control the enable with a digital output, but it is very difficult to
accurately disable the Transmit enable after transmission ends.
Microprocessors from other companies like the AT91SAM9260 and LPC1768
directly support handling the RS485 enable.

Yes, You will need a direction pin, such as RTS, to switch the direction on the transecier. It is all serial data. TX and RX to the driver.

Gerald

2011/11/2 Iñaki Zuloaga Izaguirre <inakizi@gmail.com>

Yes you can use the serial ports for RS485. You will need a UART to RS485 IC to get the correct voltages. RS485 is a half duplex standard and therefore has to have a directional pin. This pin can be selected to be any of the GPIO pins of the Beaglebone Black. Use the UART cape in the device tree overly to enable the serial port and then pass the RS485 stucture along with the termios information to setup the port. The structure can be found in serial.h. If you are planning to use the Modbus protocol over the RS485 network then you need to make a slight change to the libmodbus source code. In the file modbus-rtu.c there is a function called modbus_rtu_set_serial_mode. In the passing argument for the function include an additional variable int GPIO for the directional pin. In the firs if statement change the code so that it will now pass the structure of the RS485 to the port along with the directional pin. Note that you are using the patched serial.h that comes with the Debian Image for the Beaglebone Black and not the serial.h that comes as standard with Debian. After this setup the normal reading and writing functions of the Modbus library can be used

For your information, there is also a RS485 Cap that is working very well . As he said : " pass the RS485 stucture along with the termios information to setup the port "

Hello,
I’m trying to set-up TxEnable (other gpio for RTS) in rs485 of my custom cape with Device Tree from weeks: all works fine, except RTS!
I use 14_04_2014 Debian image and libmodbus 3.1.1 .
can you explain me better what I have to do?
I haven’t find a complete guide for how to set-up rs485 pin (not uart physical line!) in Device tree, only suggestion…
I’m not sure that my kernel (3.8.47) supports RS485 controls pin…

I haven’t understand how modify modbus_rtu_set_serial_mode function. Finally: must I set my custom RTS pin in device tree structure (half unknown) or in modbus_rtu_set_serial_mode function? or both?

I am sure that it was not clear… but if Yuo or someone can help me… I’m very grateful!!!

Thanks in advance!

Francesco.

Sorry for taking so long to come back but was a bit busy. It looks like the RS 485 patch is not included in the standard Debian release for the Beaglebone Black (with all the other patches that is included). So if you are using Debian on the Beaglebone Black you have to apply the RS 485 patch of Mickae1 manually before compiling else you could replace /kernel/drivers/tty/serial/omap-serial.c with the code at the end and also replace /kernel/uapi/linux/serial.h with the code at the end and recompile. Then just pass the structure as discussed above. Make these changes before applying the additional patches for the Debian image.

omap-serial.c

/*

  • Driver for OMAP-UART controller.

  • Based on drivers/serial/8250.c

So what exactly are we missing for RS 485 support?

https://github.com/RobertCNelson/bb-kernel/blob/am33x-v3.8/patch.sh#L866

https://github.com/RobertCNelson/bb-kernel/blob/am33x-v3.8/patches/fixes/0007-omap-RS485-support-by-Michael-Musset.patch

Regards,

Robert … It works perfectly your Debian Image with the RS485 … I don’t understand what is the problem … .

Regards,

Hi Robert

I agree with Mickae1 because I have several Debian Images that work perfectly but some of the the RS485 structure in serial.h never gets changed will applying patch.sh. It says that 0007-omap-RS485-support-by-Michael-Musset.patch is applied but later when I pass the structure in code it gives an error in regards to the the directional pin that is not defined or something another which leads me back to serial.h which is missing the patched RS 485 structure. Just found in those cases to manually edit omap-serial.c and serial.h which resolves this problem.

Love your work and do learn something new every day.

Regards

Hi,
Im having the same issue getting the RS-485 working on the latest debian 4.2.4 bone2 Beagle Bone Black build. Is there a header file to include with this source code? and is this source code complete?
Thanks