BASIC stamp manual v2.2

SEROUT – BASIC Stamp Command Reference
Page 424 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
When the BASIC Stamp is sending or receiving data, it can’t
execute other instructions.
When the BASIC Stamp is executing other instructions, it can’t
send or receive data. The BASIC Stamp does not have a serial buffer as
there is in PCs. At most serial rates, the BASIC Stamp cannot
receive data via SERIN, process it, and execute another SERIN in
time to catch the next chunk of data, unless there are significant
pauses between data transmissions.
These limitations can sometimes be addressed by using flow control; the
Fpin option for SERIN and SEROUT (at baud rates of up to the limitation
shown in Table 5.94). Through Fpin, SERIN can tell a BASIC Stamp sender
when it is ready to receive data and SEROUT (on the sender) will wait for
permission to send. (For that matter, Fpin flow control follows the rules of
other serial handshaking schemes, but most computers other than the
BASIC Stamp cannot start and stop serial transmission on a byte-by-byte
basis. That’s why this discussion is limited to communication between
BASIC Stamp modules.)
Here’s an example using flow control on the BS2 (data through I/O pin 1,
flow control through I/O pin 0, 9600 baud, N8, noninverted):
SerData VAR BYTE
SEROUT 1\0, 84, [SerData]
When SEROUT executes, I/O pin 1 (Tpin) is made an output, and I/O pin
0 (Fpin) is made an input, to wait for thego signal from the receiver.
Here’s the relationship of serial polarity to Fpin states.
Ready to Receive ("Go") Not Ready to Receive ("Stop")
Inverted
Fpin is High (1) Fpin is Low (0)
Non-inverted
Fpin is Low (0) Fpin is High (1)
Table 5.112: Flow control pin states
in relation to polarity (inverted or
non-inverted) for all BS2 models.
See the demo program, below, for a flow control example using two BS2s.
In the demo program example, without flow control, the sender would
transmit the whole word “Hello!” in about 6 ms. The receiver would catch
the first byte at most; by the time it got back from the first 1-second
PAUSE, the rest of the data would be long gone. With flow control,
communication is flawless since the sender waits for the receiver to catch
up.