Jump to content

RS-232

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Nixdorf (talk | contribs) at 08:53, 14 June 2004 (category). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


RS-232 (also referred to as EIA RS-232C or V.24) is a standard for serial binary data interchange between a DTE (Data terminal equipment) and a DCE (Data communication equipment). It is commonly used in personal computer serial ports.

History

This standard was originally used for connecting a teletypewriter, which used ASCII code, asynchronous communication and electromechanical components, with a modem. Many early minicomputers from companies such as DEC used 33-ASR teletypes as cheap system consoles (for a fancier machine one got a 35-ASR). When electronic terminals (smart and dumb) began to be used, they were often designed to be interchangeable with teletypes, and so supported RS-232. The C revision of the standard was issued in 1969 in part to accommodate the electrical characteristics of these devices. Then, because it was there, it was used for all sorts of remote communications, especially through modems, including computer to computer. Later personal computers (and other devices) started to make use of the standard so that they could connect to existing equipment. When IBM introduced the PC with an RS-232 port, this interface became truly ubiquitous. For many years some form of RS-232 port was a standard feature for serial communications on almost all computers. It remained in widespread use into the late 1990s. For much of this time it was the standard way to connect modems.

One exception is mainframe computers, which generally do not communicate directly with terminal devices. These large systems generally have specialized I/O processors attached to them for this purpose. For instance, some IBM mainframes had a telecommunication control unit (TCU) attached to their multiplexer channel. The TCU would support multiple terminals, sometimes hundreds. Many of these TCUs could support RS-232 when it was required, although there were other serial interfaces as well.

There is some confusion about what the EIA actually standardized in RS-232. This standard only specifies electrical characteristics and circuits and pin numbers. The other characteristics of the teletype interface such as the D connector, use of the ASCII code and data format and asynchronous (or start-stop) communications are not part of RS-232, but were lumped into the name because these features usually all came together, so that in the end they became, effectively, mandatory, and the original meaning of the standard name was lost. There were about 100,000 33-ASR teletypes made in total, there are now almost that many PCs made every week, but they can all act as virtual teletypes. About the only feature that was required by teletypes that has been generally abandoned is that a real teletype required two stop bits to work reliably, so that a character took 11 bit times. This is why 100 word per minute teletypes transmitted at 110 baud. Today everyone uses one stop bit. In the rest of this article RS-232 means the 33-ASR teletype simulation, not the document.

IBM favored the use of the eight-bit EBCDIC code instead of the seven-bit ASCII code. IBM also favored a big endian transmission format instead of the little endian ASCII format. IBM did support all of these however. In order to send little endian characters, for instance, the mainframe would simply bit reverse each character in a string using a block translate instruction.

Earlier teletype machines had 3 rows of keys and only supported upper case letters. They used the 5 bit baudot code and generally worked at 60 words per minute. Teletypes with 4 row keyboards and ASCII code with upper and lower case letters were an innovation that came into use in the same period as computers began to become widely available. The UART serial communications integrated circuits, introduced in the early 1970s, and still emulated by most chipsets, still support the earlier teletype formats, including 1.5 stop bits, but these features are rarely used.

The importance of serial ports began to wane when high speed networking became available for computer to computer communications. Although there were many competing standards originally, today this usually means 10 or 100 Base T Ethernet type connections. In the near future (post 2004) even higher speeds will be common.

Role in modern computing

Today, RS-232 is gradually being superseded by USB for local communications. USB is faster, has connectors that are simpler to connect and use, and has better software support. This is why many PCs intended for office use often ship with 'legacy-free' motherboards without any RS-232 circuitry. However, RS-232 is still quite common in point-of-sale (cash drawers, barcode and magnetic stripe readers) and industrial (measurement and remote-control devices) peripherals, so computers made for such applications are still equipped with RS-232 ports either 'on-board', or on a separate PCI or ISA card. As an alternative, USB docking ports are available which can provide connectors for PS/2 keyboard, PS/2 mouse, one or more serial ports, and one or more parallel ports.

Standard details

In RS-232, characters are sent one by one as a pattern of bits. The most common encoding format is the asynchronous start-stop format which uses a "start bit" followed by seven or eight data bits, possibly a "parity" bit, and one or two "stop bits". Thus 10 bits are used to send a single character, which has the nice side effect that dividing the signalling rate by ten results in the overall transmission speed. The most common alternative to asynchronous start-stop is HDLC.

The RS-232 standard defines the voltage levels that correspond to logical one and logical zero levels, the standard transmission speeds and connector types.

Connectors

The standard specifies 20 different signal connections, and a 25-pin "D-sub" (D-shaped subminiature) connector was commonly used. Male and female connectors are used – often cable ends are male and device connectors are female; but not always; m-m and f-f "gender changers" are available. There are also null modems for connecting units that both act as data terminals (or modems). For configuring and diagnosing problems with RS-232 cables, a "breakout box" may be used. This device normally has a female and male RS-232 connector and is meant to attach in-line; it then has lights for each pin and provisions for interconnecting pins in different configurations.

Most of these pins were unused by many devices, however, so it was common for machines to save money and space by using smaller connectors. The second generation IBM PC AT was released with 9-pin D-sub connectors, and that became the de facto standard; most external devices still use 25-pin connectors, so cables with 9 pins on one end and 25 on the other were common. The Apple Macintosh used a similar system, but later changed to a new connector with only 8 pins, less than what is needed for a modem.

RS-232 cables may be built with connectors commonly available at electronics stores. The cables may be between 3 and 25 pins; typically 4- or 6-pin wires are used. Flat RJ (phone-style) cables may be used with special RJ-RS232 connectors, which are the easiest to configure.

The reason that a minimal two-way interface can be created with only 3 wires is that all the RS-232 signals share a common ground return. The use of unbalanced circuits makes RS-232 highly susceptible to problems due to ground potential shifts between the two devices. RS-232 also has relatively poor control of signal rise and fall times, leading to potential crosstalk problems. RS-232 was recommended for short connections (15 meters or less). RS-232 interface cables are not usually constructed with twisted pair because of the unbalanced circuits.

Signals are plus or minus 3 to 15 volts. The range near zero volts is not a valid RS-232 level; logic one is defined as a negative voltage, the signal condition is called marking, and has the functional significance of OFF. Logic zero is positive, the signal condition is spacing, and has the function ON. Signal levels of +-5, +-10, +-12, and +-15 are all commonly seen depending on the power supplies available within a device.

Mark and space are terms carried over from teletypes. The native mode of communication for a teletype is a simple series DC circuit that is interrupted, much like a rotary dial interrupts a telephone signal. The marking condition is when the circuit is closed, the spacing condition is when the circuit is open. The start of a character is signalled by a space. The stop bits are marking. When the line is broken, a teletype cycles continuously but prints nothing because it is receiving all zeros, the NUL character.

There are three types of signals carried by these wires: ground, transmit/receive, and handshake. There are standard codes for these signals, for example:

SG or GND - Ground
TD or TX - Transmit Data
RD or RX - Receive Data
DTR - Data Terminal Ready
DSR - Data Set Ready
RTS - Ready to Send
CTS - Clear to send
DCD - Data Carrier Detect
RI - Ring Indicator
FG - Frame Ground

RS-232 devices may be classified as DTE or DCE; this defines which wires will be sending and receiving each signal. However, these definitions are not always adhered to strictly; normally it's necessary to consult documentation or test connections with a breakout box to determine signals required.

The ground signal is meant to ground the other connections. It is required. However, if the equipment is far enough apart or on separate power systems, the ground will degrade between the two devices and communications will fail; this is a difficult condition to trace. For 25-pin connectors, pin 7 is normally ground (pin 1, chassis ground, is rarely used).

For 25-pin connectors, pin 2 and 3 are the normal transmit/receive pins. One device will be sending on 2 and receiving on 3; the other should be the reverse (if not, the reverse is done in the cable end, as with a null modem adapter). If you're wiring a connection, check with the breakout box on each device to see which pin it's transmitting on. Strictly speaking, only one device need be transmitting (if no handshakes or duplex communication is required)--for example a simple printer that does not report status back to the computer. But normally both TX and RX are required.

Other "handshakes" may be required by one or the other device. For example, pin 20 is commonly used to indicate "device ready". Pins may also be "jumpered" or routed back within the connector. For example a pin saying "are you ready?" from device A might be wired to the pin saying "I'm ready" on device A if device B did not transmit such a signal. Common handshake pins are 20, 8, 4, and 6.

Settings

There is a multitude of software settings for serial connections. Most common settings are speed, parity, and stop bits.

Speed is bit speed from one device to another in bits per second (bit/s). Common bit rates per second are 300, 1200, 2400, 9600, 19200, etc. Typically both devices must be set to the same speed but some devices (such as modems) may be set to autodetect speed.

Parity is a method of verifying accuracy of data. Parity is usually none (not used), but can be odd or even. Parity works by modifying the data in each byte sent (or restricting the bytes sent if you like). Parity none is simple, the data is not changed. In even parity the data is arranged so that the number of 1 bits (that is, the total count of them in a binary byte) is an even number; this is arranged by setting the parity bit (usually the last or most significant bit) to be a 0 or 1 accordingly. In odd parity the number of 1 bits is an odd number. Parity can be used by the receiver to detect transmission errors - if a byte is received with the wrong number of 1 bits, then it must have been corrupted. If parity is correct there may have been no errors or an even number of errors.

Stop bits are sent at the end of every byte transmitted in order to allow the receiving signal hardware to resynchronise.

There is a D/P/S conventional notation for specifying the software setup of a serial connection. 8/N/1 (very common) specifies 8 data bits, no parity, 1 stop bit. The number of data bits can be 7, 8, or (sometimes) 9. Parity can be none (N), odd (O), or even (E); the parity bit is borrowed from the data bits, so 8/E/1 means that one of the 8 data bits is used as the parity bit. There can be 1, 1.5, or 2 stop bits (1.5 was used by the 60 wpm baudot teletypes).

Other settings define when pins will send handshake signals, or other data integrity checks. The most common of these is XON/XOFF. The XON character tells the receiver that the sender is ready to receive more data. The XOFF character tells the receiver to stop sending characters. The use of XON/XOFF is deprecated, and it is preferable to use RTS/CTS flow control instead.

XON/XOFF is an in-band method that works between the endpoints, but both ends must support the protocol, and there is the potential for confusion in starting up. It can be done on a 3 wire interface. RTS/CTS was originally intended to allow the teletype and the modem to coordinate half-duplex links where only one modem could transmit at a time. The terminal would raise Request To Send and wait for the modem to respond with Clear To Send. RTS/CTS is a hardware handshake, but it does have advantages.

An ASR teletype had a paper tape reader. Characters were sent when the tape was read (ASR stands for Automatic Send Receive). In an ASR teletype machine receipt of the XOFF character turned off the paper tape reader and receipt of an XON character turned it back on. The distant system would send XOFF when it was necessary to slow down the sender. In the original systems messages were prepared ahead on paper tape so that transmission time could be minimized. Bandwidth was very scarce and expensive. This also motivated the development of the terse "telegraphic" style of expression. In some early minicomputers the paper tape reader and punch were the only way to back up and restore software.

There are a couple of signaling "standards" often called RS-232, but really not. TTL-level RS-232 uses +5V for high, and 0V for low. CMOS-level RS-232 uses +3.3V for high, and 0V for low. Typically, these signal levels are used between two devices on the same circuit board. 20mA current loop uses the absence of 20mA current for high, and the presence of current in the loop for low; this signal level is often used for long-distance and optically isolated links.

Other interfaces similar to RS-232:

  • RS-422 (a high-speed system similar to RS-232 but with differential signalling)
  • RS-423 (a high-speed system similar to RS-422 but with unbalanced signalling)
  • RS-449 (a proposed successor of RS-232 that used RS-422 and RS423 signals - it never caught on like RS-232)
  • RS-485 (a descendant of RS-422 that can be used as a bus in multidrop configurations)
  • MIL STD 188 (a system like RS-232 but with better impedance and rise time control)