📄 interfacing the serial - rs-232 port part1-2.htm
字号:
<CENTER>DTR </CENTER></TD>
<TD>
<CENTER>Data Terminal Ready </CENTER></TD></TR>
<TR>
<TD>
<CENTER>Pin 22 </CENTER></TD>
<TD>
<CENTER>Pin 9 </CENTER></TD>
<TD>
<CENTER>RI </CENTER></TD>
<TD>
<CENTER>Ring Indicator </CENTER></TD></TR></TBODY></TABLE><FONT size=-1>
<CENTER>Table 1 : D Type 9 Pin and D Type 25 Pin Connectors
</CENTER></FONT></CENTER>
<P></P>
<P><A name=3><FONT size=+1>Pin Functions</FONT><BR></A>
<HR>
<P></P>
<P>
<TABLE>
<TBODY>
<TR>
<TD> </TD>
<TD colSpan=2 vAlign=top><B>Abbreviation</B></TD>
<TD vAlign=top><B>Full Name</B></TD>
<TD><B>Function</B></TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>TD</TD>
<TD vAlign=top>Transmit Data</TD>
<TD>Serial Data Output (TXD)</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>RD</TD>
<TD vAlign=top>Receive Data</TD>
<TD>Serial Data Input (RXD)</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>CTS</TD>
<TD vAlign=top>Clear to Send</TD>
<TD>This line indicates that the Modem is ready to exchange
data.</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>DCD</TD>
<TD vAlign=top>Data Carrier Detect</TD>
<TD>When the modem detects a "Carrier" from the modem at the other
end of the phone line, this Line becomes active.</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>DSR</TD>
<TD vAlign=top>Data Set Ready</TD>
<TD>This tells the UART that the modem is ready to establish a
link.</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>DTR</TD>
<TD vAlign=top>Data Terminal Ready</TD>
<TD>This is the opposite to DSR. This tells the Modem that the
UART is ready to link.</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>RTS</TD>
<TD vAlign=top>Request To Send</TD>
<TD>This line informs the Modem that the UART is ready to exchange
data.</TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD vAlign=top>RI</TD>
<TD vAlign=top>Ring Indicator</TD>
<TD>Goes active when modem detects a ringing signal from the
PSTN.</TD></TR></TBODY></TABLE></P>
<P><A name=4><FONT size=+1>Null Modems</FONT>
<HR>
</A>
<P></P>
<P>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.</P>
<CENTER>
<P><IMG alt="Null Modem Connections" height=148
src="Interfacing The Serial - RS-232 Port Part1-2_files/nullmode.gif"
width=391> <BR><FONT size=-1>Figure 1 : Null Modem Wiring
Diagram</FONT></P></CENTER>
<CENTER></CENTER>
<P>Above is my preferred method of wiring a Null Modem. It only requires
3 wires (TD, RD & SG) to be wired straight through thus is more cost
effective to use with long cable runs. The theory of operation is
reasonably easy. The aim is to make to computer think it is talking to a
modem rather than another computer. Any data transmitted from the first
computer must be received by the second thus TD is connected to RD. The
second computer must have the same set-up thus RD is connected to TD.
Signal Ground (SG) must also be connected so both grounds are common to
each computer.</P>
<P>The Data Terminal Ready is looped back to Data Set Ready and Carrier
Detect on both computers. When the Data Terminal Ready is asserted
active, then the Data Set Ready and Carrier Detect immediately become
active. At this point the computer thinks the Virtual Modem to which it
is connected is ready and has detected the carrier of the other
modem.</P>
<P>All left to worry about now is the Request to Send and Clear To Send.
As both computers communicate together at the same speed, flow control
is not needed thus these two lines are also linked together on each
computer. When the computer wishes to send data, it asserts the Request
to Send high and as it's hooked together with the Clear to Send, It
immediately gets a reply that it is ok to send and does so.</P>
<P>Notice that the ring indicator is not connected to anything of each
end. This line is only used to tell the computer that there is a ringing
signal on the phone line. As we don't have a modem connected to the
phone line this is left disconnected.</P><A name=5><FONT
size=+1>LoopBack Plug</FONT>
<HR>
</A>
<P></P>
<P>
<TABLE>
<TBODY>
<TR>
<TD vAlign=top>
<CENTER>
<P><IMG alt="Loopback Plug"
src="Interfacing The Serial - RS-232 Port Part1-2_files/loopback.gif">
<BR><FONT size=-1>Figure 2 : Loopback Plug Wiring
Diagram</FONT></CENTER></P></TD>
<TD>This loopback plug can come in extremely handy when writing
Serial / RS232 Communications Programs. It has the receive and
transmit lines connected together, so that anything transmitted
out of the Serial Port is immediately received by the same port.
If you connect this to a Serial Port an load a Terminal Program,
anything you type will be immediately displayed on the screen.
This can be used with the examples later in this
tutorial.<BR><BR><I>Please note that this is not intended for use
with Diagnostic Programs and thus will probably not work. For
these programs you require a differently wired Loop Back plug
which may vary from program to program.</I>
</TD></TR></TBODY></TABLE></P>
<P><A name=6><FONT size=+1>DTE / DCE Speeds</FONT>
<HR>
</A>
<P></P>
<P>We have already talked briefly about DTE & DCE. A typical Data
Terminal Device is a computer and a typical Data Communications Device
is a Modem. Often people will talk about DTE to DCE or DCE to DCE
speeds. DTE to DCE is the speed between your modem and computer,
sometimes referred to as your terminal speed. This should run at faster
speeds than the DCE to DCE speed. DCE to DCE is the link between modems,
sometimes called the line speed. </P>
<P>Most people today will have 28.8K or 33.6K modems. Therefore we
should expect the DCE to DCE speed to be either 28.8K or 33.6K.
Considering the high speed of the modem we should expect the DTE to DCE
speed to be about 115,200 BPS.(Maximum Speed of the 16550a UART) This is
where some people often fall into a trap. The communications program
which they use have settings for DCE to DTE speeds. However they see 9.6
KBPS, 14.4 KBPS etc and think it is your modem speed. </P>
<P>Today's Modems should have Data Compression build into them. This is
very much like PK-ZIP but the software in your modem compresses and
decompresses the data. When set up correctly you can expect compression
ratios of 1:4 or even higher. 1 to 4 compression would be typical of a
text file. If we were transferring that text file at 28.8K (DCE-DCE),
then when the modem compresses it you are actually transferring 115.2
KBPS between computers and thus have a DCE-DTE speed of 115.2 KBPS. Thus
this is why the DCE-DTE should be much higher than your modem's
connection speed.</P>
<P>Some modem manufacturers quote a maximum compression ratio as 1:8.
Lets say for example its on a new 33.6 KBPS modem then we may get a
maximum 268,800 BPS transfer between modem and UART. If you only have a
16550a which can do 115,200 BPS tops, then you would be missing out on a
extra bit of performance. Buying a 16C650 should fix your problem with a
maximum transfer rate of 230,400 BPS.</P>
<P>However don't abuse your modem if you don't get these rates. These
are MAXIMUM compression ratios. In some instances if you try to send a
already compressed file, your modem can spend more time trying the
compress it, thus you get a transmission speed less than your modem's
connection speed. If this occurs try turning off your data compression.
This should be fixed on newer modems. Some files compress easier than
others thus any file which compresses easier is naturally going to have
a higher compression ratio.</P>
<P><A name=7><FONT size=+1>Flow Control</FONT>
<HR>
</A>
<P></P>
<P>So if our DTE to DCE speed is several times faster than our DCE to
DCE speed the PC can send data to your modem at 115,200 BPS. Sooner or
later data is going to get lost as buffers overflow, thus flow control
is used. Flow control has two basic varieties, Hardware or Software.</P>
<P>Software flow control, sometimes expressed as Xon/Xoff uses two
characters Xon and Xoff. Xon is normally indicated by the ASCII 17
character where as the ASCII 19 character is used for Xoff. The modem
will only have a small buffer so when the computer fills it up the modem
sends a Xoff character to tell the computer to stop sending data. Once
the modem has room for more data it then sends a Xon character and the
computer sends more data. This type of flow control has the advantage
that it doesn't require any more wires as the characters are sent via
the TD/RD lines. However on slow links each character requires 10 bits
which can slow communications down.</P>
<P>Hardware flow control is also known as RTS/CTS flow control. It uses
two wires in your serial cable rather than extra characters transmitted
in your data lines. Thus hardware flow control will not slow down
transmission times like Xon-Xoff does. When the computer wishes to send
data it takes active the Request to Send line. If the modem has room for
this data, then the modem will reply by taking active the Clear to Send
line and the computer starts sending data. If the modem does not have
the room then it will not send a Clear to Send.</P>
<P><A name=8><FONT size=+1>The UART (8250 and Compatibles)</FONT>
<HR>
</A>
<P></P>
<P>UART stands for Universal Asynchronous Receiver / Transmitter. Its
the little box of tricks found on your serial card which plays the
little games with your modem or other connected devices. Most cards will
have the UART's integrated into other chips which may also control your
parallel port, games port, floppy or hard disk drives and are typically
surface mount devices. The 8250 series, which includes the 16450, 16550,
16650, & 16750 UARTS are the most commonly found type in your PC.
Later we will look at other types which can be used in your homemade
devices and projects. </P>
<CENTER>
<P><IMG alt="Pin Diagrams of UARTs - 16550, 16450 & 8250" height=293
src="Interfacing The Serial - RS-232 Port Part1-2_files/uart.gif"
width=520> <BR><FONT size=-1>Figure 3 : Pin Diagrams for 16550, 16450
& 8250 UARTs</FONT></P></CENTER>
<P>The 16550 is chip compatible with the 8250 & 16450. The only two
differences are pins 24 & 29. On the 8250 Pin 24 was chip select out
which functioned only as a indicator to if the chip was active or not.
Pin 29 was not connected on the 8250/16450 UARTs. The 16550 introduced
two new pins in their place. These are Transmit Ready and Receive Ready
which can be implemented with DMA (Direct Memory Access). These Pins
have two different modes of operation. Mode 0 supports single transfer
DMA where as Mode 1 supports Multi-transfer DMA. </P>
<P>Mode 0 is also called the 16450 mode. This mode is selected when the
FIFO buffers are disabled via Bit 0 of the FIFO Control Register or When
the FIFO buffers are enabled but DMA Mode Select = 0. (Bit 3 of FCR) In
this mode RXRDY is active low when at least one character (Byte) is
present in the Receiver Buffer. RXRDY will go inactive high when no more
characters are left in the Receiver Buffer. TXRDY will be active low
when there are no characters in the Transmit Buffer. It will go inactive
high after the first character / byte is loaded into the Transmit
Buffer. </P>
<P>Mode 1 is when the FIFO buffers are active and the DMA Mode Select =
1. In Mode 1, RXRDY will go active low when the trigger level is reached
or when 16550 Time Out occurs and will return to inactive state when no
more characters are left in the FIFO. TXRDY will be active when no
characters are present in the Transmit Buffer and will go inactive when
the FIFO Transmit Buffer is completely Full. </P>
<P>All the UARTs pins are TTL compatible. That includes TD, RD, RI, DCD,
DSR, CTS, DTR and RTS which all interface into your serial plug,
typically a D-type connector. Therefore RS232 Level Converters (which we
talk about in detail later) are used. These are commonly the DS1489
Receiver and the DS1488 as the PC has +12 and -12 volt rails which can
be used by these devices. The RS232 Converters will convert the TTL
signal into RS232 Logic Levels. </P>
<CENTER>
<TABLE border=1 width="80%">
<TBODY>
<TR>
<TD width="10%">
<CENTER><B>Pin No.</B></CENTER></TD>
<TD width="15%">
<CENTER><B>Name</B></CENTER></TD>
<TD><B>Notes</B></TD></TR>
<TR>
<TD>
<CENTER>Pin 1:8</CENTER></TD>
<TD>
<CENTER>D0:D7</CENTER></TD>
<TD>Data Bus</TD></TR>
<TR>
<TD>
<CENTER>Pin 9</CENTER></TD>
<TD>
<CENTER>RCLK</CENTER></TD>
<TD>Receiver Clock Input. The frequency of this input should equal
the receivers baud rate * 16</TD></TR>
<TR>
<TD>
<CENTER>Pin 10</CENTER></TD>
<TD>
<CENTER>RD</CENTER></TD>
<TD>Receive Data</TD></TR>
<TR>
<TD>
<CENTER>Pin 11</CENTER></TD>
<TD>
<CENTER>TD</CENTER></TD>
<TD>Transmit Data</TD></TR>
<TR>
<TD>
<CENTER>Pin 12</CENTER></TD>
<TD>
<CENTER>CS0</CENTER></TD>
<TD>Chip Select 0 - Active High</TD></TR>
<TR>
<TD>
<CENTER>Pin 13</CENTER></TD>
<TD>
<CENTER>CS1</CENTER></TD>
<TD>Chip Select 1 - Active High</TD></TR>
<TR>
<TD>
<CENTER>Pin 14</CENTER></TD>
<TD>
<CENTER>nCS2</CENTER></TD>
<TD>Chip Select 2 - Active Low</TD></TR>
<TR>
<TD>
<CENTER>Pin 15</CENTER></TD>
<TD>
<CENTER>nBAUDOUT</CENTER></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -