Tải bản đầy đủ (.pdf) (9 trang)

LECTURE 16 8250 UART : UNIVERSAL ASYNCHRONOUS RECEIVER TRANSMITTER

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (66.98 KB, 9 trang )

CSN200 Introduction to Telecommunications, Winter 2000 Lecture_16 UART

8250 UART :
UNIVERSAL ASYNCHRONOUS RECEIVER TRANSMITTER

Serial communications is sufficiently complex that special chips have been designed to do the work of
forming and timing the strings of bits that comprise serial data. Such a chip is called a universal
asynchronous receiver transmitter or UART. Without UARTs, communications programming would
be very complicated. The IBM family of microcomputers use the Intel 8250 UART.

The Intel 8250 is a programmable Universal Asynchronous Receiver/Transmitter packaged in a 40-
pin integrated circuit.

• The UART is used to convert parallel data to serial format on the transmit side (data going to a
modem for example) and to convert serial data to a parallel format on the receive side (coming
from a modem).
• The serial format, in order of transmission and reception, is a start bit, followed by five to eight data
bits, a parity bit (if programmed) and one or two stop bits. The maximum recommended data rate is
54K bits per second.
• It can transmit characters at the same time as it is receiving characters (full duplex).
• The transmission speed of the UART is also programmable.
• Newer UARTs are now used in serial ports in PCs : 16450 and 16550 capable of speeds up to
115,000 bps. They are more efficient than the 8250 but are compatible with it from a programming
point of view.

Internal registers enable the user to program various types of interrupts, modem controls, and character
formats. The user can read the status of the UART at any time, monitoring transmission conditions,
interrupts and modem status.


FEATURES



* Automatically generates and strips the Serial Async Control Bits (start, stop, parity)
* Full double buffering allows precise synchronization.
* Independently controlled Transmit, Receive, Line Status, and data set Interrupts.
* Modem interface capabilities.
* Fully programmable Serial-Interface characteristics:
- 5-, 6-, 7-, or 8-Bit Characters
- Even, Odd, or No-parity Bit Generation and Detection
- 1-, 1 1/2-, or 2-Stop Bit Generation
- Baud Rate Generation (DC to 56K Baud)
* False Start Bit detector
* Complete status reporting capabilities.
* Internal Diagnostic capabilities
- Loopback Controls for Communications Link Fault Isolation
- Break, Parity, Overrun, and Framing Error Simulation


Lectur16.doc Page 1 (9)
CSN200 Introduction to Telecommunications, Winter 2000 Lecture_16 UART
DOS supports at least two communications ports, and hence requires at least two UARTS. Their base
addresses are kept at 0040:0000 for COM1 and 0040:0002 for COM2. A base address is the lowest
two-byte port address of the group of port addresses by which the UART is accessed. COM1 starts at
3F8H and COM2 at 2F8H. For convenience, the discussion here refers to the registers numbered
3FxH, but the same specifications apply to the registers at 2FxH.

The 8250 has ten programmable one-byte registers by which to control and monitor the serial port.
Most are devoted to initializing the port, a process that can be rather complicated. The ten registers are
accessed through seven port addresses, numbers 3F8H-3FEH (or 2F8H-2FEH). Detailed knowledge of
these registers is necessary for programming the UART at the register level. We will use a simpler
method called BIOS INT14.



UART Internal Registers of Importance:

Transmitter Holding Register holds the byte of data about to be sent to the modem.
Receiver Data Register keeps the most recent byte of data received from the modem.
Line Control Register is used to initialize the UART for a particular mode of operation.
Line Status Register monitors the status of the serial line indicating when characters have been
received, or fully sent and when errors occur.
The Modem Control and Modem Status Registers are used only for modem communications to
control and monitor the control lines in the RS-232 circuits.

• Polling Mode: Simple communications routines constantly monitor the line status register, waiting
for an incoming character, or waiting until the register indicates that it is all right to transmit another
byte of data. Serial data transmission rates are very slow compared to a microprocessors speed. A
program using polling mode spends most of its time waiting for characters to be transmitted, bit by
bit, or received bit by bit.
• Interrupt Mode: Because the CPU operates very quickly relative to the 1200 or 2400 bit-per-
second rate at which serial data typically moves, this method can be wasteful of CPU time that
might otherwise be devoted to processing the incoming/outgoing data.
• For this reason the 8250 may be set up to bring about an interrupt whenever a character arrives, an
error occurs, etc.
• The interrupt momentarily brings into action a procedure in your program that would, say, output
the next character from a communications buffer.

We will not use Interrupt Mode but will rather Poll the status of the UART before sending or receiving
characters.


INITIALIZING THE SERIAL PORT


When a communications port is initialized ("opened"), all of the parameters by which it operates are
set. These parameters include the word length, the number of stop bits, the parity setting, and the baud
rate. The word length is the number of bits that form the basic data unit. While we are accustomed to
working in eight bits, seven bits are adequate for standard ASCII files (where all characters are below
ASCII 128).

Lectur16.doc Page 2 (9)
CSN200 Introduction to Telecommunications, Winter 2000 Lecture_16 UART
Initialization of the 8250 involves supplying the following information:
Baud rate (speed) 75, 100, 150, 300, 600, 1200, 4800, 2400, 4800, or 9600 bits per second.
Parity given as a one-character code: O for ODD parity; E for EVEN parity (the
default); N for NONE (no parity); S for SPACE, where the parity bit is
always 0; and M for MARK, where the parity bit is always 1. If eight data
bits are used, specify N; if four bits are used, do not use N.
Data bits 4, 5, 6, 7, or 8
Stop bits 1 or 2.

PROGRAMMING THE SERIAL PORT
Two techniques for programming the serial port on a PC are:
1. BIOS INT 14H SERVICES
a) There are 4 "services" available to control the serial port.
b) This method is not suitable for transmission speeds in excess of 1200 baud.

2. DIRECT PORT ACCESS
The 8250 registers must be programmed directly for high performance applications. It usually
requires the use of interrupt handlers. We will not access the serial port addresses directly in this
course.

USING BIOS INT 14H FOR SERIAL PORT ACCESS:


Service Number 0 (INT 14H) - Initialize the Serial Port
This service sets up the communications parameters for the serial port: baud rate (speed), parity, stop
bits and character length.
An 8-bit number is loaded into the microprocessor’s AL Register according to the table below:

Bits 7 6 5 4 3 2 1 0


Character Length
1 0 = 7 bits
11 = 8 bits


Stop Bits
0 = 1 stop bit
1 = 2 stop bits



Parity
01 = Odd
11 = Even
00 = None
10 = None

Baud Rate
010 = 300
011 = 600
100 = 1200

101 = 2400
110 = 4800
111 = 9600

Fig. 1 Initializing The Serial Port
Lectur16.doc Page 3 (9)
CSN200 Introduction to Telecommunications, Winter 2000 Lecture_16 UART
Sample Assembly Language Program:

Initialization of COM1 for 1200 baud, odd parity, 7 bits, 1 stop bit
(Note: BIOS COM1 is port number 0; COM2 is port number 1)
MOV AL,8AH ;SET UP BYTE 10001010 binary
MOV AH,0 ;REQUEST SERVICE NUMBER 0
MOV DX,0 ;COMM PORT NUMBER 0 (COM1)
INT 14H ; BIOS SERVICE

Sample C Program:
A C Program to initialize the UART to the same value could use the int86 instruction to execute BIOS
int14. See attached listing of a sample program appended at the end.

Service Number 1 (INT 14H) - Transmit a Character
This function is used to transmit a character through the communications line. The character is
simply loaded into the microprocessor’s AL register. The DX register, as in all BIOS INT 14H
services, is loaded with the number of the communications port and the AH register with the service
number (01 in this case).

Example: Send a '$' sign through the communications line.
MOV AL,'$' ;Char to send
MOV AH,1 ;Request service no. 1
MOV DX,0 ; Comm port no. 0 (COM1)

INT 14H
Upon return to the caller, bit 7 of the AH is set if the routine was unable to transmit a byte of data,
indicating some error condition.

Service Number 2 (INT 14H) - Receive a Character
This function receives one character from the communications port. The character received is
returned in the AL register. Bit 7 of the AH register is set if the operation failed because of the data
set ready signal, indicating an error; for example, there was no data there to be received yet.

Service Number 3 (INT 14H) - Read the Serial Port Status
This service returns the status of the serial port. The AH register reports the status of the
communications line and the AL register contains the modem status.

Meaning of bits set by FUNCTION 3, INT 14H
AH REGISTER (COMM. LINE) AL REGISTER (MODEM)
Bit 7= Time-out error Received line signal detect
Bit 6= Trans shift register empty Ring Indicator
Bit 5= Trans Holding Register Empty Data Set Ready
Bit 4= Break Detect Clear to Send
Bit 3= Framing Error Delta Rx Line signal detect
Bit 2= Parity error Trailing edge Ring detector
Bit 1= Overrun error Delta Data Set Ready
Bit 0= Data Ready Delta Clear to send


Lectur16.doc Page 4 (9)
CSN200 Introduction to Telecommunications, Winter 2000 Lecture_16 UART

The (THRE) Transmit Holding Register Empty Bit
0 ==> a character is still in the process of being sent. Transmitter is still Busy so a new character

cannot be sent until this bit becomes a 1.
1 ==> Transmit Holding Register is empty so a new character can now be transmitted.

Data Ready Bit
0 ==> Data has not been received yet.
1 ==> A character has arrived in the Data Received Register and must be read in as soon as
possible.



Lectur16.doc Page 5 (9)

×