Parallax, Inc. • IR Buddy Demo Kit (#28016) • 11/2002
Page 5
Example:
SEROUT pin, baud, [$64]
SERIN pin, baud, 1000, TO_Error, [STR buffer\8]
The first line above puts the IR Buddy in 8-byte receive/transfer mode and will initiate a transfer of any
buffered data. Since the transfer will not take place until eight bytes have been received, the
SERIN
command that follows should use a timeout period and label to allow the BASIC Stamp program to
proceed while waiting for data.
When data is available, it will be transferred to the BASIC Stamp in the eight-byte array called buffer.
$4C Loopback Test Mode
Use:
SEROUT
pin
,
baud
, [$4C,
holdoff
]
pin
variable or constant value: 0 to 15
baud
variable or constant value for 2400, 4800 or 9600 baud; open-mode
holdoff
variable or constant value: 0 to 255 ms; RX/TX delay and data byte
This function tests the serial connection between the BASIC Stamp and the IR Buddy. It is particularly
useful when the connection is over a long wire run, especially in an electrically-noisy environment. The
Loopback test can be used to establish the highest error-free baud rate between the BASIC Stamp and
the IR Buddy.
The BASIC Stamp should expect four bytes returned at the transmission baud rate after a delay specified
in holdoff. The first two bytes are the holdoff value, the third should be 254, the fourth 255.
Example:
SEROUT pin, baud, [$4C, holdoff]
SERIN pin, baud, 300, TO_Error, [STR buffer\4]
If, for example, the value 127 is sent in the holdoff parameter, the BASIC Stamp should expect the
following packet to arrive after approximately 127 milliseconds:
127 127 254 255
Resetting The IR Buddy
Before using the IR Buddy or when switching modes, it is important to reset its controller. This process is
also useful to clear any buffered data. To reset the IR Buddy, take the serial line low for at least five
milliseconds, then place it in an input mode for at least 50 milliseconds to allow the reset operation of
complete.
Example:
LOW pin
PAUSE 5
INPUT pin
PAUSE 50