Parallax, Inc. • IR Buddy Demo Kit (#28016) • 11/2002
Page 13
IR Buddy Application: Loopback Testing
In some applications, the IR Buddy may be separated from the BASIC Stamp through a long serial
connection. The following code can be used to test the serial connection to the IR Buddy to determine
the fastest error-free serial baud rate.
The program tests each baud rate (starting at 2400 baud) for all possible data values on the line. The
transmission speed and buffer return will be displayed as the program runs. If a connection or reception
error occurs, the program will halt and display an appropriate message.
' -----[ Title ]----------------------------------------------------------------
'
' IRB Loopback.BS2
' {$STAMP BS2}
' -----[ I/O Definitions ]------------------------------------------------------
IRbSIO CON 15 ' IR Buddy serial I/O
' -----[ Constants ]------------------------------------------------------------
IRbLoopback CON $4C ' loopback test
IRbMod CON 38 ' modulation freq: 30, 38 or 56
IRb96 CON 84 + $8000 ' 9600 baud, open
IRb48 CON 188 + $8000 ' 4800 baud, open
IRb24 CON 396 + $8000 ' 2400 baud, open
CrsrXY CON 2 ' DEBUG position command
ClrEOL CON 11 ' Clear DEBUG line to right
' -----[ Variables ]------------------------------------------------------------
testNum VAR Nib ' test number (fore each baud)
testVal VAR Byte ' test value
buffer VAR Byte(4) ' receive buffer
idx VAR Nib ' loop counter
testBaud VAR Word
' -----[ Initialization ]-------------------------------------------------------
Setup:
GOSUB IR_Buddy_Reset
PAUSE 250 ' let DEBUG window open
DEBUG CLS
DEBUG "IR Buddy Loopback Test", CR
DEBUG "----------------------", CR
DEBUG CR
DEBUG "Baud: ", CR
DEBUG CR