Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 2


sions used in this book’s examples, each data-transition period represents one
data bit, and the bit rate and baud rate are the same. On phone lines,
high-speed modems use phase shifts and other techniques to encode multiple
bits in each data-transition period, resulting in a baud rate that is less than the
bit rate. In popular use, however, the term baud rate often refers to the bit rate.
The number of characters transmitted per second equals the bit rate divided by
the number of bits in a word. With 8-N-1 format, a byte of data transmits at
1/10 the bit rate because each word contains 10 bits: 1 Start bit, 8 data bits, and
1 Stop bit. So a 9600-bps link using 8-N-1 format can transmit 960 data bytes
per second.

!5
!

3 
%" 8 
 


In PCs and many microcontrollers, a UART handles low-level details of send-
ing and receiving serial data. PC operating systems and programming languages
also provide drivers and other support for serial-port communications. Pro-
grammers thus can access ports without understanding every detail of the
UART’s architecture. To gain access to a port, an application selects a bit rate
and other port parameters and requests to open, or gain access to, the desired
port. To send a byte, the application writes the byte to the transmit buffer of the
selected port. The UART then sends the data, bit by bit in the requested for-
mat, adding Stop, Start, and parity bits as needed.
In a similar way, the UART stores received bytes in a buffer. After receiving a
byte, the UART can generate an interrupt to notify an application of received
data, or software can poll the port to find out if data has arrived. The
COM-port driver in PCs uses software buffers to supplement the UART’s hard-
ware buffers and manages the flow of data between the buffers.
The UARTs in microcontrollers perform the same functions as UARTs in PCs.
Some microcontrollers don’t have embedded UARTs, or an application might
need more serial ports than the hardware provides. In those cases, a system can
interface to an external UART or implement a UART in firmware. Parallax,
Inc.’s Basic Stamp module is an example of a system with a firmware UART.
Some microcontrollers contain a USART (Universal Synchronous/Asynchro-
nous Receiver/Transmitter), which is similar to a UART but supports both syn-
chronous and asynchronous communications.
Free download pdf