BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – SEROUT
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 423
same size. The string "ABC" could be stored in a byte array containing
three bytes (elements). See the “Defining Arrays” section in Chapter 4 for
more information on arrays.
Here is an example that transmits five bytes (from a byte array) through
I/O pin 1 at 9600 bps, N81/inverted:
serStr VAR Byte(5) ' create 5-byte array
Main:
serStr(0) = "H" ' fill array
serStr(1) = "E"
serStr(2) = "L"
serStr(3) = "L"
serStr(4) = "O"
SEROUT 1, 16468, [STR serStr\5] ' transmit
Note that we use the optional \L argument of STR. If we didn't specify
this, the BASIC Stamp would try to keep sending characters until it found
a byte equal to 0. Since we didn't specify a last byte of 0 in the array, we
chose to tell it explicitly to only send 5 characters.
Parity is a simple error-checking feature. When the SEROUT command's
Baudmode is set for even parity it counts the number of 1s in the outgoing
byte and uses the parity bit to make that number even. For instance, if it is
sending the 7-bit value: %0011010, it sets the parity bit to 1 in order to
make an even number of 1s (four).
The receiver also counts the data bits to calculate what the parity bit
should be. If it matches the parity bit received, the serial receiver assumes
that the data was received correctly. Of course, this is not necessarily true,
since two incorrectly received bits could make parity seem correct when
the data was wrong, or the parity bit itself could be bad when the rest of
the data was OK. Parity errors are only detected on the receiver side.
Generally, the receiver determines how to handle the error. In a more
robust application, the receiver and transmitter might be set up such that
the receiver can request a re-send of data that was received with a parity
error.
When you design an application that requires serial communication
between BASIC Stamp modules, you have to work within these
limitations:
USING PARITY AND HANDLING PARITY
ERRORS
.
C
ONTROLLING DATA FLOW.
All
2