Baud Rate, Data Bits, Parity, and All That
Serial communication using RS-232 requires that you specify four parameters: the baud rate of the transmission, the number of data bits encoding a character, the sense of the optional parity bit, and the number of stop bits.
Each transmitted character is packaged in a character frame that
consists of a single start bit followed by the data bits, the optional
parity bit, and the stop bit or bits. A typical character frame
encoding the letter "m" is shown here.
Baud rate
Baud rate, as mentioned on the Definitions
page, is a measure of how fast data is moving between instruments that
use serial communication. RS-232 uses only two voltage states, called
MARK and SPACE. In such a two-state coding scheme, the baud rate is
identical to the maximum number of bits of information, including
"control" bits, that are transmitted per second.
MARK is a negative voltage and SPACE is positive; the figure above
shows how the idealized signal looks on an oscilloscope. The page on Logic Levels
has more information on the actual values of these voltages. I find it
easiest to think first of the physical voltages as they would appear on
a noninverting 'scope, then apply a couple of simple rules to interpret
the raw signal. For examples of RS-232 signals captured with an
oscilloscope, see the Examples of RS-232 Signals page.
(Start bit)
A start bit signals the beginning of each character frame. It is a
transition from negative (MARK) to positive (SPACE) voltage; its
duration in seconds is the reciprocal of the baud rate. If we're
transmitting at 9600 baud, then the duration of the start bit and each
subsequent bit will be about 0.104 ms. The entire character frame of
eleven bits would be transmitted in about 1.146 ms.
Data bits
Data bits are transmitted "upside down and
backwards." That is, inverted logic is used and the order of
transmission is from least significant bit (LSB) to most significant
bit (MSB). To interpret the data bits in a character frame, you must
read from right to left, and read 1 for negative voltage and 0 for
positive voltage. For the figure above, this yields 1101101 (binary) or
6D (hex). An ASCII conversion table shows that this is the letter "m".
Parity bit
An optional parity bit follows the data bits in the character frame.
The parity bit, if present, also follows inverted logic: read 1 for
negative voltage and 0 for positive voltage.
This bit is included as a simple means of error checking. The idea is
this: you specify ahead of time whether the parity of the transmission
is to be even or odd. Suppose the parity is chosen to be odd. The
transmitter will then set the parity bit in such a way as to make an
odd number of 1's among the data bits and the parity bit. The
transmission in the figure above uses odd parity. There are five 1's
among the data bits, already an odd number, so the parity bit is set to
0.
Stop bits
The last part of a character frame consists of 1, 1.5, or 2 stop bits.
These bits are always represented by a negative voltage. If no further
characters are transmitted, the line stays in the negative (MARK)
condition. The transmission of the next character frame, if any, is
heralded by a start bit of positive (SPACE) voltage.
How fast can I transmit?
Knowing the structure of a character frame and the meaning of baud rate
as it applies to RS-232, you can calculate the maximum transmission
rate, in characters per second, for a given communication setting. This
rate is just the baud rate divided by the bits per frame. In the case
above, we have a total of eleven bits per character frame. If the
transmission rate is set at 9600 baud, then we get 9600/11 = 872
characters per second.
If you want to squeeze more characters per second into your
transmission, then get rid of the parity bit and reduce the stop bits
to one. The character frame then has (assuming seven data bits) a total
of only nine bits. If you are still transmitting at 9600 baud, then you
will be able to send 9600/9 = 1066 characters per second.
The next step is to drop the start and stop bits entirely and send only
the data bits. This can be done with synchronous transmission. The
start of each new character is signaled on a separate line running
between the transmitter and receiver. Assuming once again that each
character has seven data bits and that the transmission takes place at
9600 baud, the synchronous arrangement is able to send 9600/7 = 1371
characters per second.
Note that these are maximum character transmission rates. It may happen
that the hardware on one end or the other of the serial link may not be
able to reach these rates, for whatever reason. The actual transmission
rate is usually throttled by signals on the link's handshaking lines.
The Macintosh Serial Driver
The Mac's Serial Driver supports the following settings. Note that
particular communication applications usually support only a subset of
these settings. Fortunately, lab equipment usually uses a still smaller
subset of the settings available in communication software. The
"typical" instrument gives you a choice of several baud rates but has
fixed settings for data bits, parity, and stop bits.
- Baud rates
- 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400, 19200, 28800, 38400, or 57600
Data bits
- 5, 6, 7, or 8
Parity
- odd, even, or none
Stop bits
- 1, 1.5, or 2
The Mac's default configuration is 9600 baud, 8 data bits, no parity bit, and 2 stop bits. I use the notation 9600-8-N-2
to represent this communication setting. This notation gives a kind of
graphical portrayal of the sequencing of the various bits.
Last modified 1997 Aug 16 by JC