Project

General

Profile

Driving RS-485 transceivers

This page describes how you can use the MitySOM-335X modules to drive RS-485 half duplex or multidrop interfaces using a UART and a GPIO pin as the transmit enable line.

Critical Link has implemented a kernel modification (two patches, patch 1, and patch 2) that provide a low latency control of a GPIO (or RTS) pin coincident with the AM-3359 UART peripheral.

The figure below illustrates a simple connection diagram for a half duplex RS-485 transceiver. The MitySOM-3359 development kit with RS-485 expansion board can be used for assessment of system performance with either UART expansion port.

The figures below illustrate the transmit enable signal with respect to the completion of a 115200 BAUD transmit waveform. A transmit pattern of all "0s" was used to highlight the stop bit, which is a logic '1' on the scope trace. From the second figure, the transmit enable line is dropped less than 5 usecs from the last stop bit transmitted on the interface.

The application level code makes use of a recently defined linux serial IOCTL code, TIOCRS485.

From the patch, the structure that must be passed to the driver is of the form:

struct serial_rs485 {
        __u32   flags;                  /* RS485 feature flags */
#define SER_RS485_ENABLED               (1 << 0)
#define SER_RS485_RTS_ON_SEND           (1 << 1)
#define SER_RS485_RTS_AFTER_SEND        (1 << 2)
#define SER_RS485_RTS_BEFORE_SEND       (1 << 3)
#define SER_RS485_USE_GPIO              (1 << 5)
        __u32   delay_rts_before_send;  /* Milliseconds */
        __u32   delay_rts_after_send;   /* Milliseconds */
        __u32   gpio_pin;               /* GPIO Pin Index */
        __u32   padding[4];             /* Memory is cheap */
};

This structure is part of the include/linux/serial.h file in the kernel tree. This header is often included as part of the linux cross-tools headers. You must ensure that the cross compiler header file is consistent with this structure or redefine the structure in your application. In the TI software SDKs, this header is distributed under ${SDK}/linux-devkit/arm-arago-linux-gnueabi/usr/include/linux/serial.h. As of version 5.3.02 of the TI SDK, this file was rather old. The example files below account for this difference with the #define SER_RS485_USE_GPIO compile switch.

  /* new defines in linux/serial.h of CL provided kernel */
  #ifndef SER_RS485_USE_GPIO
  #define SER_RS485_USE_GPIO (1<<5)
  #define gpio_pin padding[1]
  #endif

This code was tested using a MitySOM-3359 development kit and 2 RS-485 adapter. One adapter was connected to each of the UART expansion ports and the RS-485 lines were looped back to each other. The send.c and recv.c programs in the rs485_test.tar file generated some test patterns to loop back a simple message. An oscilloscope was used to measure the TX enable lines with respect to the transmit and receive waveforms.

Go to top
Add picture from clipboard (Maximum size: 1 GB)