RS-232 Serial Interfacing (revised, Fall 1997)

RETURN to the CHEM 498C Home Page

Equipment required: RS-232 video "dumb" terminal, Macintosh (any model), ZTerm, IBM-PC with built-in serial port, Procomm, Microsoft QuickBASIC, RS-232 cables, oscilloscope, Protek 506 digital multimeter with RS-232 interface.
A. Characteristics of RS-232 connectors and signals.
1. Turn on the Soroc video terminal and set the thumb wheel switch on the back to position 11 (this sets the bit rate). Examine the cable attached to the terminal. This is a common type of serial interface cable with standard male DB-25 at each end. Pin 7 is signal ground. Pins 2 and 3 are the transmit and receive data lines, but which is which depends on the kind of cable and on the hardware device it is connected to. When you type on the term inal, an RS-232 serial data signal is sent out of the transmit pin. Connect your oscilloscope ground to pin 7. Set the vertical range to 5 volts per cm and adjust the vertical zero so the trace is in the center of the screen. Set the oscillo scope's horizontal sweep rate to 0.2 msec per division and the triggering to internal and positive trigger level. In this way, the 'scope will trigger on the leading edge of the start bit, which is a - to + transition. Now look at the signals at pins 2 and 3 while holding down one of the keys on the terminal. Which pin seems to be the transmit pin?
2. Does this make the Soroc terminal a DTE or a DCE?
3. What voltages are used to represent 0 and 1?
4. What is the voltage of the RS-232 signal when no key is pressed.
5. Hold down the "1" key (to activate the "keyboard repeat" function) and sketch one complete cycle of the signal generated.
6. Identify the start bit and the data bits on your sketch. (Recall that in the RS-232 standard the least significant bit is sent first). How many data bits are there?
(Note that the stop bit blends into the marking line between characters).
Compare the bit pattern to the ASCII table below.
HEX DEC CHR    HEX DEC CHR    HEX DEC CHR    HEX DEC CHR
 00   0 NUL     20  32 SPC     40  64  @      60  96  `
 01   1 SOH     21  33  !      41  65  A      61  97  a
 02   2 STX     22  34  "      42  66  B      62  98  b
 03   3 ETX     23  35  #      43  67  C      63  99  c
 04   4 EOT     24  36  $      44  68  D      64 100  d
 05   5 ENQ     25  37  %      45  69  E      65 101  e
 06   6 ACK     26  38  &      46  70  F      66 102  f
 07   7 BEL     27  39  '      47  71  G      67 103  g
 08   8  BS     28  40  (      48  72  H      68 104  h
 09   9 TAB     29  41  )      49  73  I      69 105  i
 0A  10  LF     2A  42  *      4A  74  J      6A 106  j
 0B  11  VT     2B  43  +      4B  75  K      6B 107  k
 0C  12  FF     2C  44  ,      4C  76  L      6C 108  l
 0D  13  CR     2D  45  -      4D  77  M      6D 109  m
 0E  14  SO     2E  46  .      4E  78  N      6E 110  n
 0F  15  SI     2F  47  /      4F  79  O      6F 111  o
 10  16 DLE     30  48  0      50  80  P      70 112  p
 11  17 DC1     31  49  1      51  81  Q      71 113  q
 12  18 DC2     32  50  2      52  82  R      72 114  r
 13  19 DC3     33  51  3      53  83  S      73 115  s
 14  20 DC4     34  52  4      54  84  T      74 116  t
 15  21 NAK     35  53  5      55  85  U      75 117  u
 16  22 SYN     36  54  6      56  86  V      76 118  v
 17  23 ETB     37  55  7      57  87  W      77 119  w
 18  24 CAN     38  56  8      58  88  X      78 120  x
 19  25  EM     39  57  9      59  89  Y      79 121  y
 1A  26 SUB     3A  58  :      5A  90  Z      7A 122  z
 1B  27 ESC     3B  59  ;      5B  91  [      7B 123  {
 1C  28  FS     3C  60  <      5C  92  \      7C 124  |
 1D  29  GS     3D  61  =      5D  93  ]      7D 125  }
 1E  20  RS     3E  62  >      5E  94  ^      7E 126  ~
 1F  31  US     3F  63  ?      5F  95  _      7F 127 DEL
7. Measure the time duration of a single bit and calculate the bit rate. (Your measurement will only be approximate: the actual bit rate is the closest standard bit rate.)

8. Similarly determine the bit rate for the highest (fastest) setting of the baud switch on the back of the terminal.

B. Interfacing an instrument with an RS-232 interface.
In this part of the experiment you will interface a digital multimeter to a computer with a RS-232 serial connection. The first problem is to identify the serial port on the computer (on the Macintosh well will use the modem port, which is marked with a picture of a telephone). The next problem is to obtain or assemble a proper cable. There are three types of connectors commonly used for RE-232 serial ports: the large 25-pin "D-shaped" DB-25 connector, the smaller 9-pin DB-9 connector, and the 8-pin round DIN connector. Such cables are commercially available, as are various connector adaptors, gender (male/female) changers, and "null modem" adaptors (which switch pins 2 and 3).

To test the cable connections and to verify the proper operation of the RS-232 output of the instrument, a useful technique is to use a general-purpose "terminal" or "communication" program, many of which are available commercially or as freeware or shareware. Such programs are the simplest way to send data to and display data from an RS-232 device, and they make it very easy to change the bit rate and other communication parameters to match those used by the instrument. For this purpose we have the shareware programs Procomm for the PCs and ZTerm for the Macintosh. Connect the able and launch the terminal program.

The next step is to determine the bit rate and other communication parameters used by the Protek 506 Digital Multimeter. Read pages 42-43 of the Protek manual to find this information; then set the required bit rate, parity, number of data bits and stop bits in the terminal program (in ZTerm: select Settings, then Connection; in Procomm, press ALT-P). To verify the proper settings, press the RETURN (ENTER) key on the computer; this should cause the multimeter to respond by sending a string of characters (depending on the function setting of the meter). Verify the format of the data sent by the multimeter. Refer to the "Data format" table on page 45 of the Protek manual and compare the format of the output on the terminal screen to this table for several different measurement functions.

Finally, in order to demonstrate the importance of the communication parameters, change the bit rate, parity, number of data bits and stop bits in the terminal program and determine which ones are important for proper communication.

C. Programming the RS-232 interface.
In this part of the experiment you will write a QuickBASIC program that reads the Protek Digital Multimeter.

In QuickBasic, as in most modern BASICs, an RS-232 port is treated like a file; that is, you OPEN it, PRINT to it, and INPUT from it. When you open a file you assign it a number (typically #1 for the first file opened, #2 for the second, etc.). Then, a PRINT #1 statement outputs to file #1 and an INPUT #1 statement inputs from file #1, whereas a plain PRINT prints to the screen and a plain INPUT inputs from the keyboard as usual.

The Macintosh Quickbasic syntax for opening the first serial port (the modem port on a Mac) as file channel 1, at 1200 baud, even parity, 7 data bits, and 1 stop bit, is:

OPEN "COM1:1200,E,7,1" AS #1
In IBM-PC Quickbasic, the syntax is:
OPEN "COM1:1200,E,7,1,rs,cs,cd,ds" FOR RANDOM AS #1
In either version, PRINT#1 by itself sends a return character, PRINT#1,"XXX" sends the character string "XXX", and INPUT#1,A$ waits for serial input from the port and assigns it to A$.

Assignment

1. Write a program that reads the temperature and displays it on the computer monitor in both degrees C and degrees F. Have your program check to make sure the meter is in temperature mode and, if not, display a warning message that instructs the operator to switch the meter to temperature mode.
2. Modify the above program so that it records the temperature in degrees C once every second and displays the current time-of-day (TIME$) and temperature as two columns of data on the screen.
3. Modify the above program so that it saves the data to a disk file.
4. Modify the above program so that it allows you to type in an upper and lower temperature limit, then reads the temperature continuously and gives a warning whenever the temperature rises above some upper limit or below the lower limit.
5. Modify the above program so that it plots temperature in degrees C versus time (seconds since starting the program, from 0 to 500) on the computer screen.
Submit the printed program listing for each of these 5 programs.


This page is maintained by Tom O'Haver , Department of Chemistry and Biochemistry, The University of Maryland at College Park. Comments, suggestions and questions should be directed to Prof. O'Haver at to2@umail.umd.edu.