' ' vector2.bas test file for the Vector-2X compass module ' ' This program uses a BotBoard (with a 68hc811e2) to talk to a ' Vector-2X compass module via the SPI. This is a bare-bones ' configuration, based on Appendix B of the Application Notes ' (Ver. 1.06) supplied by Precision Navigation, Inc. ' ' This program expects the following connections: ' ' Vector-2X 68hc11 ' --------- ------ ' +5 +5 ' GND GND ' EOC PE0 ' P/C PB1 ' *SS *SS ' SCLK SCLK ' SDO MISO ' ' The program will output the compass heading as an integer ' from 0 to 359 to the SCI; use the TERM command in pcbug11 ' to see the information. The heading is updated once per ' second. ' include "regs11.lib" ' ' Declare variables used in this program. ' declare wait ' delay counter declare value ' holds returned value ' ' Declare the RTI ISR, used to generate timed delays. ' interrupt $fff0 ' RTI ISR if wait <> 0 ' if not done yet... wait = wait - 1 ' count this tick endif pokeb tflg2, %01000000 ' clear RTI flag end ' ' The main program ' main: pokeb baud, $30 ' 9600 baud pokeb sccr2, $0c ' turn on SCI wait = 0 pokeb tmsk2, peekb(tmsk2) or %01000000 ' permit RTI interrupts pokeb tflg2, %01000000 ' clear RTI flag interrupts on ' allow interrupts pokeb portd, peekb(portd) or $20 ' force *SS high pokeb ddrd, %00111010 ' *SS=output pokeb spcr, %01011111 ' CPOL=1, CPHA=1, E/32 value = peekb(spsr) ' dummy read to clear SPI value = peekb(spdr) ' dummy read to clear SPI pokeb portb, peekb(portb) or $02 ' force P/C high print "vector2.bas" ' announce our presence do if wait = 0 ' if time to read... pokeb portb, peekb(portb) and $fd ' force P/C low wait = 4 ' 10 ms delay (or so) do loop until wait = 0 ' time it out pokeb portb, peekb(portb) or $02 ' force P/C high waituntil porte, $01 ' wait until PE0 is high wait = 4 ' 10 ms delay (or so) do loop until wait = 0 ' time it out pokeb portd, peekb(portd) and $df ' force SS low wait = 3 ' 5 ms delay (or so) do loop until wait = 0 ' time it out pokeb spdr, 0 ' send a 0 to start xfer waituntil spsr, $80 ' wait until xfer completes value = peekb(spdr) * 256 ' get msb of data pokeb spdr, 0 ' send a 0 to start xfer waituntil spsr, $80 ' wait until xfer completes value = value + peekb(spdr) ' get lsb of data pokeb portd, peekb(portd) or $20 ' force SS high print "Value = "; value; " "; outch $0d ' make it pretty wait = 250 ' set up a 1-second delay endif loop end