Specifications

BASIC Stamp II
Page 320 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
ware description and schematic. In order for SOUT to work at the proper
voltage levels, there must be an RS-232 output signal connected to SIN,
and that signal must be quiet (not transmitting data) when data is be-
ing sent through SOUT.
For more information on using the carrier-board DB9 connector for
serial communication, see the
Serin listing and figure I-17.
Serial Timing and Mode
(Baudmode)
Asynchronous serial communi-
cation relies on precise timing.
Both the sender and receiver must
be set for identical timing, usu-
ally expressed in bits per second
(bps) and called baud.
Serout accepts a single 16-bit
value called baudmode that speci-
fies important characteristics of
the serial transmission—the bit
time, data and parity bits, polar-
ity, and drive. Figure I-22 shows
how Serout baudmode is calcu-
lated and table I-6 shows com-
mon baudmodes for standard
serial baud rates.
If you’re communicating with
existing software, its speed(s)
and mode(s) will determine your
choice of baud rate and mode. In
general, 7-bit/even-parity (7E)
mode is used for text, and 8-bit/
no-parity (8N) for byte-oriented
data. Parity can detect some com-
munication errors, but to use it
you lose one data bit. This means
that incoming data bytes trans-
Calculating Baudmode
for BS2 Serout
Bits 0 through 12 of the baudmode are the bit period,
expressed in microseconds (µs). Serout’s actual bit
period is always 20µs longer than specified. Use the
following formula to calculate the baudmode bit period
for a given baud rate:
Step 1: Calculate the Bit Period (bits 0—12)
(INT means ‘convert to integer;’ drop the numbers to the right of the decimal point.)
Bit 13 lets you select one of two combinations of data
bits and parity:
Step 2: Set Data Bits and Parity (bit 13)
1,000,000
baud rate
()
– 20INT
= 8 bits, no parity
= 7 bits, even parity
0
8192
Bit 14 tells Serout whether the data should be inverted
(as when sent directly to a standard COM port) or
noninverted (to pass through a line driver):
Step 3: Select the Polarity of Serial Output (bit 14)
= noninverted
= inverted
0
16384
DP
d
BBBBBBBBBBBBB
1514131211109876543210
p
Bit period, 0 to 8191µs (+20µs)
Data bits, parity
(0 = 8 bits, no parity; 1 = 7 bits, even parity
Polarity (0 = noninverted; 1 = inverted)
Driven/open (0=driven; 1=open)
If you’re more comfortable thinking in terms of bits,
here’s a bit map of Serout’s baudmode:
FYI: Bit Map of Serout Baudmode
Bit 15 tells Serout whether to drive the output in both
states (0 and 1), or drive to one state and leave open in
the other. If you select open, the state that is driven is
determined by polarity: with inverted polarity open modes
drive to +5V only; noninverted open modes drive to
ground (0V) only. Bit settings:
Step 4: Set Driven or Open Output (bit 15)
= driven
= open
Add your choice to the sum of steps 1 through 3. The
result is the correct serial baudmode for use by Serout.
0
32768
Serout through pin 16 (SOUT) is always inverted, regardless of
the polarity setting. However, polarity will still affect fpin, if used.
Figure I-22