Serial Communication Overview

Publish Date: Mar 23, 2012 | 465 Ratings | 3.60 out of 5 |  PDF

Table of Contents

  1. What Is Serial?
  2. EIA-232 Overview
  3. EIA-422 Overview
  4. EIA-485 Overview
  5. Pinouts for NI Serial Interface Connectors
  6. What Is Handshaking?

1. What Is Serial?

Serial is a device communication protocol that is standard on almost every PC. Do not confuse it with universal serial bus (USB). Most computers include two EIA-232 based serial ports. Serial is also a common communication protocol for instrumentation in many devices, and numerous GPIB-compatible devices come with an EIA-232 port. Furthermore, you can use serial communication for data acquisition in conjunction with a remote sampling device. Note that EIA-232 and EIA-485/422 may also be referred to as RS-232 and RS-485/422.

The concept of serial communication is simple. The serial port sends and receives bytes of information one bit at a time. Although this is slower than parallel communication, which allows the transmission of an entire byte at once, it is simpler and you can use it over longer distances. For example, the IEEE 488 specifications for parallel communication state that the cabling between equipment can be no more than 20m (65ft) total, with no more than 2m (6.5ft) between any two devices; serial, however, can extend as much as 1200m (4000ft).

Typically, engineers use serial to transmit ASCII data. They complete communication using three transmission lines -- ground, transmit, and receive. Because serial is asynchronous, the port can transmit data on one line while receiving data on another. Other lines are available for handshaking but are not required. The important serial characteristics are baud rate, data bits, stop bits, and parity. For two ports to communicate, these parameters must match:

  1. Baud rate is a speed measurement for communication that indicates the number of bit transfers per second. For example, 300 baud is 300 bits per second. When engineers refer to a clock cycle, they mean the baud rate, so if the protocol calls for a 4800 baud rate, the clock is running at 4800 Hz. This means that the serial port is sampling the data line at 4800 Hz. Common baud rates for telephone lines are 14400, 28800, and 33600. Baud rates greater than these are possible, but these rates reduce the distance by which engineers can separate devices. They use these high baud rates for device communication where the devices are located together, as is typically the case with GPIB devices.
  2. Data bits are a measurement of the actual data bits in a transmission. When the computer sends a frame of information, the amount of actual data may not be a full 8 bits. Standard values for frames are 5, 7, and 8 bits. Which setting you choose depends on what information you are transferring. For example, standard ASCII has values from 0 to 127 (7 bits). Extended ASCII uses 0 to 255 (8 bits). If the data you are transferring is standard ASCII, sending 7 bits of data per frame is sufficient for communication. A frame refers to a single byte transfer, including start/stop bits, data bits, and parity. Because the number of actual bits depends on the protocol selected, you can use the term "frame" to cover all instances.
  3. Stop bits are used to signal the end of communication for a single frame. Typical values are 1, 1.5, and 2 bits. Because the data is clocked across the lines and each device has its own clock, it is possible for the two devices to become slightly out of sync. Therefore, the stop bits not only indicate the end of transmission but also give the computers some room for error in the clock speeds. The more bits used for stop bits, the greater the lenience in synchronizing the different clocks, but the slower the data transmission rate.
  4. Parity is a simple form of error checking used in serial communication. There are four types of parity -- even, odd, marked, and spaced. You also can use no parity. For even and odd parity, the serial port sets the parity bit (the last bit after the data bits) to a value to ensure that the transmission has an even or odd number of logic-high bits. For example, if the data is 011, for even parity, the parity bit is 0 to keep the number of logic-high bits even. If the parity is odd, the parity bit is 1, resulting in 3 logic-high bits. Marked and spaced parity does not actually check the data bits but simply sets the parity bit high for marked parity or low for spaced parity. This allows the receiving device to know the state of a bit so the device can determine if noise is corrupting the data or if the transmitting and receiving device clocks are out of sync.

Back to Top

2. EIA-232 Overview

EIA-232 is the serial connection found on IBM-compatible PCs. Engineers use it for many purposes, such as connecting computers to sensors and modems, or for instrument control. EIA-232 hardware permits communication at distances up to 15m (50ft). EIA-232 is limited to point-to-point connections between PC serial ports and devices. For this reason, it is common to require additional EIA-232 serial ports for your computer. Standard PC EIA-232 serial ports and many serial interface providers leverage the Win32 API for serial communication function calls. The Win32 API was originally designed for modem communication and does not implement the entire EIA-232 protocol.  Due to this limitation, the Win32 API cannot communicate with some devices.

National Instruments offers EIA-232 serial interfaces on a variety of platforms, including PCI, PCIe, USB, PCMCIA, ExpressCard, PXI, PXIe, and Ethernet. Depending on the platform, NI Serial interfaces are available in 1, 2, 4, 8, and 16 port versions. In addition, NI EIA-232 serial interfaces offer increased functionality, such as high-speed baud rates up to 1 Mb/s, minimal CPU usage through DMA transfers, optional 2000 V port-to-port isolation, and configurable nonstandard baud rates. All National Instrument Serial interfaces include NI-Serial driver software, which implements the entire EIA-232 protocol and provides high-level, easy-to-use functions for rapid application development.  The use of the NI-Serial driver software removes the short comings of the Win32 API, meaning any device built to use the EIA-232 standard will work with NI serial devices.

See Also:
Serial

Back to Top

3. EIA-422 Overview


EIA-422 is the serial connection used on Apple Macintosh computers. EIA-422 uses a differential electrical signal, as opposed to the unbalanced signals referenced to ground with EIA-232. Differential transmission, which uses two lines each for transmit and receive signals, results in greater noise immunity and longer distances as compared to EIA-232. The greater noise immunity and distance are big advantages in industrial applications.

National Instruments offers EIA-485/422 serial interfaces on a variety of platforms, including PCI, PCIe, USB, PCMCIA, ExpressCard, PXI, PXIe and Ethernet. Depending on the platform, NI Serial interfaces are available in 1, 2, 4, 8, and 16 port versions. In addition, NI EIA-485/422 serial interfaces offer increased functionality, such as high-speed baud rates up to 3 Mb/s, minimal CPU usage through DMA transfers, optional 2000 V port-to-port isolation, and configurable nonstandard baud rates. All National Instrument Serial interfaces include NI-Serial driver software, which implements the entire EIA-485/EIA-422 protocol and provides high-level, easy-to-use functions for rapid application development.

See Also:
Serial

Back to Top

4. EIA-485 Overview


EIA-485 is an improvement over EIA-422 because it increases the number of devices from 10 to 32 and defines the electrical characteristics necessary to ensure adequate signal voltages under maximum load. With this enhanced multidrop capability, you can create networks of devices connected to a single EIA-485 serial port. The noise immunity and multidrop capability make EIA-485 the serial connection of choice in industrial applications requiring many distributed devices networked to a PC or other controller for data collection, HMI, or other operations. EIA-485 is a superset of EIA-422; thus, all EIA-422 devices may be controlled by EIA-485. You can use EIA-485 hardware for serial communication for up to 1200m (4000ft) of cable.

National Instruments offers EIA-485/422 serial interfaces on a variety of platforms, including PCI, USB, PCMCIA, ExpressCard, PXI, and Ethernet. Depending on the platform, NI Serial interfaces are available in 1, 2, 4, and port versions. In addition, NI EIA-485/422 serial interfaces offer increased functionality, such as high-speed baud rates up to 3 Mb/s, minimal CPU usage through DMA transfers, optional 2000 V port-to-port isolation, and configurable nonstandard baud rates. All National Instrument Serial interfaces include NI-Serial driver software, which implements the entire EIA-485/422 protocol and provides high-level, easy-to-use functions for rapid application development.

See Also:
Serial

Back to Top

5. Pinouts for NI Serial Interface Connectors



DB-9 Male
DB-25 Male
10-Position Modular Jack
Pin
EIA-232
EIA-485/422
Pin
EIA-232
EIA-485/422
Pin
EIA-232
EIA-485/422
1
DCD
GND
2
TXD
RTS+ (HSO+)
1
No Connect
No Connect
2
RXD
CTS+ (HSI+)
3
RXD
CTS+ (HSI+)
2
RI
TXD-
3
TXD
RTS+ (HSO+)
4
RTS
RTS- (HSO-)
3
CTS
TXD+
4
DTR
RXD+
5
CTS
TXD+
4
RTS
RTS- (HSO-)
5
GND
RXD-
6
DSR
CTS- (HSI-)
5
DSR
CTS- (HSI-)
6
DSR
CTS- (HSI-)
7
GND
RXD-
6
GND
RXD-
7
RTS
RTS- (HSO-)
8
DCD
GND
7
DTR
RXD+
8
CTS
TXD+
20
DTR
RXD+
8
TXD
RTS+ (HSO+)
9
RI
TXD-
22
RI
TXD-
9
RXD
CTS+ (HSI+)
-
-
-
-
-
-
10
DCD
GND

 

Back to Top

6. What Is Handshaking?


This EIA-232 communication method allows for a simple connection of three lines -- Tx, Rx, and ground. However, for the data to be transmitted, both sides must be clocking the data at the same baud rate. Although this method is sufficient for most applications, it is limited in responding to problems such as overloaded receivers. This is where serial handshaking can help. Three of the most popular forms of handshaking with EIA-232 are software handshaking, hardware handshaking, and Xmodem.

Software Handshaking
This method uses data bytes as control characters similar to the way GPIB uses command strings. It also incorporates the simple three-line set of Tx, Rx, and ground because the control characters are sent over the transmission line like regular data. With the SetXMode function, you can enable or disable the use of two control characters, XON and XOFF. The data receiver sends these characters to pause the transmitter during communication.

The biggest drawback to this method is also the most important fact to keep in mind -- decimal 17 and 19 are no longer available for data values. This typically does not matter in ASCII transmissions because these values are noncharacter values; however, if you transmit the data via binary, it is very likely you could transmit these values as data and the transmission would fail.

Hardware Handshaking
This method uses actual hardware lines. Like the Tx and Rx lines, the RTS/CTS and DTR/DSR lines work together. One is the output and the other is the input.

The first set of lines are RTS (Request to Send) and CTS (Clear to Send). When a receiver is ready for data, it asserts the RTS line, indicating it is ready to receive data. This is read by the sender at the CTS input, indicating it is clear to send the data.

The next set of lines are DTR (Data Terminal Ready) and DSR (Data Set Ready). Engineers use these lines mainly for modem communication because they allow the serial port and the modem to communicate their status. For example, when the modem is ready for the PC to send data, it will assert the DTR line, indicating that a connection has been made across the phone line. This is read in through the DSR line, and the PC can begin to send data. The general rule of thumb is to use the DTR/DSR lines to indicate the system is ready for communication and the RTS/CTS lines for individual frames of data.

In LabWindows/CVI, the function SetCTSMode enables or disables the use of hardware handshaking. If the CTS mode is enabled, LabWindows/CVI employs the following rules:

When the PC sends data:
The EIA-232 library must detect that its CTS line is high before sending data.

When the PC receives data:
If the port is opened and the input queue has room for data, the library raises RTS and DTR.
If the port input queue is 90 percent full, the library lowers RTS and leaves DTR high.
If the port input queue is nearly empty, the library raises RTS and leaves DTR high.
If the port is closed, the library lowers RTS and DTR.

XModem Handshaking
Although this protocol is very common in modem communication, you can use the XModem protocol directly between other devices if they both follow the protocol. In LabWindows/CVI, the actual XModem implementation is hidden from the user. As long as the PC is connected to another device using XModem protocol, you can use the LabWindows/CVI XModem functions to transfer files from one site to another. The functions are XModemConfig, XModemSend, and XModemReceive.

XModem uses a protocol based on the following parameters: start_of_data, end_of_trans, neg_ack, ack, wait_delay, start_delay, max_tries, and packet_size. Both sides must agree on these parameters, and XModem has a standard definition of these. However, you can modify these parameters through the XModemConfig function in LabWindows/CVI to meet any requirement. You use these parameters in XModem by having the receiver send the neg_ack character. This tells the sender it is ready to receive data. The receiver then tries again with start_delay time in between each try until either it reaches max_tries or receives start_of_data from the sender. If it reaches max_tries, it informs the user that it could not communicate with the sender. If it does receive start_of_data from the sender, it reads the information packet that follows. This packet contains the packet number, the complement of the packet number as an error check, the actual data packet of packet_size bytes, and a checksum on the data for more error checking. After reading the data, the receiver calls wait_delay and then sends ack back to the sender. If the sender does not receive ack, it resends the data packet max_tries until it receives ack. If it never receives ack, it informs the user that it has failed to transfer the file.

Because the sender must send the data in packets of packet_size bytes, the sender pads the data packet with ASCII NULL (0) bytes if there is not enough data to fill the last packet. This can cause the received file to be larger than the original. Do not use XON/XOFF with the XModem protocol, because the packet number from the XModem transfer is very likely to increment to the XON/OFF control character values, which would cause a breakdown in communication.

Related Links:
Serial

Back to Top

Bookmark & Share

Ratings

Rate this document

Answered Your Question?
Yes No

Submit