(notes) Electronics - Interfacing the PC Serial Port (RS232).pdf

(139 KB) Pobierz
Interfacing the Serial/RS-232 Port
Interfacing the Serial / RS232 Port V5.0 http://www.senet.com.au/~cpeacock
Interfacing the Serial / RS232 Port V5.0
Disclaimer : While every effort has been made to make sure the information in this document is correct, the author can not be liable for
any damages whatsoever for loss relating to this document. Use this information at your own risk.
Table of Contents
Part 1 : Hardware (PC’s)
Page 4
Hardware Properties
Page 4
Serial Pinouts (DB25 & DB9)
Page 4
Pin Functions
Page 5
Null Modems
Page 5
Loopback Plugs
Page 6
DTE/DCE Speeds
Page 7
Flow Control
Page 7
The UART (8250’s and Compatables)
Page 8
Type of UARTS (For PC’s)
Page 10
Part 2 : Serial Port Registers (PC’s)
Page 12
Port Addresses and IRQ’s
Page 12
Table of Registers
Page 13
DLAB?
Page 14
Interrupt Enable Register (IER)
Page 15
Interrupt Identification Register (IIR)
Page 15
First In/First Out Control Register (FCR)
Page 16
Line Control Register (LCR)
Page 17
Modem Control Register (MCR)
Page 19
Line Status Register (LSR)
Page 20
Modem Status Register (MSR)
Page 21
Scratch Register
Page 21
Interfacing the Serial / RS232 Port V5.0
Page 1
71685908.002.png
Interfacing the Serial / RS232 Port V5.0 http://www.senet.com.au/~cpeacock
Part 3 : Programming (PC’s)
Page 22
Polling or Interrupt Driven?
Page 22
Termpoll.c - A Simple Comms Program using Polling
Page 22
Buff1024.c - An Interrupt Driven Comms Program
Page 24
Interrupt Vectors
Page 27
Interrupt Service Routine
Page 28
UART Configuartion
Page 30
Main Routine (Loop)
Page 31
Determining the type of UART via Software
Page 31
Part 4 : External Hardware - Interfacing Methods
Page 33
RS-232 Waveforms
Page 33
RS-232 Level Converters
Page 34
Making use of the serial format
Page 34
8250 and compatable UARTS
Page 35
CDP6402, AY-5-1015 / D36402R-9 etc UARTS
Page 36
Microcontrollers
Page 39
Interfacing the Serial / RS232 Port V5.0
Page 2
 
Interfacing the Serial / RS232 Port V5.0 http://www.senet.com.au/~cpeacock
Introduction
The Serial Port is harder to interface than the Parallel Port. In most cases, any device you connect
to the serial port will need the serial transmission converted back to parallel so that it can be used. This
can be done using a UART. On the software side of things, there are many more registers that you have
to attend to than on a Standard Parallel Port. (SPP)
So what are the advantages of using serial data transfer rather than parallel?
1. Serial Cables can be longer than Parallel cables. The serial port transmits a '1'
as -3 to -25 volts and a '0' as +3 to +25 volts where as a parallel port
transmits a '0' as 0v and a '1' as 5v. Therefore the serial port can have a
maximum swing of 50V compared to the parallel port which has a maximum
swing of 5 Volts. Therefore cable loss is not going to be as much of a
problem for serial cables than they are for parallel.
2. You don't need as many wires than parallel transmission. If your device
needs to be mounted a far distance away from the computer then 3 core cable
(Null Modem Configuration) is going to be a lot cheaper that running 19 or
25 core cable. However you must take into account the cost of the interfacing
at each end.
3. Infra Red devices have proven quite popular recently. You may of seen many
electronic diaries and palmtop computers which have infra red capabilities
build in. However could you imagine transmitting 8 bits of data at the one
time across the room and being able to (from the devices point of view)
decipher which bits are which? Therefore serial transmission is used where
one bit is sent at a time. IrDA-1 (The first infra red specifications) was
capable of 115.2k baud and was interfaced into a UART. The pulse length
however was cut down to 3/16th of a RS232 bit length to conserve power
considering these devices are mainly used on diaries, laptops and palmtops.
4. Microcontroller's have also proven to be quite popular recently. Many of
these have in built SCI (Serial Communications Interfaces) which can be
used to talk to the outside world. Serial Communication reduces the pin
count of these MPU's. Only two pins are commonly used, Transmit Data
(TXD) and Receive Data (RXD) compared with at least 8 pins if you use a 8
bit Parallel method (You may also require a Strobe).
Interfacing the Serial / RS232 Port V5.0
Page 3
71685908.003.png
Interfacing the Serial / RS232 Port V5.0 http://www.senet.com.au/~cpeacock
Part One : Hardware (PC's)
Hardware Properties
Devices which use serial cables for their communication are split into two categories. These are
DCE (Data Communications Equipment) and DTE (Data Terminal Equipment.) Data Communications
Equipment are devices such as your modem, TA adapter, plotter etc while Data Terminal Equipment is
your Computer or Terminal.
The electrical specifications of the serial port is contained in the EIA (Electronics Industry
Association) RS232C standard. It states many parameters such as -
1. A "Space" (logic 0) will be between +3 and +25 Volts.
2. A "Mark" (Logic 1) will be between -3 and -25 Volts.
3. The region between +3 and -3 volts is undefined.
4. An open circuit voltage should never exceed 25 volts. (In Reference to
GND)
5. A short circuit current should not exceed 500mA. The driver should be
able to handle this without damage. (Take note of this one!)
Above is no where near a complete list of the EIA standard. Line Capacitance, Maximum Baud
Rates etc are also included. For more information please consult the EIA RS232-E standard. It is
interesting to note however, that the RS232C standard specifies a maximum baud rate of 20,000 BPS!,
which is rather slow by today's standards. Revised standards, EIA-232D & EIA-232E were released, in
1987 & 1991 respectively.
Serial Ports come in two "sizes", There are the D-Type 25 pin connector and the D-Type 9 pin
connector both of which are male on the back of the PC, thus you will require a female connector on
your device. Below is a table of pin connections for the 9 pin and 25 pin D-Type connectors.
Serial Pinouts (D25 and D9 Connectors)
D-Type-25 Pin
No.
D-Type-9 Pin No. Abbreviation
Full Name
Pin 2
Pin 3
TD
Transmit Data
Pin 3
Pin 2
RD
Receive Data
Pin 4
Pin 7
RTS
Request To Send
Pin 5
Pin 8
CTS
Clear To Send
Interfacing the Serial / RS232 Port V5.0
Page 4
71685908.004.png
Interfacing the Serial / RS232 Port V5.0 http://www.senet.com.au/~cpeacock
Pin 6
Pin 6
DSR
Data Set Ready
Pin 7
Pin 5
SG
Signal Ground
Pin 8
Pin 1
CD
Carrier Detect
Pin 20
Pin 4
DTR
Data Terminal Ready
Pin 22
Pin 9
RI
Ring Indicator
Table 1 : D Type 9 Pin and D Type 25 Pin Connectors
Pin Functions
Abbreviation
Full Name
Function
TD
Transmit Data
Serial Data Output (TXD)
RD
Receive Data
Serial Data Input (RXD)
CTS
Clear to Send
This line indicates that the Modem is ready to exchange
data.
DCD
Data Carrier
Detect
When the modem detects a "Carrier" from the modem at
the other end of the phone line, this Line becomes active.
DSR
Data Set Ready This tells the UART that the modem is ready to establish a
link.
DTR
Data Terminal
Ready
This is the opposite to DSR. This tells the Modem that the
UART is ready to link.
RTS
Request To Send This line informs the Modem that the UART is ready to
exchange data.
RI
Ring Indicator
Goes active when modem detects a ringing signal from the
PSTN.
Null Modems
A Null Modem is used to connect two DTE's together. This is commonly used as a cheap way to
network games or to transfer files between computers using Zmodem Protocol, Xmodem Protocol etc.
This can also be used with many Microprocessor Development Systems.
Interfacing the Serial / RS232 Port V5.0
Page 5
71685908.001.png
Zgłoś jeśli naruszono regulamin