'{$PORT COM1} '**************************************************************************** ' IOX TEST ' ' Version 1.0 Oct 9, 2002 ' ' George Heron, N2APB n2apb@amsat.org ' ' ' This simple BASIC program exercises the asynchronous serial ' command-response communication link between the BS2 and the SX processors. ' I found that the max usable speed was 2400 baud, as limited by the BS2. ' The corresponding version is running on the IOX chip (i.e., 1.0) ' using RA0 as Tx, and RA1 as Rx. The BS2 is running this program ' using P0 as Tx and P1 as Rx. ' ' ====================== ' FUNCTIONAL DESCRIPTION ' ====================== ' This test program issues a series of serial commands to the IOX chip, including ' input parameters (e.g., messages to be displayed), and expecting the appropriate ' responses from the IOX chip (frequency values, ACK signals, etc.) The BS2 program ' cycles through all the commands described in the IOX Data Sheet and then jumps ' back up to the top of the program to repeat the test sequence in an endless loop. ' ' A Debug window is displayed on the PC screen to indicate which tests are in progress. ' This status display enables the user to better understand what is supposed to be ' happening on the IOX side if there are problems there. The data received from the IOX ' circuit is also displayed in the Debug window, allowing the user to see the input values ' coming back from IOX, such as measured frequency, keypad entry, etc. ' ' Some tests will appear to hang the BS2 program, even in a properly-running IOX system. ' For example, the KEYPAD routine on the IOX is designed to wait forever for the user to ' press a key pad. Further, when the IOX system is not running properly (e.g., if power is ' lost), the BS2 program would obviously not receive the expected response. For these ' reasons, a "timeout period" is incorporated with all the SERIN commands that await feedback ' from the IOX subsystem. Now, if the user should not be present to press a keypad during the ' automated tests, or if there is a problem with the IOX circuitry, the BS2 test program ' will merely "timeout", issue an "operation failed" message in its Debug window, and ' continue on to the next test. This type of "exception handling" is a common technique ' used by software engineers in industry. ' ' As stated before this IOX test program runs forever, even when the PC is shut down or if ' the RS232 programming cable is removed from the BS2! Further, it automatically starts up ' when power is applied to the BS2+IOX system, providing a convenient constant source of ' IOX commands during the initial debug staged of the target IOX subsystem. ' ' ' Copyright 2002 by G. Heron. All rights reserved. ' '***************************************************************************** ' '{$STAMP BS2} Response var BYTE KeyboardChar var BYTE N var BYTE FreqString var BYTE(9) CounterReg var BYTE(3) Frequency var WORD BAUD con 396 CMD con $FE '**************** 'START OF PROGRAM '**************** START: debug "===============", CR debug "IOX TEST v 1.0", CR debug "===============", CR '********* 'LCD TESTS '********* LCDTEST: gosub ClearDisplay 'issue ClearDisplay command debug "Issuing test message to SX",CR serout 0,BAUD,7,["BS2 Message"] 'send test message to SX chip for individual 'character display, paced at 7ms intervals pause 1000 'wait a bit to ensure message present debug "Issuing Cursor On command",CR serout 0,BAUD,20,[CMD,15] 'issue Cursor On command pause 20 debug "Issuing Line1positioning command",CR serout 0,BAUD,20,[CMD,$80] 'issue Line1positioning command pause 20 serout 0,BAUD,7,["Line1 w/cursor"] pause 1000 debug "Issuing Cursor Off command",CR serout 0,BAUD,20,[CMD,12] 'issue Cursor Off command pause 20 debug "Issuing Line2positioning command",CR serout 0,BAUD,20,[CMD,$C0] 'issue Line2positioning command pause 20 serout 0,BAUD,7,["Line2 no cursor"] pause 1000 debug "Clearing line 2",CR serout 0,BAUD,20,[CMD,3] 'issue ClearLine2 command pause 1000 debug "Clearing line 1",CR serout 0,BAUD,20,[CMD,2] 'issue ClearLine1 command pause 1000 debug "Issuing Blank LCD command",CR serout 0,BAUD,7,["Blank LCD 1 sec "] pause 1000 serout 0,BAUD,20,[CMD,8] 'issue Blank LCD command pause 1000 'wait a bit debug "Issuing UnBlank LCD command",CR serout 0,BAUD,20,[CMD,12] 'issue UnBlank LCD command pause 200 '************ 'KEYPAD TESTS '************ KEYPADTEST: goto FREQTEST 'remove this line to do KEYPAD tests gosub ClearDisplay 'issue ClearDisplay command debug "Keypad Test: " serout 0,BAUD,7,["Hit any key"] pause 500 serout 0,BAUD,20,[CMD,101] 'issue ReadKeypad command serin 1,BAUD,PARITYERR,2000,TIMEOUT,[Response] debug DEC Response,CR goto FREQTEST TIMEOUT: debug "No keypad entry made",CR '*************** 'FREQ CNTR TESTS '*************** FREQTEST: gosub ClearDisplay serout 0,BAUD,7,["Reading Freq"] debug "Measuring Frequency ..." serout 0,BAUD,20,[CMD,68] 'issue "Set 1:1 prescaler" command pause 100 serout 0,BAUD,20,[CMD,65] 'issue MeasureFreq command pause 2000 serout 0,BAUD,20,[CMD,66] 'issue ReadOutFreqCntrs command serin 1,BAUD,PARITYERR,5000,TIMEOUT4,[STR CounterReg\3] debug CR,"Counter Regs:" debug " ",DEC CounterReg(2) debug " ",DEC CounterReg(1) debug " ",DEC CounterReg(0),CR serout 0,BAUD,20,[CMD,67] 'issue ReadOutFreqString command FreqString(9) = 0 serin 1,BAUD,PARITYERR,5000,TIMEOUT4,[STR FreqString\8] pause 100 debug "Frequency String= ",STR FreqString,CR serout 0,BAUD,20,[CMD,$C5] 'issue Line2positioning command pause 40 serout 0,BAUD,7,[STR FreqString] 'display 8 BCD frequency characters on 2nd line pause 1000 goto DIGPOTTEST TIMEOUT4: debug "No Frequency Measurement response",CR '************ 'DIGPOT TESTS '************ DIGPOTTEST: gosub ClearDisplay debug "Stepping Digital Pot wiper UP",CR serout 0,BAUD,20,[CMD,2] 'issue ClearLine1 command pause 1000 serout 0,BAUD,7,["DigPot Inc"] pause 10 for N = 1 to 10 serout 0,BAUD,20,[CMD,91,1] 'issue IncPot command + wiper increment count pause 2 next debug "Stepping Digital Pot wiper DOWN",CR serout 0,BAUD,20,[CMD,2] 'issue ClearLine1 command pause 250 serout 0,BAUD,7,["DigPot Dec"] pause 10 for N = 1 to 10 serout 0,BAUD,20,[CMD,92,1] 'issue DecPot command + wiper decrement count pause 2 next '********* 'ADC TESTS '********* ADCTEST: gosub ClearDisplay debug "Reading A/D Converter ... " serout 0,BAUD,20,[CMD,80] 'issue Get ADC command serin 1,BAUD,PARITYERR,1000,TIMEOUT2,[Response] 'await reply of ADC value in Response debug "ADC = ",DEC Response,CR goto SetDDS TIMEOUT2: debug "No ADC response",CR '------------- 'SET DDS '------------- SetDDS: debug "Setting DDS = 10KHz",CR dir9 = 1 'set the DDS_Load pin as an output out9 = 0 'and init it to 0 gosub ClearDisplay 'issue ClearDisplay command serout 0,BAUD,7,["DDS = 10KHz"] 'send program name to LCD shiftout 7,8,0,[$01,$EE,$09,$00,$00] 'shift out 40 DDS mode bits to set freq (01,EE,09,00,00 = 10KHz) 'data sent LSB-to-MSB for each sequencial 8-bit value out9 = 1 'strobe the DDS Load line out9 = 0 pause 1000 '********** ' PING TEST '********** PINGTEST: serout 0,BAUD,[$FF] 'send PING code to SX chip serin 1,BAUD,PARITYERR,2000,TIMEOUT3,[Response] 'await 2 sec for the response byte from SX chip if Response = 1 then ACK debug "Bad ping response!", CR goto START ACK: debug "ACK received OK", CR pause 500 goto START PARITYERR: debug "Communications parity error", CR goto START TIMEOUT3: debug "No Ping response",CR goto START '************ ' SUBROUTINES '************ '------------- 'CLEAR DISPLAY '------------- ClearDisplay: serout 0,BAUD,1,[CMD,$01] 'issue ClearDisplay command pause 400 'ensure SX LCD has enough time to do operation return end