📄 rs232.txt
字号:
RS-232 Serial Communications
USERS MANUAL
Version 1.3
Aug 14 1998
Copyright (C) 1998
All rights reserved
MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815
Voice : 256-881-4630
FAX : 256|880|0925
BBS : 256-880-9748 [upon request]
email : info@marshallsoft.com
web : http://www.marshallsoft.com
ftp : ftp://ftp.marshallsoft.com/marshallsoft
_______
____|__ | (R)
--+ | +-------------------
| ____|__ | Association of
| | |_| Shareware
|__| o | Professionals
--+--+ | +---------------------
|___|___| MEMBER
MARSHALLSOFT is a trademark of MarshallSoft Computing, Inc.
RS-232 Serial Communications Page 1
C O N T E N T S
Chapter Page
1.0 The UART...................................................3
1.1 UART Types.............................................3
National 8250..........................................3
National 16450.........................................3
National 16550.........................................3
StarTech 16650.........................................3
Texas Instruments 16750................................3
1.2 UART Operation.........................................4
1.3 RS-232 Signals.........................................5
1.4 UART Registers.........................................6
1.5 Register Summary.......................................7
2.0 Modems
2.1 Modem Standards.......................................11
2.2 Flow Control..........................................12
2.3 Modem Initialization..................................13
3.0 Other Serial Devices......................................14
4.0 Shareware.................................................14
RS-232 Serial Communications Page 2
1.0 The UART
The heart of serial communications is the "Universal Asynchronous
Receiver Transmitter", or UART for short. The UART is responsible for
controlling the computer's RS-232 port.
1.1 UART Types
UARTs can be broken down into two classes: buffered and unbuffered.
The 8250 and 16450 are unbuffer, while the 16550, 16650, and 16750
are buffered.
1.1.1 National 8250
The National 8250 was the original UART used in the IBM PC and
compatibles, and are only suitable up to 9600 baud on slower DOS
(before the IBM/AT) machines. The 8250A is somewhat faster than the
8250, but should also be limited to slower DOS machines.
1.1.2 National 16450
The National 16450 was designed to work with the IBM PC/AT (16-bit
data bus) and faster machines. Faster than the 8250, it still has a
one-byte buffer. The 16450 chip is suitable for many DOS applications
and some Windows applications up to about 38400 baud.
1.1.3 National 16550
The National 16550 features 16-byte transmit side and receive side
FIFO buffers. The interrupt trigger level (on the receive side) can
be set at 1, 4, 8 or 14 bytes. The TX FIFO trigger is fixed at 16
bytes.
The FIFOs on the original 16550 UARTs did not work. The 16550A soon
followed the 16550 and is the "standard" UART for Windows machines.
The 16550A is recommended as the minimum chip on any new serial board
purchase.
1.1.4 StarTech 16650
The StarTech 16650 features 32-byte FIFOs and on-chip flow control,
and can be run at up to 460800 baud. It is also pin for pin
compatible with the 16550 UART.
1.1.5 TI 16750
The Texas Instruments 16750 features 64-byte FIFOs and on-chip flow
control and can be run at up to 921600 baud, but is not pin for pin
compatible with the 16550 UART.
RS-232 Serial Communications Page 3
1.2 UART Operation
The purpose of the UART is:
(1) To convert bytes from the CPU (Central Processing Unit) into a
serial format by adding the necessary start, stop, and parity bits to
each byte before transmission, and to then transmit each bit at the
correct baud rate.
The first bit is always the start bit, followed by 5 to 8 data bits,
(optionally) followed by the parity bit, followed by the stop bit or
bits.
(2) To convert the incoming stream (at a specified baud rate) of
serial bits into bytes by removing the start, stop, and parity bit
before being made available to the CPU.
The UART is capable of operating in one of two modes, 'polled' and
'interrupt driven'. The serial communications functions in the BIOS
use the polled method. In this approach, the CPU is typically in a
loop asking the UART over and over again if it has a byte ready. If
a byte is ready, the polling code returns the byte. But, if the next
byte comes in before the polling code is executing again, then that
byte is lost.
In the interrupt driven approach, when a byte is received by the
UART, an 'Interrupt Service Routine' (ISR) is executed immediately,
suspending temporarily whatever is currently executing. The ISR then
moves the byte from the UART to a buffer so that the application
program can later read it.
The 16550 can be programmed so that a receive (RX) interrupt is not
triggered until 4 (or 8 or 14) bytes have been received, while the
16650 can be triggered at up to 30 bytes, and the 16750 can be
triggered at up to 56 bytes. This can significantly reduce the CPU
processing time, since 14 (or 30 or 56) bytes can be moved at once.
Transmitted bytes are queued up awaiting transmission. When a byte
is moved from the UART transmitter holding register to the UART
transmitter shift register, an interrupt is generated and the next
byte is taken from the transmitter buffer by the ISR and written to
the UART holding register.
Up to 16 bytes can be written at once to the transmitter FIFO buffer
while processing one transmitter interrupt if an 16550 UART is used,
while the 16650 can write up to 32 bytes at once, and the 16750 can
write up to 64 bytes at once.
RS-232 Serial Communications Page 4
1.3 RS-232 Signals
RS-232 is the name of the serial data interface standard used to
connect computers to modems.
A summary of the serial port pins and their function follows. For
more detailed information, refer to one of the many books dealing
with RS-232 interfacing.
Signal Ground Pin 7 (DB25), Pin 5 (DB9)
The SG line is used as the common signal ground, and must always be
connected.
Transmit Data Pin 2 (DB25), Pin 3 (DB9)
The TX line is used to carry data from the computer to the serial
device.
Receive Data Pin 3 (DB25), Pin 2 (DB9)
The RX line is used to carry data from the serial device to the
computer.
Data Terminal Ready Pin 20 (DB25), Pin 4 (DB9)
The DTR line is used by the computer to signal the serial device that
it is ready. DTR should be set high when talking to a modem.
Data Set Ready Pin 6 (DB25), Pin 6 (DB9)
The DSR line is used by the serial device to signal the computer that
it is ready.
Request to Send Pin 4 (DB25), Pin 7 (DB9)
The RTS line is used to 'turn the line around' in half duplex modems,
and for hardware flow control in most modems that require flow
control. RTS is controlled by the computer and read by the serial
device (modem).
Clear to Send Pin 5 (DB25), Pin 8 (DB9)
The CTS line is used to 'turn the line around' in half duplex modems,
and for hardware flow control in most modems that require flow
control. CTS is controlled by the serial device (modem) and read by
the computer.
Data Carrier Detect Pin 8 (DB25), Pin 1 (DB9)
The DCD line is used by the modem to signal the computer that a data
carrier signal is present.
Ring Indicator Pin 22 (DB25), Pin 9 (DB9)
The RI line is asserted when a 'ring' occurs.
RS-232 Serial Communications Page 5
1.4 UART Registers
Data sheets can be obtained from the following sources on the
Internet.
16550 www.national.com and www.exar.com
16650 www.exar.com
16750 www.ti.com
These UARTs consists of 8 register ports as follows:
Offset R/W Register
0 R/W Receiver (read) / Transmitter (write)
1 R/W Interrupt Enable Register (IER)
2 R Interrupt Identification Register (IIR)
2 W FIFO Control Register (FCR : 16550/650/750)
2 R/W Enhanced Features Register (EFR : 16650 Only)
3 R/W Line Control Register (LCR)
4 R/W Modem Control Register (MCR)
5 R/W Line Status Register (LSR)
6 R/W Modem Status Register (MSR)
7 R/W Scratch register. Not used.
For the standard PC ports, the UART registers are based at 3F8h
(COM1), 2F8h (COM2), 3E8h (COM3), and 2E8h (COM4). COM1 and COM3
share interrupt request line IRQ4 while COM2 and COM4 share request
line IRQ3. This means that COM1 and COM3 can't be used concurrently.
Similarly for COM2 and COM4.
Four sources of interrupts are possible. (1) receiver error or BREAK,
(2) receiver data ready, (3) ready to transmit, and (4) RS-232 input.
Additional sources can be generated by the 16650 (see 16650 spec
sheet).
These four sources of interrupts are summarized as follows:
Source of Interrupt Action Required to Clear
Receiver error or BREAK. Read Line Status register.
Receiver data. Read data from data register.
Transmitter Buffer Empty. Write to data register or read IID reg.
RS-232 input. Read Modem Status register.
Serial ports are configured as either Data Communications Equipment
(DCE) or Data Terminal Equipment (DTE). Modems are always configured
as DCE, while serial printers are (almost) always configured as DTE.
Most serial (computer) ports are designed to talk to modems and are
therefore configured as DTE. Serial (computer) ports designed to talk
to serial printers (rare today) are configured as DCE. Most other
serial device are configured as DCE.
A normal RS-232 cable is used to connect two serial ports with
opposite configuration (DTE & DCE), while a null modem cable is used
to connect two serial ports of the same configuration (both DTE or
both DCE).
RS-232 Serial Communications Page 6
1.5 Register Summary
REG 0 : Data Register
Reading from the data register fetches the next input byte, once it
is ready. Writing to the data register transmits the byte written to
it over the serial line.
REG 1 : Interrupt Enable Register (IER)
The Interrupt Enable register enables each of four types of
interrupts when the appropriate bit is set to a one.
bit 3 : Enable interrupt on RS-232 input.
bit 2 : Enable interrupt on receiver error or break.
bit 1 : Enable interrupt on transmitter buffer empty (TBE).
bit 0 : Enable interrupt on received data (RxRDY).
REG 2 : Interrupt Identification Register (IID)
Reading the Interrupt Identification (read only) register once an
interrupt has occurred identifies the interrupt as follows:
Bit 2 Bit 1 Bit 0 Priority Interrupt
0 0 1 none none
1 1 0 0 (high) Serialization or break.
1 0 0 1 Received data.
0 1 0 2 Transmitter Buffer Empty.
0 0 0 3 (low) RS-232 Input.
REG 2 : Interrupt Identification Register (IID)
In the 16550, 16650, and 16750, REG 2 (write only) is also the FIFO
control register. Writing bits 6 & 7 will set the RX FIFO trigger
level (number of bytes received before an interrupt is generated).
Bit 7 Bit 6 16550 Trigger 16650 Trigger 16750 Trigger
0 0 1 byte 8 bytes 1 byte
0 1 4 bytes 16 bytes 16 bytes
1 0 8 bytes 24 bytes 32 bytes
1 1 14 bytes 28 bytes 56 bytes
The TX FIFO level can also be set in the 16650 by setting bits 4 & 5.
The 64-byte FIFO mode on the 16750 can be enabled by setting bit 5 in
the FCR. See the 16650 & 16750 data sheets for more details.
REG 2 : Enhanced Feature Register (EFR) [16650 ONLY]
The EFR can only be accessed after writing a BF to the LCR, after
which the advanced features on the 16650 are enabled by setting bit 4
of the EFR. For more details, see the 16650 data sheet.
RS-232 Serial Communications Page 7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -