Link here

Understanding Serial Communications

Configuring baud rates and data format for RS232 RS422 and multi-drop RS485 protocols

A UART is a Universal Asynchronous Receiver/Transmitter that converts parallel data from the host processor (any Mosaic controller) into a serial data stream. Each of the two UARTs on the wildcard is capable of full-duplex communications, meaning that both transmission and reception can occur simultaneously (although the RS485 protocol is half duplex as explained below). In other words, each local UART on the wildcard can both send data to and receive data from a remote UART on the other end of a connecting serial cable. The local and remote must share a common ground, so all serial cables include at least one ground conductor.

The words port and channel are used interchangeably to refer to a serial communications link. The UART Wildcard provides two simultaneous communications links, each configurable as RS232, RS485 or RS422.

 

Baud Rate

The serial interface is asynchronous, meaning that there is no clock transmitted along with the data. Rather, the transmitter and receiver must be communicating using a known baud rate, or bit frequency. Both the local and remote UARTs must be configured for the same baud rate. Software-selectable baud rates up to 56,000 baud are supported.

You can use the driver function Set_Baud to specify the baud rate. The actual baud rate produced differs from that requested by a small error owing to rounding of an internal divisor. The baud rate produced is,

Baudactual = 500000 / Round(500000/Bauddesired)

where Bauddesired is an unsigned integer from 1 to 56000, 500000 is the frequency of the UART's internal clock and Round(500000/Bauddesired) is an internal divisor (rounded to the nearest integer). So long as the error between the actual baud rate and that specified is less than 1.5% (or the error between transmitter and receiver is less than 3%) there should be no communication errors.

Baud rates up to 56,000 baud are supported. There are different sets of standard baud rates in use depending on the application. Modem to phone line communications use rates of 110, 150, 300, 600, 1200, 2400, 3000, and 3200 baud. Modem to modem lines often use 1200, 4800, 9600, 14400, 28800, 33600, and 56000 baud. Port to modem communications usually use 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600 and 115200 baud.

Of these baud rates in common use, the UART Wildcard can produce the following at high accuracy:

Programming Common Baud Rates
Specified Baud Divisor Actual Baud Error (%)
110 4545 110 0.01
150 3333 150 0.01
300 1667 300 -0.02
600 833 600 0.04
1200 417 1199 -0.08
2400 208 2404 0.16
3000 167 2994 -0.20
3200 156 3205 0.16
4800 104 4808 0.16
9600 52 9615 0.16
14400 35 14286 -0.79
19200 26 19231 0.16
33600 15 33333 -0.79
38400 13 38462 0.16
56000 9 55556 -0.79

Both the local and remote UARTs must be configured for the same baud rate. You may use nonstandard baud rates if both devices support them. The UART Wildcard supports any baud rate produced by the above formula.

 

Data Format

Serial data is shifted out least-significant-bit first. At the UART, a logic high (5 volts) is called a mark, and a logic low (0 volts) is called a space. The serial output at the UART idles at the logic high (mark) level. A logic-low start bit marks the start of a character, followed by 5 to 8 data bits per character. An optional parity bit can be specified to enable error detection by the UART. One to two logic-high stop bits mark the end of a character.

Parity options include even, odd, high, low, or no parity. Even parity means that the bits sum to an even number, and odd parity means that the bits sum to an odd number. High (mark) parity means that the parity bit is always logic 1 at the UART, and low (space) parity means that the parity bit is always logic 0 at the UART. No parity means that there is no parity bit.

A break sequence forces the serial output to a logic low (space) at the UART.

Both the local and remote UARTs must be configured for the same communications parameters.

The standard data format for Mosaic's controllers uses 8 data bits, no parity, and 1 stop bit.
 

FIFOs

Each UART implements transmit and receive FIFO buffers to reduce the required frequency of service by the host processor. A FIFO is a First In/First Out buffer that can queue a burst of outgoing characters for transmission, or save a set of incoming characters until the host can read them. Each of the two channels on the UART Wildcard implements two 16-character FIFOs, one for outgoing characters and one for incoming characters.

 

Serial Driver Chips

The serial data stream at the UART is conditioned by serial driver chips that transmit and receive the data. The resulting signal levels on the interface cable connect the local and remote in a manner specified by a standard protocol. The most widely used protocol is RS232, a full duplex protocol with a single-ended bipolar voltage swing on the serial cable. Newer protocols include the full duplex RS422 and the half duplex RS485 protocols, each of which drives differential 0 to 5 volt signals on the serial cable.

Each of the two channels on the UART Wildcard can be configured for RS232, RS422, or RS485. The protocols are described in turn.

 

RS232

Each RS232 driver uses inverting logic and implements a single-ended bipolar output voltage (that is, one signal that swings above and below ground). A logic high at the UART is converted by the RS232 output driver to a voltage between –7 and –12 volts, while a logic low at the UART is converted to a voltage between +7 and +12 volts. The RS232 receiver accepts signals in the range –12 to +12 volts and outputs logic level (0 or 5 volt) signals to the UART circuitry. The RS232 driver and receiver use separate conductors on the serial cables, enabling full duplex communications. Note that the local and the remote must share a common ground, so a minimum of 3 wires are required for full duplex RS232 communications: a transmit wire, a receive wire, and a common ground.

As of the time of this writing, more detailed information about the RS232 protocol is available at http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html.

 

Optional RS232 Modem Interface

A modem (modulator/demodulator) provides a way of encoding digital data as a set of audio signals that can be sent over a telephone line. Most modems communicate using RS232 and a set of hardware handshaking signals used to regulate data flow. The UART Wildcard implements these optional RS232 modem handshaking signals on channel 1. The handshaking signals can be disabled and/or ignored by applications that do not need them.

Owing to hardware constraints, if modem handshaking is needed on UART channel 1, then channel 1 must be configured for RS232, and channel 2 cannot be configured for RS232 communications. These factors are discussed in more detail in The UART Wildcard: Modem Handshaking Signals.

 

RS422

Each RS422 driver transmits a differential pair of output signals at 0 and 5 volts. The RS422 receiver converts the differential signal to the 0 to 5 volt logic signal required by the UART circuitry. Because differential signals have inherently better signal-to-noise properties, reliable RS422 communications can be sent over much longer distances compared to RS232. The RS422 driver and receiver use separate differential conductor pairs on the serial cables, enabling full duplex communications. Note that the local and the remote must share a common ground, so a minimum of 5 wires are required for full duplex RS422 communications: two transmit wires, two receive wires, and a common ground.

 

RS485

RS485 is a half duplex version of RS422 that is capable of multi-drop operation. RS485 uses the same differential signaling scheme as RS422, and hence has the same superior signal-to-noise characteristics and range described above. In fact, a single driver chip on the UART Wildcard is used to implement both RS422 and RS485 communications for a given serial channel. In RS485 mode, the RS422 transmit and receive pairs are shorted together with a pair of onboard jumpers as explained in the UART Wildcard Hardware: RS485 Jumpers section below. Note that the local and the remote must share a common ground, so a minimum of 3 wires are required for half duplex RS485 communications: a pair of transceive wires and a common ground.

 

Multi-drop RS485

Because a single pair of conductors is used for both transmission and reception, RS485 is useful for multi-drop applications in which a master communicates with multiple slave serial devices, or nodes.

To avoid contention on the RS485 bus, the application software must assure that only one transmitter is enabled at a time. The master is in charge of designating which receiver is on at any one time. In the simplest scheme, all RS485 transceivers come up in receive mode when the interface is initialized, and each transceiver node has a unique address known to it and the master. A single master can broadcast commands to all the slaves, and can direct commands to an individual slave using its unique address. The master can instruct a single slave to go into transmit mode, and then the master can put itself into receive mode, thereby allowing the master to retrieve data from the slave. After the slave transmission is complete, the slave puts itself back into receive mode so that the master can transmit additional commands. In this manner, data can be exchanged between the master and each slave on the bus.

Care must be taken when changing an RS485 node from transmit mode to receive mode, or visa versa. Characters may be lost if the transmit driver is turned off while pending characters are still being transmitted. To avoid this problem, the software function named RS485_Rcv_When_Xmit_Done that establishes the RS485 receive mode is coded such that it waits until all queued (pending) characters have been transmitted before the driver chip is taken out of transmit mode. Similarly, when establishing the transmit mode, the application software is responsible for ensuring that the RS485 receiver is not disabled until all expected characters have been received.

 
This page is about: Understanding UART Configuration for RS232, Full-duplex RS422, and Multi-drop RS485 Serial Communications Protocols – Configuring UART baud rates and data format for RS232, full-duplex RS422 and multi-drop RS485 serial communication protocols on the UART Wildcard - Mosaic Industries, Inc.
 
 
Navigation