from:http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
Universal asynchronous receiver/transmitter
| This article needs additional citations for verification. (November 2010) |
A Universal Asynchronous Receiver/Transmitter, abbreviated UART ( /ˈjuːɑrt/), is a type of "asynchronous receiver/transmitter", a piece of computer hardware that translates data between parallel and serial forms. UARTs are commonly used in conjunction with communication standards such asEIA,RS-232,RS-422 orRS-485. The universal designation indicates that the data format and transmission speeds are configurable and that the actual electric signaling levels and methods (such asdifferential signaling etc.) typically are handled by a special driver circuit external to the UART.
A UART is usually an individual (or part of an) integrated circuit used for serial communications over a computer or peripheral device serial port. UARTs are now commonly included in microcontrollers. A dual UART, orDUART, combines two UARTs into a single chip. Many modern ICs now come with a UART that can also communicate synchronously; these devices are calledUSARTs (universal synchronous/asynchronous receiver/transmitter).
Contents |
Transmitting and receiving serial data
The Universal Asynchronous Receiver/Transmitter (UART) takes bytes of data and transmits the individual bits in a sequential fashion.[1] At the destination, a second UART re-assembles the bits into complete bytes. Each UART contains ashift register, which is the fundamental method of conversion between serial and parallel forms. Serial transmission of digital information (bits) through a single wire or other medium is much more cost effective than parallel transmission through multiple wires.[citation needed]
The UART usually does not directly generate or receive the external signals used between different items of equipment. Separate interface devices are used to convert thelogic level signals of the UART to and from the external signaling levels. External signals may be of many different forms. Examples of standards for voltage signaling areRS-232,RS-422 and RS-485 from theEIA. Historically, current (incurrent loops) was used in telegraph circuits. Some signaling schemes do not use electrical wires. Examples of such areoptical fiber, IrDA (infrared), and (wireless)Bluetooth in its Serial Port Profile (SPP). Some signaling schemes use modulation of a carrier signal (with or without wires). Examples are modulation of audio signals with phone linemodems, RF modulation with data radios, and theDC-LIN forpower line communication.
Communication may be simplex (in one direction only, with no provision for the receiving device to send information back to the transmitting device),full duplex (both devices send and receive at the same time) orhalf duplex (devices take turns transmitting and receiving).
Character framing
The idle, no data state is high-voltage, or powered. This is a historic legacy from telegraphy, in which the line is held high to show that the line and transmitter are not damaged. Each character is sent as a logic low start bit, a configurable number of data bits (usually 8, but legacy systems can use 5, 6, 7 or 9), an optional parity bit, and one or more logic high stop bits. The start bit signals the receiver that a new character is coming. The next five to eight bits, depending on the code set employed, represent the character. Following the data bits may be a parity bit. The next one or two bits are always in the mark (logic high, i.e., '1') condition and called the stop bit(s). They signal the receiver that the character is completed. Since the start bit is logic low (0) and the stop bit is logic high (1) there are always at least two guaranteed signal changes between characters.
Obviously a problem exists if a receiver detects a line that is low for more than one character time. This is called a "break." It is normal to detect breaks to disable a UART or switch to an alternative channel. Sometimes remote equipment is designed to reset or shut down when it receives a break. Premium UARTs can detect and create breaks.
Receiver
All operations of the UART hardware are controlled by a clock signal which runs at a multiple of the data rate. For example, each data bit may be as long as 16 clock pulses. The receiver tests the state of the incoming signal on each clock pulse, looking for the beginning of the start bit. If the apparent start bit lasts at least one-half of the bit time, it is valid and signals the start of a new character. If not, the spurious pulse is ignored. After waiting a further bit time, the state of the line is again sampled and the resulting level clocked into a shift register. After the required number of bit periods for the character length (5 to 8 bits, typically) have elapsed, the contents of the shift register is made available (in parallel fashion) to the receiving system. The UART will set a flag indicating new data is available, and may also generate a processorinterrupt to request that the host processor transfers the received data.
The best UARTs "resynchronize" on each change of the data line that is more than a half-bit wide. In this way, they reliably receive when the transmitter is sending at a slightly different speed than the receiver. (This is the normal case, because communicating units usually have no shared timing system apart from the communication signal.) Simplistic UARTs may merely detect the falling edge of the start bit, and then read the center of each expected data bit. A simple UART can work well if the data rates are close enough that the stop bits are sampled reliably.
It is a standard feature for a UART to store the most recent character while receiving the next. This "double buffering" gives a receiving computer an entire character transmission time to fetch a received character. Many UARTs have a small first-in, first-outFIFO buffer memory between the receiver shift register and the host system interface. This allows the host processor even more time to handle an interrupt from the UART and prevents loss of received data at high rates.
Transmitter
Transmission operation is simpler since it is under the control of the transmitting system. As soon as data is deposited in the shift register after completion of the previous character, the UART hardware generates a start bit, shifts the required number of data bits out to the line, generates and appends the parity bit (if used), and appends the stop bits. Since transmission of a single character may take a long time relative to CPU speeds, the UART will maintain a flag showing busy status so that the host system does not deposit a new character for transmission until the previous one has been completed; this may also be done with an interrupt. Since full-duplex operation requires characters to be sent and received at the same time, practical UARTs use two different shift registers for transmitted characters and received characters.
Application
Transmitting and receiving UARTs must be set for the same bit speed, character length, parity, and stop bits for proper operation. The receiving UART may detect some mismatched settings and set a "framing error" flag bit for the host system; in exceptional cases the receiving UART will produce an erratic stream of mutilated characters and transfer them to the host system.
Typical serial ports used with personal computers connected to modems use eight data bits, no parity, and one stop bit; for this configuration the number of ASCII characters per second equals the bit rate divided by 10.
Some very low-cost home computers or embedded systems dispensed with a UART and used the CPU to sample the state of an input port or directly manipulate an output port for data transmission. While very CPU-intensive, since the CPU timing was critical, these schemes avoided the purchase of a UART chip that was costly in the 1970's. The technique was known as a bit-banging serial port.
Synchronous transmission
USART chips have both synchronous and asynchronous modes. In synchronous transmission, the clock data is recovered separately from the data stream and no start/stop bits are used. This improves the efficiency of transmission on suitable channels since more of the bits sent are usable data and not character framing. An asynchronous transmission sends no characters over the interconnection when the transmitting device has nothing to send; but a synchronous interface must send "pad" characters to maintain synchronization between the receiver and transmitter. The usual filler is the ASCII "SYN" character. This may be done automatically by the transmitting device.
History
Some early telegraph schemes used variable-length pulses (as in Morse code) and rotating clockwork mechanisms to transmit alphabetic characters. The first UART-like devices (with fixed-length pulses) were rotating mechanical switches (commutators). These sent 5-bitBaudot codes for mechanical teletypewriters, and replacedmorse code. Later, 6-bit codes became common to avoid the figures vs. character errors that could occur when Baudot's shift character was corrupted.ASCII was adopted by the U.S. so that the military services would all use the same teletypewriter codes. ASCII added upper and lower case, with enough punctuation to print most documents. This required a seven bit code. When U.S. telephone systems became digital in the 1960s, they used an8-bit data sample size to digitize voice. As a result, most data transmission and computers shifted to 8-bit character sizes to use the lowest cost data transmission system. For example,IBM built computers in the early 1960s with 8-bit characters, and an "upper half" of Latin I characters became common in many data networks that had formerly used 7-bit ASCII. The economic effect of the telephone system is large: It effectively forced character systems with more than 8-bits (e.g.Unicode) back into an 8-bit form (e.g.UTF-8), and most commercially important computers for the last forty years have used internal word sizes that are multiples of 8 bits.
Gordon Bell designed the UART for thePDP series of computers. The ASCII code to a teletypewriter made an excellent general-purpose I/O device for a small computer. To reduce costs, including wiring and back-plane costs, these computers also pioneeredflow control using XON and XOFF characters rather than hardware wires.
Western Digital made the first single-chip UART WD1402A around 1971; this was an early example of amedium scale integrated circuit. Another popular chip was a SCN2651 from the Signetics 2650 family.
An example of an early 1980s UART was the National Semiconductor 8250. In the 1990s, newer UARTs were developed with on-chip buffers. This allowed higher transmission speed without data loss and without requiring such frequent attention from the computer. For example, the popular National Semiconductor16550 has a 16 byteFIFO, and spawned many variants, including the16C550, 16C650, 16C750, and 16C850.
Depending on the manufacturer, different terms are used to identify devices that perform the UART functions.Intel called their8251 device a "Programmable Communication Interface".MOS Technology6551 was known under the name "Asynchronous Communications Interface Adapter" (ACIA). The term "Serial Communications Interface" (SCI) was first used atMotorola around 1975 to refer to their start-stop asynchronous serial interface device, which others were calling a UART.
Structure
A UART usually contains the following components:
- a clock generator, usually a multiple of the bit rate to allow sampling in the middle of a bit period.
- input and output shift registers
- transmit/receive control
- read/write control logic
- transmit/receive buffers (optional)
- parallel data bus buffer (optional)
- First-in, first-out (FIFO) buffer memory (optional)
Special receiver conditions
Overrun error
An "overrun error" occurs when the receiver cannot process the character that just came in before the next one arrives. Various devices have different amounts of buffer space to hold received characters. The CPU must service the UART in order to remove characters from the input buffer. If the CPU does not service the UART quickly enough and the buffer becomes full, an Overrun Error will occur, and incoming characters will be lost.
Underrun error
An "underrun error" occurs when the UART transmitter has completed sending a character and the transmit buffer is empty. In asynchronous modes this is treated as an indication that no data remains to be transmitted, rather than an error, since additional stop bits can be appended. This error indication is commonly found in USARTs, since an underrun is more serious in synchronous systems.
Framing error
A "framing error" occurs when the designated "start" and "stop" bits are not valid. As the "start" bit is used to identify the beginning of an incoming character, it acts as a reference for the remaining bits. If the data line is not in the expected idle state when the "stop" bit is expected, a Framing Error will occur.
Parity error
A "parity error" occurs when the number of "active" bits does not agree with the specified parity configuration of the USART, producing aParity Error. Because the "parity" bit is optional, this error will not occur if parity has been disabled. Parity error is set when the parity of an incoming data character does not match the expected value.
Break condition
A "break condition" occurs when the receiver input is at the "space" level for longer than some duration of time, typically, for more than a character time. This is not necessarily an error, but appears to the receiver as a character of all zero bits with a framing error.
Some equipment will deliberately transmit the "break" level for longer than a character as an out-of-band signal. When signaling rates are mismatched, no meaningful characters can be sent, but a long "break" signal can be a useful way to get the attention of a mismatched receiver to do something (such as resetting itself). Unix-like systems can use the long "break" level as a request to change the signaling rate, to support dial-in access at multiple signaling rates.
UART models
Model | Description |
---|---|
EXAR XR21V1410 | |
Intersil 6402 | |
CDP 1854 (RCA, now Intersil) | |
Zilog Z8440 | 2000 kbit/s. Async, Bisync, SDLC, HDLC, X.25. CRC. 4-byte RX buffer. 2-byte TX buffer. DMA.[2] |
8250 | Obsolete with 1-byte buffers |
8251 | |
Motorola 6850 | |
6522 | |
6551 | |
Rockwell 65C52 | |
16450 | |
16550 | |
16550A | 16-byte buffers, TL=1,4,8,14; 115.2 kbit/s standard, many support 230.4 or 460.8 kbit/s. DMA-mode.[3] |
16C552 | |
16650 | 32-byte buffers. 460.8 kbit/s. |
16750 | 64-byte buffer for send, 56-byte for receive. 921.6 kbit/s. |
16850 | 128-byte buffers. 460.8 kbit/s or 1500 kbit/s. |
16C850 | |
16950 | |
Hayes ESP | 1 kB buffers, 921.6 kbit/s, 8-ports.[4] |
UART in modems
Modems for personal computers that plug into a motherboard slot must also include the UART function on the card. The original 8250 UART chip shipped with the IBM personal computer had no on-chip buffering for received characters, which meant that communications software performed poorly at speeds above 9600 bits/second, especially if operating under a multitasking system or if handling interrupts from disk controllers. High-speed modems used UARTs that were compatible with the original chip but which included additional FIFO buffers, giving software additional time to respond to incoming data.
A look at the performance requirements at high bit rates shows why the 16, 32, 64 or 128 byte FIFO is a necessity. The Microsoft specification for a DOS system requires that interrupts not be disabled for more than 1 millisecond at a time. Some hard disk drives and video controllers violate this specification. 9600 bit/s will deliver a character approximately every millisecond, so a 1 byte FIFO should be sufficient at this rate on a DOS system which meets the maximum interrupt disable timing. Rates above this may receive a new character before the old one has been fetched, and thus the old character will be lost. This is referred to as an overrun error and results in one or more lost characters. With error correcting modems, any lost characters will be retransmitted, but retransmission slows the connection.
A 16 byte FIFO allows up to 16 characters to be received before the computer has to service the interrupt. This increases the maximum bit rate the computer can process reliably from 9600 to 153,000 bit/s if it has a 1 millisecond interrupt dead time. A 32 byte FIFO increases the maximum rate to over 300,000 bit/s. A second benefit to having a FIFO is that the computer only has to service about 8 to 12% as many interrupts, allowing more CPU time for updating the screen, or doing other chores. Thus the computer's responses will improve as well.