home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / ibm / pc / 1108 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  32.7 KB

  1. Xref: sparky comp.sys.ibm.pc:1108 comp.sys.ibm.pc.programmer:802 comp.sys.ibm.pc.hardware:37049
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!sbusol.rz.uni-sb.de!coli.uni-sb.de!sbustd!chbl
  3. From: chbl@sbustd.rz.uni-sb.de (Christian Blum)
  4. Newsgroups: comp.sys.ibm.pc,comp.sys.ibm.pc.programmer,comp.sys.ibm.pc.hardware
  5. Subject: FAQ serial port (part one)
  6. Date: 25 Jan 1993 10:03:50 GMT
  7. Organization: Studenten-Mail, Rechenzentrum Universitaet des Saarlandes
  8. Lines: 757
  9. Message-ID: <1k0du6INNgkv@coli-gate.coli.uni-sb.de>
  10. NNTP-Posting-Host: sbustd.stud.uni-sb.de
  11.  
  12.  
  13.   This is a FAQ answer on serial communications using the TTY protocol. It
  14. contains information on the TTY protocol and hardware and software implemen-
  15. tations on IBM PCs which is derived from National Semiconductor data sheets
  16. and practical experience of the author and his supporters.
  17.   If you want to contribute to this FAQ in any way, please email me (probably
  18. by replying to this posting). My email address is: chbl@stud.uni-sb.de
  19.   See the end for details.
  20.   It's the second publication of this file. Lots of errors have been
  21. removed, and lots of information has been added (which has surely brought
  22. other errors with it, see Murphy's Law).
  23.  
  24.  
  25. PART ONE - HARDWARE & SOFTWARE
  26.  
  27.  
  28. Acknowledgements
  29. ================
  30.  
  31.   The following persons have contributed (directly or indirectly :-) to this
  32. summary:
  33.       Madis Kaal <mast@anubis.kbfi.ee ??>     this address is known to be bad
  34.       Steve Poulsen <stevep@ims.com>
  35.       Scott C. Sadow <NS16550A@mycro.UUCP>
  36.       Dan Norstedt <?>
  37.         [Commercial: This line could display YOUR name!]
  38.  
  39.  
  40.  
  41. Introduction
  42. ============
  43.  
  44.   One of the most universal parts of the PC is its serial port. You can
  45. connect a mouse, a modem, a printer, a plotter, another PC, ...
  46.   But its usage (both software and hardware) is one of the best-kept secrets
  47. for most users, besides that it is not difficult to understand how to
  48. connect (not plug-in) devices to it and how to program it.
  49.   Regard this FAQ as a manual of the serial port of your PC for both
  50. hardware and software.
  51.  
  52.  
  53. Historical summary
  54. ------------------
  55.  
  56.   In early days of telecommunications, errand-boys and optical signals (flags,
  57. lights, clouds of smoke) were the only methods of transmitting information
  58. across long distances. With increasing requirements on speed and growing
  59. amount of information, more practical methods were developed. One milestone
  60. was the first wire-bound transmission on May 24th, 1844 ("What hath God
  61. wrought", using the famous Morse-alphabet). Well, technology improved a bit,
  62. and soon there were machines that could be used like typewriters, except that
  63. you typed not only on your own piece of paper but also on somebody elses.
  64. The only thing that has changed on the step from the teletyper to your PC
  65. is speed.
  66.  
  67.  
  68. The TTY (teletyping) protocol
  69. -----------------------------
  70.  
  71.   Definition: A protocol is a clear description of the LOGICAL method of
  72. transmitting information. This does NOT include physical realisation.
  73.  
  74.   The TTYp uses two different states of the line called 'mark' and 'space'.
  75. If no data is transmitted, the line is in the 'space' state. Data looks
  76. like
  77.  
  78.       space  ----------+   +-------+   +---+   +-------
  79.                        |   |       |   |   |   |
  80.       mark             +---+       +---+   +---+
  81.  
  82.                         (1)  --------(2)-------- (3)
  83.  
  84.   (1) start bit   (2) data bits   (3) stop bit(s)
  85.  
  86.   Both transmitter (TX) and receiver (RX) use the same data rate (measured
  87. in baud, which is the reciprocal value of the smallest time interval between
  88. two changes of the line state. TX and RX know about the number of data
  89. bits (probably with a parity bit added), and both know about the size of
  90. the stop step (called the stop bit or the stop bits, depending on the size
  91. of the stop step; normally 1, 1.5 or 2 times the size of a data bit). Data
  92. is transmitted bit-synchroneously and word-asynchroneously, which means that
  93. the size of the bits, the length of the word etc.pp. is clearly defined
  94. but the time between two words is undefined.
  95.   The start bit indicates the beginning of a new data word. It is used to
  96. synchronize transmitter and receiver.
  97.   Data is transmitted LSB to MSB, which means that the least significant
  98. bit (Bit 0) is transmitted first with 4 to 7 bits of data following, re-
  99. sulting in 5 to 8 bits of data. A logical '0' is transmitted by the
  100. 'space' state of the line, a logical '1' by 'mark'.
  101.   A parity bit can be added to the data bits to allow error detection.
  102. There are two (well, actually five) kinds of parity: odd and even (plus
  103. none, mark and space). Odd parity means that the number of 'mark' steps in
  104. the data word (including parity bit) is always odd, so the parity bit is
  105. set accordingly (I don't have to explain 'even' parity, must I?). It is
  106. also possible to set the parity bit to a fixed state or to omit it.
  107.   The stop bit does not indicate the end of the word (as it could be
  108. derived from its name); it rather separates two consecutive words by
  109. putting the line into the 'space' state for a minimum time.
  110.   The protocol is usually described by a sequence of numbers and letters,
  111. e.g. 8n1 means 1 start bit (always), 8 bits of data, no parity bit, 1 stop
  112. bit. 7e2 would indicate 7 bits of data, even parity, 2 stop bits (but I've
  113. never seen this one...). The usual thing is 8n1 or 7e1.
  114.   Early teletypers used the neckbreaking speed of 50 baud (which means
  115. that one step is 20ms), 5 bits of data, no parity and 1.5 stop bits (don't
  116. ask me why!). Your PC is capable of serial transmission at up to 115,200
  117. baud (step size of 8.68 microseconds!). Typical rates are 300 baud, 1200 baud,
  118. 2400 baud and 9600 baud.
  119.  
  120.  
  121. The physical transmission
  122. -------------------------
  123.  
  124.   Teletypers used a closed-loop line with a space current of 20ma and a
  125. mark current of 0ma (typical), which allowed to detect a 'broken line'.
  126. The RS232C port of your PC uses voltages rather than currents to indicate
  127. logical states: 'space' is signaled by +3v to +15v (typically +12v), 'mark'
  128. by -3v to -15v (typically -12V). The typical output impedance of the serial
  129. port of a PC is 2 kiloohms (resulting in about 5ma @ 10v), the typical input
  130. impedance is about 4.3 kiloohms, so there should be a maximum fan-out of 5
  131. (5 inputs can be connected to 1 output). Please don't rely on this, it may
  132. differ from PC to PC.
  133.   Three lines (RX, TX & ground) are needed.
  134.  
  135. Q. Why does my PC have a 25pin/9pin connector if there are only 3 lines
  136.    needed?
  137. A. There are several status lines that are only used with a modem. See the
  138.    software section of this FAQ.
  139.  
  140. Q. How can I easily connect two PCs by a three-wire lead?
  141. A. This connection is called a 'null-modem' connection. RX1 is connected
  142.    to TX2 and vice versa, GND1 to GND2. In addition to this, connect RTS
  143.    to CTS & DCD and DTR to DSR (modem software often relies on that). See
  144.    the hardware section for further details.
  145.  
  146.  
  147. Hardware
  148. ========
  149.  
  150.  
  151. The connectors
  152. --------------
  153.  
  154.   PCs have 9pin/25pin male SUB-D connectors. The pin layout is as follows
  155. (looking at the back side of your PC):
  156.  
  157.         1                         13         1           5
  158.       _______________________________      _______________
  159.       \  . . . . . . . . . . . . .  /      \  . . . . .  /
  160.        \  . . . . . . . . . . . .  /        \  . . . .  /
  161.         ---------------------------          -----------
  162.         14                      25            6       9
  163.  
  164.  Name (V24)  25pin  9pin  Dir  Full name               Remarks
  165. --------------------------------------------------------------------------
  166.     TxD         2     2    o   Transmit Data
  167.     RxD         3     3    i   Receive Data
  168.     RTS         4     5    o   Request To Send
  169.     CTS         5     8    i   Clear To Send
  170.     DTR        20     4    o   Data Terminal Ready
  171.     DSR         6     6    i   Data Set Ready
  172.     RI         22     9    i   Ring Indicator
  173.     DCD         8     1    i   Data Carrier Detect
  174.     GND         7     5    -   Signal ground
  175.      -          1     -    -   Protective ground       Don't use this one!
  176.     SCTE       24     -    -   Sync. clock trans. end  Several PCs only
  177.     SCT        15     -    o   Sync. clock TX          dito.
  178.     SCR        17     -    i   Sync. clock RX          dito.
  179.  
  180.   The most important lines are RxD, TxD, and GND. Others are used with
  181. modems, printers and plotters to indicate internal states or to use
  182. synchroneous transmission (this is rarely used, and most PCs don't support
  183. it).
  184.   '0' means +3v to +15V, '1' means -3v to -15v. '1' is the active state.
  185.  
  186.   The lines are:
  187.  
  188.   RxD, TxD: These lines carry the data.
  189.   RTS, CTS: Are used by the PC and the modem/printer/whatsoever (further
  190.     on referred to as the data set) to start/stop a communication. The PC
  191.     sets RTS to its active state ('1'), and the data set responds with CTS
  192.     '1' (always in this order). If the data set wants to stop/interrupt the
  193.     communication (e.g. buffer overflow), it drops CTS to '0'; the PC uses
  194.     RTS to control the data flow.
  195.   DTR, DSR: Are used to establish a connection at the very beginning, i.e.
  196.     the PC and the data set 'shake hands' first to assure they are both
  197.     present. The PC sets DTR to '1', and the data set answers with DSR
  198.     '1'. Modems often indicate hang-up by resetting DSR to '0'.
  199.   (These six lines plus GND are often referred to as '7 wire'-connection or
  200.   'hand shake'-connection.)
  201.   DCD: The modem uses this line to indicate that it has detected the
  202.     carrier of the modem on the other side of the line.
  203.   RI: The modem uses this line to signal that 'the phone rings' (even if
  204.     there isn't a bell fitted to your modem).
  205.   SCTE, SCT, SCR: forget about these.
  206.   Protective ground: This line is connected to the power ground of the
  207.     serial adapter. It should not be used as a signal ground, and it
  208.     MUST NOT be connected to GND (even if your DMM shows up a
  209.     connection!). Connect this line to the screen of the lead (if there is
  210.     one).
  211.  
  212.   Technical data (typical):
  213.  
  214.     Signal level: -10.5v/+11v
  215.     Short circuit current: 6.8ma  (yes, that's enough for your mouse!)
  216.     Output impedance: 2 kiloohms
  217.     Input impedance: 4.3 kiloohms
  218.  
  219.  
  220. Connecting devices
  221. ------------------
  222.  
  223.   Normally, a 7 wire connection is used. Connect:
  224.         GND1    to    GND2
  225.     RxD1    to    TxD2
  226.     TxD1    to    RxD2
  227.     DTR1    to    DSR2
  228.     DSR1    to    DTR2
  229.     RTS1    to    CTS2
  230.     CTS1    to    RTS2
  231.   If a modem is connected, add lines for the following:
  232.         RI, DCD
  233.   If software wants it, connect DCD1 to CTS1 and DCD2 to CTS2.
  234.   BEWARE! While PCs use pin 2 for RxD and pin 3 for TxD, modems normally
  235. have those pins reversed! This allows to easily connect pin1 to pin1, pin2
  236. to pin 2 etc. If you connect two PCs, cross RxD and TxD.
  237.  
  238.   If hardware handshaking is not needed, a so-called null-modem connection
  239. can be used. Connect:
  240.         GND1    to    GND2
  241.     RxD1    to    TxD2
  242.     TxD1    to    RxD2
  243. Additionally, connect (if software needs it):
  244.         RTS1    to    CTS1 & DCD1
  245.     RTS2    to    CTS2 & DCD2
  246.     DTR1    to    DSR1
  247.     DTR2    to    DSR2
  248. You won't need long wires for these!
  249.   The null-modem connection is used to establish an XON/XOFF-transmission
  250. between two PCs (see software section for details).
  251.   Remember: the names DTR, DSR, CTS & RTS refer to the lines as seen from
  252. the PC. This means that for your data set DTR & RTS are incoming signals
  253. and DSR & CTS are outputs!
  254.  
  255.  
  256. Base addresses & interrupts
  257. ---------------------------
  258.  
  259.   Normally, the following list is correct:
  260.  
  261.  
  262.     Port     Base address    Int #
  263.  
  264.     COM1         0x3F8        0xC
  265.     COM2         0x2F8        0xB
  266.     COM3         0x3E8        0xC
  267.     COM4         0x2E8        0xB
  268.  
  269.  
  270.   In PCs, serial communication is realized with a set of three chips
  271. (there are no further components needed!): a UART (Universal Asynchroneous
  272. Receiver/Transmitter) and two line drivers. Normally, the 82450/16450/8250
  273. does the 'brain work' while the 1488 and 1489 drive the lines. 
  274.   The chips are produced by many manufacturers; it's of no importance
  275. which letters are printed in front of the numbers (mostly NS for National
  276. Semiconductor). Don't regard the letters behind the number also; they just
  277. indicate special features and packaging (Advanced, FIFO, New, MILitary,
  278. bug fixes [see below] etc.).
  279.   You might have heard of the possibility to replace the 16450 by a 16550A
  280. to improve reliability and software throughput. This is only useful if your
  281. software is able to use the FIFO (first in-first out) buffer features. The
  282. chips are fully pin-compatible except for two pins that are not used by
  283. any board known to the author: pin 24 (CSOUT, chip select out) and pin 29
  284. (NC, no connection to be made). With the 16550A, pin 24 is -TXRDY and pin
  285. 29 is -RXRDY, signals that aren't needed and that even won't care if they
  286. are shorted to +5v or ground. Therefore it should always be possible to
  287. simply replace the 16450 by the 16550A - even if it's not always useful due
  288. to lacking software capabilities. IT IS DEFINITELY NOT NECESSARY FOR
  289. COMMUNICATION UP TO LOUSY 9600 BAUD! These rates can easily be handled by
  290. any CPU and the interrupt-driven communication won't slow down the computer
  291. substantially. But if you want to use high-speed transfer with or without
  292. using the interrupt features (i.e. by 'polling'), it is recommended to use
  293. the 16550A in order to make transmission more reliable if your software
  294. supports it (see excursion some pages below).
  295.  
  296.  
  297. How to detect which chip is used
  298. --------------------------------
  299.  
  300.   This is really not difficult. The 8250 has no scratch register (see data
  301. sheet info below), the 16450/82450 has no FIFO, the 16550 has no working
  302. FIFO :-) and the 16550A performs alright. See the software section for
  303. an example.
  304.  
  305.  
  306. Data sheet information
  307. ----------------------
  308.  
  309.   Some hardware information taken from the data sheet of National
  310. Semiconductor (shortened and commented):
  311.  
  312.   Pin description of the 16450(16550A) [Dual-In-Line package]:
  313.  
  314.                    +-----+ +-----+
  315.                D0 -|  1  +-+   40|- VCC
  316.                D1 -|  2        39|- -RI
  317.                D2 -|  3        38|- -DCD
  318.                D3 -|  4        37|- -DSR
  319.                D4 -|  5        36|- -CTS
  320.                D5 -|  6        35|- MR
  321.                D6 -|  7        34|- -OUT1
  322.                D7 -|  8        33|- -DTR
  323.              RCLK -|  9        32|- -RTS
  324.               SIN -| 10        31|- -OUT2
  325.              SOUT -| 11        30|- INTR
  326.               CS0 -| 12        29|- NC (-RXRDY)
  327.               CS1 -| 13        28|- A0
  328.              -CS2 -| 14        27|- A1
  329.          -BAUDOUT -| 15        26|- A2
  330.               XIN -| 16        25|- -ADS
  331.              XOUT -| 17        24|- CSOUT (-TXRDY)
  332.               -WR -| 18        23|- DDIS
  333.                WR -| 19        22|- RD
  334.               VSS -| 20        21|- -RD
  335.                    +-------------+
  336.  
  337. A0, A1, A2, Register Select, Pins 26-28:
  338. Address signals connected to these 3 inputs select a UART register for
  339. the CPU to read from or to write to during data transfer. A table of
  340. registers and their addresses is shown below. Note that the state of the
  341. Divisor Latch Access Bit (DLAB), which is the most significant bit of the
  342. Line Control Register, affects the selection of certain UART registers.
  343. The DLAB must be set high by the system software to access the Baud
  344. Generator Divisor Latches.
  345.  
  346.   DLAB  A2  A1  A0    Register
  347.     0    0   0   0    Receive Buffer (read) Transmitter Holding Reg. (write)
  348.     0    0   0   1    Interrupt Enable
  349.     x    0   1   0    Interrupt Identification (read)
  350.     x    0   1   0    FIFO Control (write) (undefined on the 16450. CB)
  351.     x    0   1   1    Line Control
  352.     x    1   0   0    Modem Control
  353.     x    1   0   1    Line Status
  354.     x    1   1   0    Modem Status
  355.     x    1   1   1    Scratch (special use on some boards. CB)
  356.     1    0   0   0    Divisor Latch (LSB)
  357.     1    0   0   1    Divisor Latch (MSB)
  358.  
  359. -ADS, Address Strobe, Pin 25: The positive edge of an active Address
  360. Strobe (-ADS) signal latches the Register Select (A0, A1, A2) and Chip
  361. Select (CS0, CS1, -CS2) signals.
  362. Note: An active -ADS input is required when Register Select and Chip
  363. Select signals are not stable for the duration of a read or write
  364. operation. If not required, tie the -ADS input permanently low. (As it is
  365. done in your PC. CB)
  366.  
  367. -BAUDOUT, Baud Out, Pin 15: This is the 16 x clock signal from the
  368. transmitter section of the UART. The clock rate is equal to the main
  369. reference oscillator frequency divided by the specified divisor in the
  370. Baud Generator Divisor Latches. The -BAUDOUT may also be used for the
  371. receiver section by tying this output to the RCLK input of the chip. (Yep,
  372. that's true for your PC. CB).
  373.  
  374. CS0, CS1, -CS2, Chip Select, Pins 12-14: When CS0 and CS1 are high and CS2
  375. is low, the chip is selected. This enables communication between the UART
  376. and the CPU.
  377.  
  378. -CTS, Clear To Send, Pin 36: When low, this indicates that the modem or
  379. data set is ready to exchange data. This signal can be tested by reading
  380. bit 4 of the MSR. Bit 4 is the complement of this signal, and Bit 0 is '1'
  381. if -CTS has changed state since the previous reading (bit0=1 generates an
  382. interrupt if the modem status interrupt has been enabled).
  383.  
  384. D0-D7, Data Bus, Pins 1-8: Connected to the data bus of the CPU.
  385.  
  386. -DCD, Data Carrier Detect, Pin 38: blah blah blah, can be tested by
  387. reading bit 7 / bit 3 of the MSR. Same text as -CTS.
  388.  
  389. DDIS, Driver Disable, Pin 23: This goes low whenever the CPU is reading
  390. data from the UART.
  391.  
  392. -DSR, Data Set Ready, Pin 37: blah, blah, blah, bit 5 / bit 1 of MSR.
  393.  
  394. -DTR, Data Terminal Ready, Pin 33: can be set active low by programming
  395. bit 0 of the MCR '1'. Loop mode operation holds this signal in its
  396. inactive state.
  397.  
  398. INTR, Interrupt, Pin 30: goes high when an interrupt is requested by the
  399. UART. Reset low by the MR.
  400.  
  401. MR, Master Reset, Pin 35: Schmitt Trigger input, resets internal registers
  402. to their initial values (see below).
  403.  
  404. -OUT1, Out 1, Pin 34: user-designated output, can be set low by
  405. programming bit 2 of the MCR '1' and vice versa. Loop mode operation holds
  406. this signal inactive high.
  407.  
  408. -OUT2, Out 2, Pin 31: blah blah blah, bit 3. (Used in your PC to connect
  409. the UART to the interrupt line of the slot when '1'. CB)
  410.  
  411. RCLK, Receiver Clock, Pin 9: This input is the 16 x baud rate clock for
  412. the receiver section of the chip. (Normally connected to -BAUDOUT, as in
  413. your PC. CB)
  414.  
  415. RD, -RD, Read, Pins 22 and 21: When Rd is high *or* -RD is low while the
  416. chip is selected, the CPU can read data from the UART. (One of these is
  417. normally tied. CB)
  418.  
  419. -RI, Ring Indicator, Pin 39: blah blah blah, Bit 6 / Bit 2 of the MSR.
  420. (Bit 2 indicates only change from active low to inactive high! Curious,
  421. isn't it? CB)
  422.  
  423. -RTS, Request To Send, Pin 32: blah blah blah, see DTR (Bit 1).
  424.  
  425. SIN, Serial Input, Pin 10.
  426.  
  427. SOUT, Serial Output, Pin 11: ... Set to 'space' (high) upon MR.
  428.  
  429. -RXRDY, -TYRDY: refer to NS data sheet. Those pins are used for DMA
  430. channeling. Since they are not connected in your PC, I won't describe them
  431. here.
  432.  
  433. VCC, Pin 40, +5v
  434.  
  435. VSS, Pin 20, GND
  436.  
  437. WR, -WR: same as Rd, -RD for writing data.
  438.  
  439. XIN, XOUT, Pins 16 and 17: Connect a crystal here (1.5k betw. xtal & pin 17)
  440. and pin 16 with a capacitor of approx. 20p to GND and other xtal conn. 40p
  441. to GND. Resistor of approx. 1meg parallel to xtal. Or use pin 16 as an input
  442. and pin 17 as an output for an external clock signal.
  443.  
  444.  
  445. Absolute Maximum Ratings:
  446.  
  447.   Temperature under bias: 0 C to +70 C
  448.   Storage Temperature: -65 C to 150 C
  449.   All input or output voltages with respect to VSS: -0.5v to +7.0v
  450.   Power dissipation: 1W
  451.  
  452. Further electrical characteristics see the very good data sheet of NS.
  453.  
  454. UART Reset Configuration
  455.  
  456. Register/Signal        Reset Control      Reset State
  457. --------------------------------------------------------------------
  458.   IER                       MR            0000 0000
  459.   IIR                       MR            0000 0001
  460.   FCR                       MR            0000 0000
  461.   LCR                       MR            0000 0000
  462.   MCR                       MR            0000 0000
  463.   LSR                       MR            0110 0000
  464.   MSR                       MR            xxxx 0000 (according to signals)
  465.   SOUT                      MR            high
  466.   INTR (RCVR errs)     Read LSR/MR        low
  467.   INTR (data ready)    Read RBR/MR        low
  468.   INTR (THRE)          Rd IIR/Wr THR/MR   low
  469.   INTR (modem status)  Read MSR/MR        low
  470.   -OUT2                     MR            high
  471.   -RTS                      MR            high
  472.   -DTR                      MR            high
  473.   -OUt1                     MR            high
  474.   RCVR FIFO           MR/FCR1&FCR0/DFCR0  all bits low
  475.   XMIT FIFO           MR/FCR1&FCR0/DFCR0  all bits low
  476.  
  477.  
  478.  
  479. Known problems with several chips
  480. ---------------------------------
  481.  
  482. (From material Madis Kaal received from Dan Norstedt)
  483.  
  484.     8250 and 8250-B:
  485.  
  486.         * These UARTs pulse the INT line after each interrupt cause has
  487.           been serviced (which none of the others do). [Generates interrupt
  488.           overhead. CB]
  489.  
  490.         * The start bit is about 1 us longer than it ought to be. [This
  491.           shouldn't be a problem. CB]
  492.  
  493.         * 5 data bits and 1.5 stop bits doesn't work.
  494.  
  495.         * When a 1 bit is written to the bit 1 (Tx int enab) in the IER,
  496.           a Tx interrupt is generated. This is an erroneous interrupt
  497.           if the THRE bit is not set. [So don't set this bit as long as
  498.           the THRE bit isn't set. CB]
  499.  
  500.         * The first valid Tx interrupt after the Tx interrupt is enabled
  501.           is probably missed. Suggested workaround:
  502.           1) Wait for the TRHE bit to become set.
  503.           2) Disable CPU interrupts.
  504.           3) Write Tx interrupt enable to the IER.
  505.           4) Write Tx interrupt enable to the IER, again.
  506.           5) Enable CPU interrupts.
  507.  
  508.         * The TSRE (bit 6) doesn't work properly.
  509.  
  510.         * If both the Rx and Tx interrupts are enabled, and a Rx interrupt
  511.           occurs, the IIR indication may be lost; Suggested workarounds:
  512.           1) Test THRE bit in the Rx routine, and either set IER bit 1
  513.              or call the Tx routine directly if it is set.
  514.           2) Test the THRE bit instead of using the IIR.
  515.  
  516.     * [If one of these chips vegetates in your PC, go get your solder
  517.           iron heated... CB]
  518.  
  519.     8250A, 82C50A, 16450 and 16C450:
  520.  
  521.         * (Same problem as above:)
  522.           If both the Rx and Tx interrupts are enabled, and a Rx interrupt
  523.           occurs, the IIR indication may be lost; Suggested workarounds:
  524.           1) Test THRE bit in the Rx routine, and either set IER bit 1
  525.              or call the Tx routine directly if it is set.
  526.           2) Test the THRE bit instead of using the IIR.
  527.       3) [Don't enable both interrupts at the same time. I've never
  528.              had any need to do this. CB]
  529.  
  530.     16550 (without the A):
  531.  
  532.         * Rx FIFO bug: Sometimes a FIFO will get extra characters.
  533.           [This seemed to be very embarracing for NS; they've added a
  534.           simple detection method in the 16550A (bit 6 of IIR). CB]
  535.  
  536. No bugs reported in the 16550A (yet?)
  537.  
  538. [Same is true for the 16C552, a two-in-one version of the 16550A. CB]
  539.  
  540.  
  541.  
  542. Software
  543. ========
  544.  
  545.  
  546.   First some information from the data sheet. Then: HOW TO USE IT.
  547.  
  548.  
  549. Register Description
  550. --------------------
  551.  
  552. See "Hardware" for addresses.
  553.  
  554. Register  Bit 0    Bit 1    Bit 2    Bit 3    Bit 4    Bit 5    Bit 6    Bit 7
  555.  
  556. RBR (r/o)  ----------------------- data bits received ------------------------
  557. THR (w/o)  ------------------ data bits to be transmitted --------------------
  558. IER       ERBFI    ETBEI    ELSI     EDSSI      0        0        0       0
  559. IIR (r/o) pending  IID0     IID1     IID2       0        0      FIFO en  FIFOen
  560. FCR (w/o) enable   RFres    XFres    DMAsel     0        0      - RX trigger -
  561. LCR       - word length -   stopbits PAR en   even sel stick par SBR     DLAB
  562. MCR       DTR      RTS      OUT1     OUT2     Loop       0        0       0
  563. LSR       RBF      OE       PE       FE       Break    THRE     TEMT    FIFOerr
  564. MSR       DCTS     DDSR     TERI     DDCD     CTS      DSR      RI      DCD
  565.  
  566. ERBFI:   Enable Receiver Buffer Full Interrupt
  567. ETBEI:   Enable Transmitter Buffer Empty Interrupt
  568. ELSI:    Enable Line Status Interrupt
  569. EDSSI:   Enable Delta Status Signals Interrupt
  570. IID#:    Interrupt IDentification
  571. RFres:   Receiver FIFO reset
  572. XFres:   Transmitter FIFO reset
  573. SBR:     Set BReak
  574. RBF:     Receiver Buffer Full (Data Available)
  575. OE:      Overrun Error
  576. PE:      Parity Error
  577. FE:      Framing Error
  578. THRE:    Transmitter Holding Register Empty (new data can be written to THR)
  579. TEMT:    Transmitter Empty (last word has been sent)
  580. DCTS:    Delta Clear To Send
  581. DDSR:    Delta Data Set Ready
  582. TERI:    Trailing Edge Ring Indicator
  583. DDCD:    Delta Data Carrier Detect
  584.  
  585. LCR (Line Control Register):
  586.  
  587.    Bit 1  Bit 0    word length         Bit 2      Stop bits
  588.      0      0        5 bits              0            1
  589.      0      1        6 bits              1          1.5/2
  590.      1      0        7 bits         (1.5 if word length is 5)
  591.      1      1        8 bits   (1.5 does not work with some chips, see above)
  592.  
  593.    Bit 5  Bit 4  Bit 3     Parity type       Bit 6   SOUT condition
  594.      x      x      0       no parity           0     normal operation
  595.      0      0      1       odd parity          1     force 'mark' (break)
  596.      0      1      1       even parity       Bit 7   DLAB
  597.      1      0      1       mark parity         0     normal registers
  598.      1      1      1       space parity        1     divisor at reg 0, 1
  599.  
  600. Baud Rate Generator:
  601.  
  602.   DLAB must be set. Write word (16 bits) to address 0 of the UART (this is
  603. the base address) to program baud rate as follows:
  604.      xtal frequency in Hz / 16 / rate = divisor
  605.   Your PC uses an xtal frequency of 1.8432 MHz.
  606.   Do *NOT* use 0 as a divisor (your maths teacher told you so)! [It
  607. results in a rate of some 1000 baud. CB]
  608.   An error of up to 5 percent is irrelevant.
  609.   Some values:
  610.  
  611.      Baud rate   Divisor (hex)   Percent Error
  612.      50          900             0.0%
  613.          75          600             0.0%
  614.         110          417             0.026%
  615.         134.5        359             0.058%
  616.         150          300             0.0%
  617.         300          180             0.0%
  618.     600           C0             0.0%
  619.        1200           60             0.0%
  620.        1800           40             0.0%
  621.        2000           3A             0.69%
  622.        2400           30             0.0%
  623.        3600           20             0.0%
  624.        4800           18             0.0%
  625.        7200           10             0.0%
  626.        9600            C             0.0%
  627.       19200            6             0.0%
  628.       38400            3             0.0%
  629.       56000            2             2.86%
  630.      115200            1             0.0%
  631.  
  632.   NS specifies that the 16550A is capable of 256 kbaud if you use a 4 MHz
  633. or an 8 MHz crystal. But a staff member of NS Germany (I know that this
  634. abbreviation is not well-chosen :-( ) told one of my friends on the phone
  635. that it runs correctly at 512 kbaud as well, but I don't know if the
  636. 1488/1489 manage this. This is true for the 16C552, too.
  637.   BTW: Ever tried 1.76 baud? Kindergarten kids write faster.
  638.   Mice typically use 2400 baud, 8n1.
  639.  
  640.  
  641. LSR (Line Status Register):
  642.  
  643.    Bit 0    Data Ready (DR). Reset by reading RBR.
  644.    Bit 1    Overrun Error (OE). Reset by reading LSR. Indicates loss of data.
  645.    Bit 2    Parity Error (PE). Indicates transmission error. Reset by LSR.
  646.    Bit 3    Framing Error (FE). Indicates missing stop bit. Reset by LSR.
  647.    Bit 4    Break Indicator (BI). Set if 'space' for more than 1 word. Reset
  648.             by LSR.
  649.    Bit 5    Transmitter Holding Register Empty (THRE). Indicates that a new
  650.             word can be written to THR. Reset by writing THR.
  651.    Bit 6    Transmitter Empty (TEMT). Indicates that no transmission is
  652.             running. Reset by reading LSR.
  653.    Bit 7    Set if at least 1 word in FIFO has been received with an error.
  654.             Cleared by reading LSR if there is no further error in the FIFO.
  655.  
  656. FCR (FIFO Control Register):
  657.  
  658.    Bit 0:   FIFO enable.
  659.    Bit 1:   Clear receiver FIFO. This bit is self-clearing.
  660.    Bit 2:   Clear transmitter FIFO. This bit is self-clearing.
  661.    Bit 3:   DMA mode (pins -RXRDY and -TXRDY), see sheet
  662.    Bits 6-7:Trigger level of the DR-interrupt.
  663.    Bit 7  Bit 6    Receiver FIFO trigger level
  664.      0      0         01
  665.      0      1         04
  666.      1      0         08
  667.      1      1         14
  668.  
  669.  
  670.    Excursion: why and how to use the FIFOs (by Scott C. Sadow)
  671.    -----------------------------------------------------------
  672.  
  673.    Normally when transmitting or receiving, the UART generates an
  674.    interrupt for every character sent or received. For 2400 baud, typically
  675.    this is 240/second. For 115,200 baud, this means 11,520/second. With FIFOs
  676.    enabled, the number of interrupts is greatly reduced. For transmit
  677.    interrupts, the UART indicates the transmit holding register is not busy
  678.    until the 16 byte FIFO is full. A transmit hold register empty interrupt
  679.    is not generated until the FIFO is empty (last byte is being sent) Thus,
  680.    the number of transmit interrupts is reduced by a factor of 16. For
  681.    115,200 baud, this means only 7,200 interrupts/second. For receive data
  682.    interrupts, the processing is similar to transmit interrupts. The main
  683.    difference is that the number of bytes in the FIFO before generating an
  684.    interrupt can be set. When the trigger level is reached, a recieve data
  685.    interrupt is generated, but any other data received is put in the FIFO.
  686.    The receive data interrupt is not cleared until the number of bytes in the
  687.    FIFO is below the trigger level.
  688.  
  689.    To add 16550A support to existing code, there are 2 requirements.
  690.  
  691.       1) When reading the IIR to determine the interrupt source, only
  692.          use the lower 3 bits.
  693.  
  694.       2) After the existing UART initialization code, try to enable the
  695.          FIFOs by writing to the FCR. (A value of C7 hex will enable FIFO mode,
  696.          clear both FIFOs, and set the receive trigger level at 14 bytes) Next,
  697.          read the IIR. If Bit 6 of the IIR is not set, the UART is not a
  698.          16550A, so write 0 to the FCR to disable FIFO mode.
  699.  
  700.  
  701. IIR (Interrupt Identification Register):
  702.  
  703.    Bit 3  Bit 2  Bit 1  Bit 0    Priority   Source    Description
  704.      0      0      0      1                 none
  705.      0      1      1      0      highest    Status    OE, PE, FE or BI of the
  706.                                                       LSR set. Serviced by
  707.                               reading the LSR.
  708.      0      1      0      0      second     Receiver  DR or trigger level rea-
  709.                                                       ched. Serviced by read-
  710.                                                       ing RBR 'til under level
  711.      1      1      0      0      second     FIFO      No Receiver FIFO action
  712.                                                       since 4 words' time
  713.                               (neither in nor out) but
  714.                               data in RX-FIFO. Serviced
  715.                               by reading RBR.
  716.      0      0      1      0      third      Transm.   THRE. Serviced by read-
  717.                                                       ing IIR (if source of
  718.                               int only!!) or writing
  719.                               to THR.
  720.      0      0      0      0      fourth     Modem     One of the delta flags
  721.                                                       in the MSR set. Serviced
  722.                                                       by reading MSR.
  723.    Bit 6 & 7: 16550A: set if FCR bit 0 set.
  724.               16550:  bit 7 set, bit 6 cleared
  725.           others: clear
  726.    In most software applications bits 3, 6 & 7 should be masked when servicing
  727.    the interrupt since they are not relevant. These bits cause trouble with 
  728.    old software relying on that they are cleared...
  729.    NOTE! Even if some of these interrupts are masked, the service routine
  730.    can be confronted with *all* states shown above when the IIR is loop-polled
  731.    until bit 0 is set. Check examples.
  732.  
  733. IER (Interrupt Enable Register):
  734.  
  735.    Bit 0:   If set, DR interrupt is enabled.
  736.    Bit 1:   If set, THRE interrupt is enabled.
  737.    Bit 2:   If set, Status interrupt is enabled.
  738.    Bit 3:   If set, Modem status interrupt is enabled.
  739.  
  740. MCR (Modem Control Register):
  741.  
  742.    Bit 0:   Programs -DTR. If set, -DTR is low and the DTR pin of the port is
  743.             '1'.
  744.    Bit 1:   Programs -RTS.
  745.    Bit 2:   Programs -OUT1. Not used in a PC.
  746.    Bit 3:   Programs -OUT2. If set, interrupts generated by the UART are trans-
  747.             ferred to the ICU (Interrupt Control Unit).
  748.    Bit 4:   '1': local loopback. All outputs disabled.
  749.  
  750. MSR (Modem Status Register):
  751.  
  752.    Bit 0:   Delta CTS. Set if CTS has changed state since last reading.
  753.    Bit 1:   Delta DSR. Set if DSR has changed state since last reading.
  754.    Bit 2:   TERI. Set if -RI has changed from low to high (i.e. RI at port
  755.             has changed from '1' to '0').
  756.    Bit 3:   Delta DCD. Set if DCD has changed state since last reading.
  757.    Bit 4:   CTS. 1 if '1' at port.
  758.    Bit 5:   DSR.
  759.    Bit 6:   RI. If loopback is selected, it is equivalent to OUT1.
  760.    Bit 7:   DCD.
  761.  
  762.  
  763. --
  764. ---------------------------------------------------------------------
  765. Christian Blum                   Universitaet des Saarlandes, Germany
  766. Friedrich-Ebert-Str. 50          chbl@stud.uni-sb.de
  767. W-6685 Heiligenwald              chbl@sbustd.rz.uni-sb.de
  768. Germany                          Tel (+49) (0) 6821 67476
  769.