Chapter 10. Serial Ports

Yet all experience is an arch wherethro’Gleams that untravell’d world whose margin fades For ever and for ever when I move.

Alfred, Lord Tennyson, Ulysses

Serial I/O involves the transfer of data over a single wire for each direction. All serial interfaces convert parallel data to a serial bit stream and vice versa. Serial communication is employed when moving data in parallel between systems is not practical, either in physical or cost terms. Such serial communication may be between a computer and a terminal or printer, the infrared beamings of a Palm computer or remote control, or, in more advanced forms, high-speed network communication such as Ethernet. For embedded computers, a simple serial interface is the easiest and cheapest way to connect to a host computer, either as part of the application or merely for debugging purposes.

This chapter looks at serial ports and how you implement an RS-232C interface. We’ll even take a look at how you can power your embedded system through an RS-232C port. From there, we’ll take a look at the more robust RS-422. We’ll then take a look at a serial interface with a difference, IrDA. IrDA uses pulses of infrared light to transmit data across short distances, without the need of interconnecting cables. Finally, we’ll take a look at a serial interface that is rapidly dominating both desktop computers and peripherals. USB allows peripherals to be networked to a host desktop computer and is becoming the standard by which you will interface your embedded computer to a Macintosh or PC.

Let’s start our examination of serial interfaces by looking at the engine that drives it all.

UARTs

The simplest form of serial interface is that of the Universal Asynchronous Receiver Transmitter, or simply just UART for short. They also are sometimes called Asynchronous Communication Interface Adapters, or ACIAs. They are termed “asynchronous” because no clock is transmitted with the serial data. The receiver must lock onto the data and detect individual bits without the luxury of a clock for synchronization.

Figure 10-1 shows a functional diagram of a UART. It consists of two sections, a receiver (Rx) that converts a serial bit stream to parallel data for the microprocessor and a transmitter (Tx) that converts parallel data from a microprocessor into serial form for transmission. The UART also provides status information such as whether the receiver is full (data has arrived) or the transmitter is empty (a pending transmission has completed). Many microcontrollers incorporate UARTs on-chip, but for larger systems, the UART is often a separate device.

Functional diagram of a Universal Asynchronous Receiver Transmitter

Figure 10-1. Functional diagram of a Universal Asynchronous Receiver Transmitter

Serial devices send data one bit at a time, so normal “parallel” data must first be converted to serial form before transfer. Serial transmission consists of breaking down bytes of data into single bits and shifting them out of the device one at a time. A UART’s transmitter is essentially just a parallel-to-serial converter with extra features. The essence of the UART transmitter is a shift register that is loaded in parallel, and then each bit is sequentially shifted out of the device on each pulse of the serial clock. Conversely, the receiver accepts a serial bit stream into a shift register, and then this is read out in parallel by the processor.

Tip

UARTs actually predate semiconductor-based computers. In the early days of electrical communication, UARTs were mechanical devices with cogs, relays, and electromechanical shift registers. To adjust a UART’s settings, you first picked up a wrench!

One of the problems associated with serial transmission is reconstructing the data at the receiving end. Difficulties arise in detecting boundaries between bits. For instance, if the serial line is low for a given length of time, the device receiving the data must be able to identify whether the stream represents 00 or 000. It has to know where one bit stops and the next starts. The transmitting and receiving devices can accomplish this by sharing a common clock. Hence, in a synchronous serial system, the serial data stream is synchronized with a clock that is transmitted along with the data stream. This simplifies the recovery of data but requires an extra signal line to carry the serial clock. Asynchronous serial devices, such as UARTs, do not share a common clock; rather, each device has its own, local clock. The devices must operate at exactly the same frequency, and additional logic is required to detect the phase of the transmitted data and phase-lock the receiver’s clock to it.

Asynchronous transmission is used in systems in which one character is sent at a time, and the interval of time between each byte transmission may vary. The transmission format uses one start bit at the beginning and one or two stop bits at the end of each character (Figure 10-2). The receiver synchronizes its clock upon receiving the start bit and then samples the data bits (either seven or eight, depending on the system configuration). Upon receiving the stop bit(s) in the correct sequence, the receiver assumes that the transfer was successful and that it has a valid character. If it did not receive an appropriate stop sequence, the receiver assumes that its clock drifted out of phase and a framing error or bit-misalignment error is declared. It’s up to the application software to check for such errors and take appropriate action.

Asynchronous serial data

Figure 10-2. Asynchronous serial data

The conversion from parallel to serial format is usually accomplished by dedicated UART hardware, but in systems in which only parallel I/O is available, the conversion may be performed by software, toggling a single bit of a parallel I/O port acting as the serial line.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.132.223