home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / cmanual-3.0.lha / CManual / Devices / SerialDevice / SerialDevice.doc < prev    next >
Text File  |  1993-10-12  |  64KB  |  1,839 lines

  1. 7    SERIAL DEVICE
  2.  
  3. 7.1  INTRODUCTION
  4.  
  5. All Amiga models have a serial port to which you can connect
  6. external devices like a modem, scanner or a printer with a
  7. serial interface. Data can be sent in both directions, in
  8. several different formats, like seven or eight bits, with
  9. or without error checking etc.
  10.  
  11. On the Amiga the serial port consists of a 25 pin connector,
  12. and can communicate with baud rate up to 32250. It is the
  13. custom chip called "Paula" which contains a Universal
  14. Asynchronous Receiver/Transmitter (UART) that takes care of
  15. all serial data transmissions. The chip itself can manage
  16. up to one million bits per second, but at that speed the data
  17. buffer would be filled before the system had time to react,
  18. and normal cables can not manage to transmit more than
  19. 100,000 - 200,000 bits per second.
  20.  
  21. Baud rates between 1200 and 9600 are in most cases more than
  22. sufficient, and at that speed the computer will still be able
  23. to multitask properly.
  24.  
  25.  
  26.  
  27. 7.2  THE SERIAL PORT
  28.  
  29. The serial port sends and receives data in streams of bits.
  30. In theory only one physical wire would therefore be required,
  31. but there have been several extra cables added to send and
  32. receive special information as well as to supply external
  33. devices with power (+12V) and so on.
  34.  
  35. Since all data is sent bit by bit, and not as with the parallel
  36. port which sends one byte (8 bits) each time, it is rather
  37. slow. (Well at least not as fast as the parallel port, which
  38. is fully documented in the next chapter.) However, since
  39. some applications only works with one line, for example
  40. the modems which are connected to the telephone system,
  41. serial communication is easier to handle. Serial cables are
  42. also much cheaper.
  43.  
  44. Although only one line is required there is a whole 25-pin
  45. connector on the Amiga. Normal applications like a modem, or
  46. a scanner only needs some of the lines, but since there are
  47. so many possible lines to use, a lot of special equipment can
  48. be connected to the serial port. (See illustration "RS-232".)
  49.  
  50.  
  51.  
  52. 7.2.1  BYTE TO BITS AND VICE VERSA
  53.  
  54. Since the serial device only sends a stream of bits, a special
  55. chip has to convert the data (bytes) to bits (8). The character
  56. "A" would for example be transformed to 01000001 and "B" to
  57. 01000010 and so on. Of course the chip must also be able to
  58. do the opposite, to convert an incoming stream of bits to
  59. bytes.
  60.  
  61.             --------
  62.   A (64) <- |      | <- 01000001  (Receiving data)
  63.             | UART |
  64.   D (68) -> |      | -> 01000100  (Transmitting data)
  65.             --------
  66.  
  67.  
  68. The special chip that takes care of this is the "Universal
  69. Asynchronous Receiver/Transmitter" usually referred to as
  70. "UART". (See illustration "UART") Luckily we do not need to
  71. bother too much about this. However, it is good to know what
  72. is actually happening.
  73.  
  74.  
  75.  
  76. 7.2.2  PIN ASSIGNMENT
  77.  
  78. The Amiga's serial port is a 25-pin D-female-type connector.
  79. Below is an almost complete list of the pin assignment,
  80. together with a short description. (See illustration "RS-232".)
  81.  
  82. Pin  Amiga   RS232  HAYES  Direction  Type      Description
  83. -------------------------------------------------------------------
  84.   1  SHIELD  GND    GND    -          Standard  Ground  
  85.   2  TXD     TXD    TXD    Out        Standard  Transmit data
  86.   3  RXD     RXD    RXD    In         Standard  Receive data
  87.   4  RTS     RTS x  -      Out        Standard  Request to send
  88.   5  CTS     CTS x  CTS    In         Standard  Clear to send
  89.   6  DSR     DSR x  DSR    In         Standard  Data set ready
  90.   7  GND     GND    GND    -          Standard  Signal ground
  91.   8  DCD     DCD    DCD    In         Standard  Carrier detect
  92.   9  +12V    -      -      -          Amiga     +12 Volt
  93.  10  -12V    -      -      -          Amiga     -12 Volt
  94.  11  AUDO    -      -      Out        Amiga     Audio output
  95.  12  -       S.DS   SI     +          -         Speed indicate
  96.  13          S.CTS  -      +          -         RS232 code
  97.  14  -       S.TXD  -      +          -         RS232 code
  98.  15  -       TXC    -      +          -         RS232 code
  99.  16  -       S.RXD  -      +          -         RS232 code
  100.  17  -       RXC    -      +          -         RS232 code
  101.  18  AUDI    -      -      In         Amiga     Audio in (not used)
  102.  19  -       S.RTS  -      +          -         RS
  103.  20  DTR     DTR x  DTR    Out        Standard  Data terminal ready
  104.  21  -       SQD    -      -          *         (A1000 +5V)
  105.  22  RI      RI     RI     In         Standard  Ring indicator
  106.  23  -       SS     -      -          *         (A1000 +12V)
  107.  24  -       TXC1   -      -          -         3.58 MHz clock
  108.  25  -       -      -      -          Amiga     Reset (A1000)
  109.  
  110. (x) Used only if you have set the "seven-wire flag". Se below
  111.     for more information.
  112.  
  113. WARNING! Pin 21 and 23 are connected to the power supply on
  114. the old Amiga 1000s (+5V and +12V). On all other models the
  115. power is sent through pin 9 and 10. Be careful with this if
  116. you intend to make serial cables! We do not want to burn the
  117. user's external devices, do we?
  118.  
  119.  
  120.  
  121. 7.2.3  THE DATA STREAM
  122.  
  123. Since all data is sent and received in a stream of bits, the
  124. UART chip needs to know when each new byte (set of 8 bits) is
  125. coming in. To make this possible, following rules have been
  126. stated: (See illustration "Serial Bits".)
  127.  
  128.   1. When no data is sent, a mark bit (1) is sent over and over.
  129.  
  130.   2. Just before a byte is sent, a start bit (0) is transmitted.
  131.      The receiver will now know that seven or eight bits (depends
  132.      on what type of device it is) of data will be received.
  133.  
  134.   3. An optional "parity" bit will come directly after the
  135.      data bits. The parity bit is used for error checking. The
  136.      receiver may use "even", "odd" or no parity at all. If
  137.      the receiver is using even parity, the sender should set
  138.      the parity bit to 1 if the remainder of all data bits
  139.      divided by two is 0, else the parity bit should be set to
  140.      0. If the receiver is using odd parity, the sender should
  141.      set the parity bit to 0 if the remainder of all data bits
  142.      divided by two is 0, else the parity bit should be set to
  143.      1. If the receiver does not use parity checking, either
  144.      set the parity bit to 0 or do not send any parity bit at
  145.      all.
  146.  
  147.   4. Finally we need to send one (or two) stop bit(s) to tell
  148.      the receiver that the last data bit has been sent.
  149.  
  150.  
  151.   ...1 0 0 0 1 0 0 0 1 0 1 0 0 0 1... -> -> ->
  152.   ..._       _       _   _       _...
  153.       \_____/ \_____/ \_/ \_____/             
  154.      ^                           ^
  155.      | ^ ^ ^ 8 7 6 5 4 3 2 1 0 ^ |
  156.      | | | | <-- Data bits --> | Mark bit(s)
  157.      | | | |   (7 or 8 bits)   | 
  158.      | | | |                   Start bit
  159.      | | | |                        
  160.      | \ / Parity bit (We use even parity, hence 0)                 
  161.      |  | 
  162.      |  One or two stop bits
  163.      |
  164.      Mark bit(s)
  165.  
  166.  
  167.   Even parity: The sum of the data bits is divided by two, and
  168.                if the remainder is 0, the parity bit should be
  169.                set to 1. If the remainder is 1, the parity bit
  170.                should be set to 0. 
  171.  
  172.     10100110 = 4 bits are set. 4/2  remainder = 0 -> parity = 1
  173.     01110110 = 5 bits are set. 5/2  remainder = 1 -> parity = 0
  174.  
  175.  
  176.   Odd parity: The sum of the data bits is divided by two, and
  177.               if the remainder is 0, the parity bit should be
  178.               set to 0. If the remainder is 1, the parity bit
  179.               should be set to 1. 
  180.  
  181.     10100110 = 4 bits are set. 4/2  remainder = 0 -> parity = 0
  182.     01110110 = 5 bits are set. 5/2  remainder = 1 -> parity = 1
  183.  
  184.  
  185. The nice thing about the serial device is that we do not need
  186. to bother about this. (So why did I write it?) You only have
  187. to tell the device if you want to use parity, and if so if it
  188. should use even (default) or odd parity. You should also tell
  189. the serial device if you want to send seven or eight data bits,
  190. and one or two stop bits. Once you have told the device what
  191. you want, you do not need to think about it any more.
  192.  
  193.  
  194.  
  195. 7.3  THE SERIAL DEVICE
  196.  
  197. The Serial Port is a limited resource it that sense that there
  198. exist (normally) only one port. There may however be several
  199. programs running at the same time which all want to use the
  200. serial port. To make this possi