📄 interfacing the serial - rs-232 port part1-2.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)http://www.beyondlogic.org/serial/serial.htm -->
<HTML><HEAD><TITLE>Interfacing The Serial / RS-232 Port</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META
content="Describes interfacing the Serial (RS-232) Port in relation to both Hardware and Software. Gives Practical Examples using CDP6402 UART and Software Examples in C."
name=description>
<META
content="RS232, RS-232, Serial, CPD6402, AY-5-1015, 8250, 16450, 16550, 16650, 16750, UART, MAX-232, COMMS, COM Port, Serial Port, Terminal, Programming in C, Serial Programming, RS-232 Programming"
name=keywords>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR></HEAD>
<BODY
background="Interfacing The Serial - RS-232 Port Part1-2_files/bgyellow.gif"
leftMargin=0 topMargin=0 FACE="ARIAL" BASEFONT marginwidth="0" marginheight="0">
<STYLE type=text/css>#TITLEBLOCK {
COLOR: #ffffff; TEXT-DECORATION: none
}
TD {
FONT-FAMILY: Arial
}
P {
FONT-FAMILY: Arial
}
FONT {
FONT-FAMILY: Arial
}
A {
FONT-FAMILY: Arial
}
LI {
FONT-FAMILY: Arial
}
B {
FONT-FAMILY: Arial
}
PRE {
COLOR: #100080
}
TT {
COLOR: #100080
}
</STYLE>
<SCRIPT language=javascript
src="Interfacing The Serial - RS-232 Port Part1-2_files/beyondmenu.js"></SCRIPT>
<CENTER><BR><BR><FONT color=green size=5>Interfacing the Serial / RS232
Port</FONT>
<TABLE width="95%">
<TBODY>
<TR>
<TD><BR><BR>
<P>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) </P>
<P>So what are the advantages of using serial data transfer rather than
parallel? </P>
<TABLE>
<TBODY>
<TR>
<TD vAlign=top>1.</TD>
<TD>
<P>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. </P></TD></TR>
<TR>
<TD vAlign=top>2.</TD>
<TD>
<P>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. </P></TD></TR>
<TR>
<TD vAlign=top>3.</TD>
<TD>
<P>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. </P></TD></TR>
<TR>
<TD vAlign=top>4.</TD>
<TD>
<P>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). </P></TD></TR></TBODY></TABLE>
<UL></UL><A name=TOC><A>
<P>
<HR>
<I><FONT size=+2>
<CENTER>Table of Contents</CENTER></FONT></I>
<HR>
<P></P>
<P>
<CENTER><FONT size=+1><B>Part 1 : Hardware (PC's)</B></FONT><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#1">Hardware
Properties</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#2">Serial Pinouts (D25
and D9 connectors)<BR><A
href="http://www.beyondlogic.org/serial/serial.htm#3">Pin Functions
</A><BR><A href="http://www.beyondlogic.org/serial/serial.htm#4">Null
Modems </A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#5">Loopback
Plugs</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#6">DTE/DCE
Speeds</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#7">Flow Control
</A><BR><A href="http://www.beyondlogic.org/serial/serial.htm#8">The UART
(8250's and Compatibles) </A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#9">Type of UARTS (For
PC's) </A><BR><FONT size=+1><B>Part 2 : Serial Ports' Registers
(PC's)</B></FONT><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#12">Port Addresses and
IRQ's</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#13">Table of
Registers</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#14">DLAB ? </A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#15">Interrupt Enable
Register (IER)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#16">Interrupt
Identification Register (IIR)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#17">First In / First
Out Control Register (FCR)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#18">Line Control
Register (LCR)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#19">Modem Control
Register (MCR)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#20">Line Status
Register (LSR)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#21">Modem Status
Register (MSR)</A><BR><A
href="http://www.beyondlogic.org/serial/serial.htm#22">Scratch
Register</A><BR><FONT size=+1><B>Part 3 : Programming
(PC's)</B></FONT><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#30">Polling or
Interrupt Driven?</A><BR><A
href="http://www.beyondlogic.org/serial/termpoll.c">Source Code -
Termpoll.c (Polling Version)</A><BR><A
href="http://www.beyondlogic.org/serial/buff1024.c">Source Code -
Buff1024.c (ISR Version) </A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#31">Interrupt
Vectors</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#32">Interrupt Service
Routine</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#33">UART
Configuration</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#34">Main Routine
(Loop)</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#35">Determining the
type of UART via Software</A><BR><FONT size=+1><B>Part 4 : External
Hardware - Interfacing Methods</B></FONT><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#40">RS-232
Waveforms</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#41">RS-232 Level
Converters</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#42">Making use of the
Serial Format</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#43">8250 and
compatable UART's</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#44">CDP6402, AY-5-1015
/ D36402R-9 etc UARTs</A><BR><A
href="http://www.beyondlogic.org/serial/serial1.htm#46">Microcontrollers</A><BR>
<P></P></CENTER><A name=part1></A>
<HR width="100%">
<I><FONT size=+2>Part One : Hardware (PC's)</FONT></I>
<HR width="100%">
<P></P>
<UL>
<P><A name=1><FONT size=+1>Hardware Properties</FONT>
<HR>
</A>
<P></P>
<P>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. </P>
<P>The electrical specifications of the serial port is contained in the
EIA (Electronics Industry Association) RS232C standard. It states many
parameters such as - </P>
<CENTER>
<TABLE width="80%">
<TBODY>
<TR>
<TD vAlign=top>1.</TD>
<TD>A "Space" (logic 0) will be between +3 and +25 Volts. </TD></TR>
<TR>
<TD vAlign=top>2.</TD>
<TD>A "Mark" (Logic 1) will be between -3 and -25 Volts. </TD></TR>
<TR>
<TD vAlign=top>3.</TD>
<TD>The region between +3 and -3 volts is undefined. </TD></TR>
<TR>
<TD vAlign=top>4.</TD>
<TD>An open circuit voltage should never exceed 25 volts. (In
Reference to GND) </TD></TR>
<TR>
<TD vAlign=top>5.</TD>
<TD>A short circuit current should not exceed 500mA. The driver
should be able to handle this without damage. (Take note of this
one!) </TD></TR></TBODY></TABLE></CENTER>
<P>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-C 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. A new
standard, RS-232D has been recently released. </P>
<P>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. </P>
<P><A name=2><FONT size=+1>Serial Pinouts (D25 and D9
Connectors)</FONT><BR>
<HR>
</A>
<P></P>
<P>
<CENTER>
<TABLE border=1 width="80%">
<TBODY>
<TR>
<TD width="25%">
<CENTER><B>D-Type-25 Pin No. </B></CENTER></TD>
<TD width="25%">
<CENTER><B>D-Type-9 Pin No. </B></CENTER></TD>
<TD width="20%">
<CENTER><B>Abbreviation</B></CENTER></TD>
<TD width="30%">
<CENTER><B>Full Name </B></CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 2 </CENTER></TD>
<TD>
<CENTER>Pin 3 </CENTER></TD>
<TD>
<CENTER>TD </CENTER></TD>
<TD>
<CENTER>Transmit Data </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 3 </CENTER></TD>
<TD>
<CENTER>Pin 2 </CENTER></TD>
<TD>
<CENTER>RD </CENTER></TD>
<TD>
<CENTER>Receive Data </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 4 </CENTER></TD>
<TD>
<CENTER>Pin 7 </CENTER></TD>
<TD>
<CENTER>RTS </CENTER></TD>
<TD>
<CENTER>Request To Send </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 5 </CENTER></TD>
<TD>
<CENTER>Pin 8 </CENTER></TD>
<TD>
<CENTER>CTS </CENTER></TD>
<TD>
<CENTER>Clear To Send </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 6 </CENTER></TD>
<TD>
<CENTER>Pin 6 </CENTER></TD>
<TD>
<CENTER>DSR </CENTER></TD>
<TD>
<CENTER>Data Set Ready </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 7 </CENTER></TD>
<TD>
<CENTER>Pin 5 </CENTER></TD>
<TD>
<CENTER>SG </CENTER></TD>
<TD>
<CENTER>Signal Ground </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 8 </CENTER></TD>
<TD>
<CENTER>Pin 1 </CENTER></TD>
<TD>
<CENTER>CD </CENTER></TD>
<TD>
<CENTER>Carrier Detect </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 20 </CENTER></TD>
<TD>
<CENTER>Pin 4 </CENTER></TD>
<TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -