home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 August / Chip_1999-08_cd.bin / sharewar / wscmclib / ASYNC.TXT < prev    next >
Text File  |  1999-05-24  |  29KB  |  902 lines

  1.  
  2.  
  3.  
  4.                       RS232/422/485 Serial Communications
  5.  
  6.  
  7.                               USERS MANUAL
  8.  
  9.  
  10.  
  11.                                Version 2.0
  12.  
  13.                              January 22, 1999
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.                             Copyright (C) 1999
  21.                             All rights reserved
  22.  
  23.  
  24.  
  25.                         MarshallSoft Computing, Inc.
  26.                            Post Office Box 4543
  27.                            Huntsville AL 35815
  28.  
  29.                         Voice : 256-881-4630
  30.                           FAX : 256-880-0925
  31.                         email : info@marshallsoft.com
  32.                           web : http://www.marshallsoft.com
  33.                           ftp : ftp://ftp.marshallsoft.com/marshallsoft
  34.  
  35.  
  36.                                _______
  37.                           ____|__     |                (R)
  38.                        --+       |    +-------------------
  39.                          |   ____|__  |  Association of
  40.                          |  |       |_|  Shareware
  41.                          |__|   o   |    Professionals
  42.                        --+--+   |   +---------------------
  43.                             |___|___|    MEMBER
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.       MARSHALLSOFT is a trademark of MarshallSoft Computing, Inc.
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.      RS232/422/485 Serial Communications                       Page 1
  61.  
  62.                             C O N T E N T S
  63.  
  64.  
  65.  
  66.       Chapter                                                   Page
  67.  
  68.  
  69.        1.0 The UART...................................................3
  70.  
  71.            1.1 UART Types.............................................3
  72.  
  73.                National 8250..........................................3
  74.  
  75.                National 16450.........................................3
  76.  
  77.                National 16550.........................................3
  78.  
  79.                StarTech 16650.........................................3
  80.  
  81.                Texas Instruments 16750................................3
  82.  
  83.            1.2 UART Operation.........................................4
  84.  
  85.            1.3 RS-232 Signals.........................................5
  86.  
  87.            1.4 UART Registers.........................................6
  88.  
  89.            1.5 Register Summary.......................................7
  90.  
  91.        2.0 Modems
  92.  
  93.            2.1 Modem Standards.......................................11
  94.  
  95.            2.2 Flow Control..........................................12
  96.  
  97.            2.3 Modem Initialization..................................13
  98.  
  99.        3.0 RS422 and RS485...........................................14
  100.  
  101.        4.0 Other Serial Devices......................................15
  102.  
  103.        5.0 Shareware.................................................15
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.      RS232/422/485 Serial Communications                       Page 2
  121.  
  122.       1.0 The UART
  123.  
  124.       The heart of serial communications is the "Universal Asynchronous
  125.       Receiver Transmitter", or UART for short. The UART is responsible for
  126.       controlling the computer's RS-232/422/485 port.
  127.  
  128.       1.1 UART Types
  129.  
  130.       UARTs can be broken down into two classes: buffered and unbuffered.
  131.       The 8250 and 16450 are unbuffer, while the 16550, 16650, and 16750
  132.       are buffered.
  133.  
  134.       1.1.1 National 8250
  135.  
  136.       The National 8250 was the original UART used in the IBM PC and
  137.       compatibles, and are only suitable up to 9600 baud on slower DOS
  138.       (before the IBM/AT) machines. The 8250A is somewhat faster than the
  139.       8250, but should also be limited to slower DOS machines.
  140.  
  141.       1.1.2 National 16450
  142.  
  143.       The National 16450 was designed to work with the IBM PC/AT (16-bit
  144.       data bus) and faster machines. Faster than the 8250, it still has a
  145.       one-byte buffer. The 16450 chip is suitable for many DOS applications
  146.       and some Windows applications up to about 38400 baud.
  147.  
  148.       1.1.3 National 16550
  149.  
  150.       The National 16550 features 16-byte transmit side and receive side
  151.       FIFO buffers. The interrupt trigger level (on the receive side) can
  152.       be set at 1, 4, 8 or 14 bytes. The TX FIFO trigger is fixed at 16
  153.       bytes.
  154.  
  155.       The FIFOs on the original 16550 UARTs did not work. The 16550A soon
  156.       followed the 16550 and is the "standard" UART for Windows machines.
  157.  
  158.       The 16550A is recommended as the minimum chip on any new serial board
  159.       purchase.
  160.  
  161.       1.1.4 StarTech 16650
  162.  
  163.       The StarTech 16650 features 32-byte FIFOs and on-chip flow control,
  164.       and can be run at up to 460800 baud. It is also pin for pin
  165.       compatible with the 16550 UART.
  166.  
  167.       1.1.5 TI 16750
  168.  
  169.       The Texas Instruments 16750 features 64-byte FIFOs and on-chip flow
  170.       control and can be run at up to 921600 baud, but is not pin for pin
  171.       compatible with the 16550 UART.
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.      RS232/422/485 Serial Communications                       Page 3
  181.  
  182.       1.2 UART Operation
  183.  
  184.       The purpose of the UART is:
  185.  
  186.       (1) To convert bytes from the CPU (Central Processing Unit) into a
  187.       serial format by adding the necessary start, stop, and parity bits to
  188.       each byte before transmission, and to then transmit each bit at the
  189.       correct baud rate.
  190.  
  191.       The first bit is always the start bit, followed by 5 to 8 data bits,
  192.       (optionally) followed by the parity bit, followed by the stop bit or
  193.       bits.
  194.  
  195.       (2) To convert the incoming stream (at a specified baud rate) of
  196.       serial bits into bytes by removing the start, stop, and parity bit
  197.       before being made available to the CPU.
  198.  
  199.       The UART is capable of operating in one of two modes, 'polled' and
  200.       'interrupt driven'.  The serial communications functions in the BIOS
  201.       use the polled method.  In this approach, the CPU is typically in a
  202.       loop asking the UART over and over again if it has a byte ready.  If
  203.       a byte is ready, the polling code returns the byte. But, if the next
  204.       byte comes in before the polling code is executing again, then that
  205.       byte is lost.
  206.  
  207.       In the interrupt driven approach, when a byte is received by the
  208.       UART, an 'Interrupt Service Routine' (ISR) is executed immediately,
  209.       suspending temporarily whatever is currently executing. The ISR then
  210.       moves the byte from the UART to a buffer so that the application
  211.       program can later read it.
  212.  
  213.       The 16550 can be programmed so that a receive (RX) interrupt is not
  214.       triggered until 4 (or 8 or 14) bytes have been received, while the
  215.       16650 can be triggered at up to 30 bytes, and the 16750 can be
  216.       triggered at up to 56 bytes. This can significantly reduce the CPU
  217.       processing time, since 14 (or 30 or 56) bytes can be moved at once.
  218.  
  219.       Transmitted bytes are queued up awaiting transmission.  When a byte
  220.       is moved from the UART transmitter holding register to the UART
  221.       transmitter shift register, an interrupt is generated and the next
  222.       byte is taken from the transmitter buffer by the ISR and written to
  223.       the UART holding register.
  224.  
  225.       Up to 16 bytes can be written at once to the transmitter FIFO buffer
  226.       while processing one transmitter interrupt if an 16550 UART is used,
  227.       while the 16650 can write up to 32 bytes at once, and the 16750 can
  228.       write up to 64 bytes at once.
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.      RS232/422/485 Serial Communications                       Page 4
  241.  
  242.       1.3 RS-232 Signals
  243.  
  244.       RS-232 is the name of the serial data interface standard used to
  245.       connect computers to modems.
  246.  
  247.       A summary of the serial port pins and their function follows.  For
  248.       more detailed information, refer to one of the many books dealing
  249.       with RS-232 interfacing.
  250.  
  251.       Signal Ground Pin 7 (DB25), Pin 5 (DB9)
  252.  
  253.       The SG line is used as the common signal ground, and must always be
  254.       connected.
  255.  
  256.       Transmit Data Pin 2 (DB25), Pin 3 (DB9)
  257.  
  258.       The TX line is used to carry data from the computer to the serial
  259.       device.
  260.  
  261.       Receive Data Pin 3 (DB25), Pin 2 (DB9)
  262.  
  263.       The RX line is used to carry data from the serial device to the
  264.       computer.
  265.  
  266.       Data Terminal Ready Pin 20 (DB25), Pin 4 (DB9)
  267.  
  268.       The DTR line is used by the computer to signal the serial device that
  269.       it is ready. DTR should be set high when talking to a modem.
  270.  
  271.       Data Set Ready Pin 6 (DB25), Pin 6 (DB9)
  272.  
  273.       The DSR line is used by the serial device to signal the computer that
  274.       it is ready.
  275.  
  276.       Request to Send Pin 4 (DB25), Pin 7 (DB9)
  277.  
  278.       The RTS line is used to 'turn the line around' in half duplex modems,
  279.       and for hardware flow control in most modems that require flow
  280.       control.  RTS is controlled by the computer and read by the serial
  281.       device (modem).
  282.  
  283.       Clear to Send Pin 5 (DB25), Pin 8 (DB9)
  284.  
  285.       The CTS line is used to 'turn the line around' in half duplex modems,
  286.       and for hardware flow control in most modems that require flow
  287.       control.  CTS is controlled by the serial device (modem) and read by
  288.       the computer.
  289.  
  290.       Data Carrier Detect Pin 8 (DB25), Pin 1 (DB9)
  291.  
  292.       The DCD line is used by the modem to signal the computer that a data
  293.       carrier signal is present.
  294.  
  295.       Ring Indicator Pin 22 (DB25), Pin 9 (DB9)
  296.  
  297.       The RI line is asserted when a 'ring' occurs.
  298.  
  299.  
  300.      RS232/422/485 Serial Communications                       Page 5
  301.  
  302.       1.4 UART Registers
  303.  
  304.       Data sheets can be obtained from the following sources on the
  305.       Internet.
  306.  
  307.       16550  www.national.com and www.exar.com
  308.       16650  www.exar.com
  309.       16750  www.ti.com
  310.  
  311.       These UARTs consists of 8 register ports as follows:
  312.  
  313.            Offset    R/W   Register
  314.              0       R/W   Receiver (read) / Transmitter (write)
  315.              1       R/W   Interrupt Enable Register (IER)
  316.              2       R     Interrupt Identification Register (IIR)
  317.              2       W     FIFO Control Register (FCR : 16550/650/750)
  318.              2       R/W   Enhanced Features Register (EFR : 16650 Only)
  319.              3       R/W   Line Control Register (LCR)
  320.              4       R/W   Modem Control Register (MCR)
  321.              5       R/W   Line Status Register (LSR)
  322.              6       R/W   Modem Status Register (MSR)
  323.              7       R/W   Scratch register. Not used.
  324.  
  325.       For the standard PC ports, the UART registers are based at 3F8h
  326.       (COM1), 2F8h (COM2), 3E8h (COM3), and 2E8h (COM4).  COM1 and COM3
  327.       share interrupt request line IRQ4 while COM2 and COM4 share request
  328.       line IRQ3. This means that COM1 and COM3 can't be used concurrently.
  329.       Similarly for COM2 and COM4.
  330.  
  331.       Four sources of interrupts are possible. (1) receiver error or BREAK,
  332.       (2) receiver data ready, (3) ready to transmit, and (4) RS-232 input.
  333.       Additional sources can be generated by the 16650 (see 16650 spec
  334.       sheet).
  335.  
  336.       These four sources of interrupts are summarized as follows:
  337.  
  338.          Source of Interrupt        Action Required to Clear
  339.          Receiver error or BREAK.   Read Line Status register.
  340.          Receiver data.             Read data from data register.
  341.          Transmitter Buffer Empty.  Write to data register or read IID reg.
  342.          RS-232 input.              Read Modem Status register.
  343.  
  344.       Serial ports are configured as either Data Communications Equipment
  345.       (DCE) or Data Terminal Equipment (DTE). Modems are always configured
  346.       as DCE, while serial printers are (almost) always configured as DTE.
  347.       Most serial (computer) ports are designed to talk to modems and are
  348.       therefore configured as DTE. Serial (computer) ports designed to talk
  349.       to serial printers (rare today) are configured as DCE. Most other
  350.       serial device are configured as DCE.
  351.  
  352.       A normal RS-232 cable is used to connect two serial ports with
  353.       opposite configuration (DTE & DCE), while a null modem cable is used
  354.       to connect two serial ports of the same configuration (both DTE or
  355.       both DCE).
  356.  
  357.  
  358.  
  359.  
  360.      RS232/422/485 Serial Communications                       Page 6
  361.  
  362.       1.5 Register Summary
  363.  
  364.       REG 0 : Data Register
  365.  
  366.       Reading from the data register fetches the next input byte, once it
  367.       is ready. Writing to the data register transmits the byte written to
  368.       it over the serial line.
  369.  
  370.       REG 1 : Interrupt Enable Register (IER)
  371.  
  372.       The Interrupt Enable register enables each of four types of
  373.       interrupts when the appropriate bit is set to a one.
  374.  
  375.          bit 3 : Enable interrupt on RS-232 input.
  376.          bit 2 : Enable interrupt on receiver error or break.
  377.          bit 1 : Enable interrupt on transmitter buffer empty (TBE).
  378.          bit 0 : Enable interrupt on received data (RxRDY).
  379.  
  380.       REG 2 : Interrupt Identification Register (IID)
  381.  
  382.       Reading the Interrupt Identification (read only) register once an
  383.       interrupt has occurred identifies the interrupt as follows:
  384.  
  385.          Bit 2  Bit 1  Bit 0  Priority    Interrupt
  386.            0      0      1      none      none
  387.            1      1      0      0 (high)  Serialization or break.
  388.            1      0      0      1         Received data.
  389.            0      1      0      2         Transmitter Buffer Empty.
  390.            0      0      0      3 (low)   RS-232 Input.
  391.  
  392.       REG 2 : Interrupt Identification Register (IID)
  393.  
  394.       In the 16550, 16650, and 16750, REG 2 (write only) is also the FIFO
  395.       control register.  Writing bits 6 & 7 will set the RX FIFO trigger
  396.       level (number of bytes received before an interrupt is generated).
  397.  
  398.       Bit 7  Bit 6   16550 Trigger  16650 Trigger  16750 Trigger
  399.        0      0        1 byte          8 bytes        1 byte
  400.        0      1        4 bytes        16 bytes       16 bytes
  401.        1      0        8 bytes        24 bytes       32 bytes
  402.        1      1       14 bytes        28 bytes       56 bytes
  403.  
  404.       The TX FIFO level can also be set in the 16650 by setting bits 4 & 5.
  405.       The 64-byte FIFO mode on the 16750 can be enabled by setting bit 5 in
  406.       the FCR. See the 16650 & 16750 data sheets for more details.
  407.  
  408.       REG 2 : Enhanced Feature Register (EFR) [16650 ONLY]
  409.  
  410.       The EFR can only be accessed after writing a BF to the LCR, after
  411.       which the advanced features on the 16650 are enabled by setting bit 4
  412.       of the EFR. For more details, see the 16650 data sheet.
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.      RS232/422/485 Serial Communications                       Page 7
  421.  
  422.       1.3 Register Summary (Continued)
  423.  
  424.       REG 3 : Line Control Register (LCR)
  425.  
  426.       RS-232 line parameters are selected by writing to this register.
  427.  
  428.          bit 7    : DLAB = 0
  429.          bit 6    : BREAK on(1), off(0).
  430.          bits 5-3 : Parity None(000),ODD(001),EVEN(011),MARK(101),SPACE(111)
  431.          bit 2    : One stop bit(0), two stop bits(1).
  432.          bits 1-0 : Data bits = 5 (00), 6(01), 7(10), 8(11).
  433.  
  434.       Parity  Meaning
  435.        Odd    The parity bit is 1 if the sum of the data bits is odd.
  436.        Even   The parity bit is 1 id the sum of the data bits is even.
  437.        None   There is no parity bit.
  438.        Mark   The parity bit is always set to 0.
  439.        Space  The parity bit is always set to 1.
  440.  
  441.       When the Divisor Latch Access Bit (DLAB) is 1, registers 0 and 1
  442.       become the LS and MS bytes of the Baud Rate Divisor registers.
  443.  
  444.       The baud rate is computed as (115200 / BaudRateDivisor). Thus,
  445.       common baud rates correspond to divisors as follows:
  446.  
  447.          Baud   Divisor      Baud  Divisor      Baud  Divisor
  448.           300    0180        4800   0018       38400   0003
  449.          1200    0060        9600   000C       57600   0002
  450.          2400    0030       19200   0006      115200   0001
  451.  
  452.       NOTES:
  453.       (1) Must write BF hex to LCR before EFR [16650 ONLY] can be
  454.       accessed (see 16650 data sheet).
  455.       (2) Must set DLAB = 1 (80 hex) before 64 byte FIFO bit can be
  456.       accessed (see 16750 data sheet).
  457.       (3) The 3 parity bits in the UART are named "Parity Enable" (bit 3),
  458.       "Parity Select" (bit 4), and "Stick Parity" or "Sticky Bit" (bit 5).
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.      RS232/422/485 Serial Communications                       Page 8
  481.  
  482.       1.3 Register Summary (Continued)
  483.  
  484.       REG 4 : Modem Control Register (MCR)
  485.  
  486.       RTS, DTR, loopback testing, and General Purpose Outputs #1 and #2 are
  487.       controlled by the Modem Control register as follows:
  488.  
  489.          bit 7 : Clock select. X1 (if 0), X4 (if 1). [16750 ONLY]
  490.          bit 6 : IR enable [16650 ONLY]
  491.          bit 5 : Interrupt type select [16650 ONLY] or
  492.                  Flow control enable [16750 ONLY].
  493.          bit 4 : Enable local loopback.
  494.          bit 3 : Enable GP02. Necessary for UART interrupts.
  495.          bit 2 : Enable GP01.
  496.          bit 1 : Set / clear RTS.
  497.          bit 0 : Set / clear DTR.
  498.  
  499.       REG 5 : Line Status Register (LSR)
  500.  
  501.       Reading the Line Status register provides status information as
  502.       follows (1 for TRUE, 0 for FALSE) :
  503.  
  504.          bit 7 : FIFO data error [16650 & 16750 ONLY].
  505.          bit 6 : Transmitter Empty (TXE).
  506.          bit 5 : Transmitter Buffer Empty (TBE).
  507.          bit 4 : BREAK detect.
  508.          bit 3 : Framing error.
  509.          bit 2 : Parity error.
  510.          bit 1 : Overrun error.
  511.          bit 0 : Data Ready.
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.      RS232/422/485 Serial Communications                       Page 9
  541.  
  542.       1.3 Register Summary (Continued)
  543.  
  544.       REG 6 : Modem Status Register (MSR)
  545.  
  546.       Reading the Modem Status register provides the following status
  547.       information (1 for TRUE, 0 for FALSE) :
  548.  
  549.          bit 7 : DCD status.
  550.          bit 6 : RI status.
  551.          bit 5 : DSR status.
  552.          bit 4 : CTS status.
  553.          bit 3 : Delta DCD status.
  554.          bit 2 : Delta RI status.
  555.          bit 1 : Delta DSR status.
  556.          bit 0 : Delta CTS status.
  557.  
  558.       The delta bits (bits 0 through 3) are set whenever one of the status
  559.       bits (bits 4 through 7) changes (from 0 to 1 or from 1 to 0) since
  560.       the last time that the Modem Status register was read. Reading the
  561.       Modem Status register clears the delta bits.
  562.  
  563.       REG 7 : Scratch Register
  564.  
  565.       There is no function associated with register 7.  It does not exist
  566.       in early versions of the 8250.
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.      RS232/422/485 Serial Communications                       Page 10
  601.  
  602.       2.0 Modems
  603.  
  604.       A modem is used to extend the distance over which you may
  605.       communicate. Without a modem, your RS-232 cable is limited to a
  606.       maximum of approximately 50 feet.  But with a modem, you can
  607.       communicate literally around the world.
  608.  
  609.       2.1 Modem Standards
  610.  
  611.       Two modems can communicate over a telephone line only if they are
  612.       both using the same signaling frequencies and modulation, which are
  613.       determined by the the modem standards used.  Modem standards can be
  614.       divided into three sets: (1) speed, (2) data compression used, and
  615.       (3) error control.
  616.  
  617.       The Bell standards (103 & 212A) are those of AT&T.  The CCITT (The
  618.       International Consultative Committee for Telephone and Telegraph)
  619.       standards are designated as 'V. '.
  620.  
  621.       Speed
  622.  
  623.            Bell 103  :   300 baud
  624.            Bell 212A :  1200 baud
  625.            V.21      :   300 baud
  626.            V.22bis   :  1200 & 2400 baud
  627.            V.32      :  4800 & 9600 baud
  628.            V.32bis   :  4800, 7200, 9600, 12000, and 14400 baud
  629.            V.34      :  V.32bis plus 16800, 19200, 21600, 24000, 26400,
  630.                         and 28800 baud.
  631.            V.34bis   :  V.34 plus 31200 and 33600 baud.
  632.            USR X2    :  US Robotics 56KB standard (33.6 KB uploads).
  633.            K56flex   :  Rockwells 56KB standard (33.6 KB uploads).
  634.            V.90      :  The new 56K standard.
  635.  
  636.       Data Compression
  637.  
  638.            MNP 5     :  Microcom Networking Protocol (proprietary).
  639.            V.42bis   :  International data compression standard.
  640.  
  641.       Error Control
  642.  
  643.            MNP 2,3,4 :  Three level error correction (public domain).
  644.            V.42      :  International error correction standard.
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.      RS232/422/485 Serial Communications                       Page 11
  661.  
  662.       2.2 Flow Control
  663.  
  664.       With modems using data compression, the modem to modem connection
  665.       will run at various speeds depending on the quality of the line.
  666.       The computer to modem connection will be at a fixed baud rate.
  667.       Therefore, a protocol (flow control) is necessary to synchronize the
  668.       data flow between a modem and the computer to which it is connected.
  669.       Refer to your modem manual for information on flow control protocols
  670.       supported.
  671.  
  672.       Two flow control protocols are used by most all modems which require
  673.       flow control.  Software flow control is called 'XON/XOFF' (other
  674.       software flow control character pairs are defined but operate the
  675.       same as XON/XOFF) and hardware flow control is called 'RTS/CTS'. Most
  676.       modems which require flow control enable hardware flow control by
  677.       default.
  678.  
  679.       In XON/XOFF (software) flow control, the computer suspends
  680.       transmitting data if it receives a XOFF character (13 hex) from the
  681.       modem, and continues transmitting when it receives a XON character
  682.       (11 hex).  Similiarly, the computer can signal the modem not to send
  683.       any more data by transmitting a XOFF to it, and can tell the modem to
  684.       continue transmission be sending a XON.
  685.  
  686.       In RTS/CTS (hardware) flow control, the RTS line is used by the
  687.       computer to signal the modem , while the CTS line is used by the
  688.       modem to signal the computer.  The RTS line is set OFF by the
  689.       computer to tell the modem to suspend transmission, and set to ON to
  690.       tell the modem to continue transmission.  The CTS line is set to OFF
  691.       by the modem to tell the computer to stop transmitting, and set to ON
  692.       to tell the computer to continue transmitting.
  693.  
  694.       Given the choice, always choose hardware flow control over software
  695.       flow control so that all data transmission is transparent.  If
  696.       hardware flow control is not the default (which it almost always is),
  697.       you should modify your modem initialization string to turn hardware
  698.       flow control on.
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.      RS232/422/485 Serial Communications                       Page 12
  721.  
  722.       2.3 Modem Initialization
  723.  
  724.       If an application uses a modem (as opposed to using a null modem
  725.       cable), then it should always send an initialization string to the
  726.       modem. Communication programs such as PROCOMM and TELIX always send
  727.       such a string automatically as soon as they start up.
  728.  
  729.       The particular initialization string depends on the make of your
  730.       modem.  For most modems, the following string (followed by a carriage
  731.       return) should work:
  732.  
  733.            AT E1 S7=60 S11=60 V1 X1 Q0 S0=0
  734.  
  735.       Recall that the modem must be in command mode in order to send AT
  736.       commands. To force command mode, send the character string "+-+"
  737.       (without the quotes), preceeded by 1 second of silence, and followed
  738.       by one second of silence.
  739.  
  740.       Refer to your Modem User's Guide for a full discussion of these
  741.       commands.  A brief description is as follows:
  742.  
  743.            AT     Modem attention command.
  744.            E1     Modem will echo what you send to it.
  745.            S7=60  Wait 60 seconds for carrier and/or dial tone.
  746.            S11=60 Use 60 milliseconds for tone dialing duration & spacing.
  747.            V1     Display result code as words (not numbers).
  748.            X1     Use the extended result message (CONNECT XXXX) set.
  749.            Q0     Modem displays result codes.
  750.            S0=0   Do not answer RING.
  751.  
  752.       If the application will answer incoming calls, set the S0 register to
  753.       the ring on which to automatically answer.
  754.  
  755.       Most modems can be set to the 'factory default' by transmitting
  756.  
  757.            AT&F
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.      RS232/422/485 Serial Communications                       Page 13
  781.  
  782.       3.0 RS422 and RS485
  783.  
  784.       RS422 and RS485 use the same UARTs as RS232. However, both RS422 and
  785.       RS485 are based on balanced differential signals, as opposed to RS232
  786.       which uses unbalanced signal levels. In other word, RS422 uses the
  787.       difference in voltage levels between 2 wires whereas RS232 uses the
  788.       voltage level of a single wire with respect to a common signal
  789.       ground.
  790.  
  791.       RS422 and RS485 both require a pair of wires for every signal. RS422
  792.       is only usable in point to point systems.
  793.  
  794.       RS485 has tri-state capability (its driver can be disabled) and can
  795.       support up to 32 receivers (multidrop) on the same line.
  796.  
  797.       RS485 can also be wired as "2-wire" in which the same pair of wires
  798.       are used for both transmitting and receiving. Typically, RTS is set
  799.       before transmitting and dropped after the last bit of the last byte
  800.       is sent.
  801.  
  802.       RS422 and RS485 may both require (for long run lengths) termination
  803.       resistors and/or biasing resistors, which is beyond the scope of this
  804.       discussion.
  805.  
  806.       RS422 an RS485 are typically used in industrial settings where long
  807.       run lengths (to 4000 feet) are necessary. For more information, refer
  808.       to one of the many technical references on the Internet such as:
  809.  
  810.       http://www.arcelect.com/485info.htm
  811.       http://www.bb-elec.com/techlibr.html
  812.       http://www.kksystems.com/serdesc1.html
  813.       http://www.sealevel.com/tech.html
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.      RS232/422/485 Serial Communications                       Page 14
  841.  
  842.       4.0 Other Serial Devices
  843.  
  844.       To be sure, the modem is the most common serial device. But there are
  845.       many other serial devices such as digitizing tablets, scanners,
  846.       digital cameras, numerical control machines, card readers, panel
  847.       displays, etc.
  848.  
  849.       Some serial devices (such as modems) use hardware (RTS/CTS) flow
  850.       control, but DTR/DSR flow control and software (XON/XOFF) flow
  851.       control are also common.
  852.  
  853.       If you are writing a program to communicate with a serial device,
  854.       keep in mind the following:
  855.  
  856.       (1) Always set DTR and RTS. Many serial devices "play dead" if DTR
  857.           is not set.
  858.  
  859.       (2) You may need to add a small time delay (0.25 sec) between
  860.           transmitted characters. This can be reduced or eliminated once
  861.           everything is working.
  862.  
  863.       (3) Make sure that your receive buffer is sufficently large. You want
  864.           to avoid buffer overflow.
  865.  
  866.       5.0 Shareware Libraries
  867.  
  868.       MarshallSoft Computing develops serial communications libraries for
  869.       DOS (real and protected mode) and Windows (Windows 3.1, 95/98, and
  870.       NT) marketed as shareware.
  871.  
  872.       There are specific libraries for C/C++, Delphi, Pascal (DOS only),
  873.       Visual Basic (Windows & DOS versions), and PowerBASIC.
  874.  
  875.       WSC4C  WIN C/C++        Windows Standard Comm Library for C/C++
  876.       WSC4D  WIN Delphi       Windows Standard Comm Library for Delphi
  877.       WSC4VB WIN Visual Basic Windows Standard Comm Library for VB
  878.       WSC4PB WIN PowerBASIC   Windows Standard Comm Library for PBCC
  879.  
  880.       PCL4W  WIN C/C++        Personal Comm Library for Windows
  881.       PCLVBW WIN Visual Basic Personal Comm Library for C/C++
  882.  
  883.       PCL4C  DOS C/C++        Personal Comm Library for C/C++
  884.       PCL4P  DOS Pascal       Personal Comm Library for Pascal
  885.       PCL4VB DOS Visual Basic Personal Comm Library for Visual Basic
  886.       PCL4PB DOS PowerBASIC   Personal Comm Library for PowerBASIC
  887.  
  888.       Our libraries have also been sucessfully used from Excel, Access,
  889.       Word, FoxPro, PowerBuilder, Clarion, dBase, Fortran, and Cobol.
  890.  
  891.       All shareware can be found on on our web site at:
  892.  
  893.  
  894.             http://www.marshallsoft.com
  895.  
  896.             ftp://ftp.marshallsoft.com/marshallsoft
  897.  
  898.       Better yet, visit our web site and take a look around.
  899.  
  900.      RS232/422/485 Serial Communications                       Page 15
  901.  
  902.