Subject:
|
SPI Interrupts (Vector2X)
|
Newsgroups:
|
lugnet.robotics.handyboard
|
Date:
|
Wed, 26 Feb 1997 23:08:44 GMT
|
Original-From:
|
<tomb@%SayNoToSpam%netperceptions.com>
|
Viewed:
|
2272 times
|
| |
 | |
I am at it again! I am trying to get the Vector2X working on the SPI
bus of the handy board. I have read the docs, and they seem to make
sense, however, I cannot get the code to work.
I have the Vector2X running as a master, my assumption is that the
sample rate is too slow (5Hz), and that I probably want a reading
"right now", instead of waiting until the reading finishes. I will
let the V2X keep sending me updates, and the interrupt routine will
take care of all this for me.
This started out as a copy of the example from the IC manual, with
modifications to use the SPI interrupt instead of the TOC interrupt.
I know it works up to the point of actually getting an interrupt.
That "debug_vec" variable shows me that it doesn't work. When I load
this, and do a printf("%x\n", debug_vec); I get 0000. When I do a
comp_init(1); and the printf afain, I get 0f00, just like I want. The
trouble is I never get 4f00.
Anyone familiar with SPI interrupts see what I may be doing wrong? I
checked my code against the code in the Robot Digest where someone had
the 4 processor HC11 all talking SPI, and it looks very similiar.
I have put an O'scope on the CPU, verifying that the pins are
connected as I show them here (SS, MOSI, CLK).
*
* icb file: "compspi.asm"
*
* Tom Brusehaver 02/16/96
*
* Run the V2X in master mode, this keeps collecting the "current"
* heading, resulting in having almost real-time, constant input from
* the compass.
*
* Pin Connections
* V2X HC11
* pin desc pin desc Notes
* 13 EOC SS Sync bit counters between master and slave
* 2 SDO MOSI Data coming in
* 3 SDI MISO Data going out
* 1 SCLK CLK Bit clock
* 5 P/C gnd after startup
#include <6811regs.asm>
ORG MAIN_START
subroutine_initialize_module:
#include <ldxibase.asm>
* X now has base pointer to interrupt vectors
* get current vector; poke such that when we finish we go there
LDD SPIINT,X ; SPI Interrupt
STD interrupt_code_exit+1 ; fix $0000 at end.
* install ourself as a new vector
LDD #interrupt_code_start
STD SPIINT,X
rts
* variables
variable_temp_word: FDB 0 ; read each byte and store here
variable_head_word: FDB 0 ; after reading 2 bytes move them here
variable_byte_count: FDB 0 ; read first or second byte?
variable_debug_vec: FDB 0 ; --for now--
subroutine_comp_init:
* put SPI in slave mode
LDAA #$04
STAA DDRD
LDAA SPDR ; read it
LDAA #$CC ; SPIE, SPE !DWOM, !MSTR, CPOL, CPHA, E/2
STAA SPCR
LDAA SPSR ; clear SPIF
ldaa #$0f
sta variable_debug_vec ; --fornow--debug
CLI
RTS
* interrupt program begins here
interrupt_code_start:
ldaa #$4f
sta variable_debug_vec ; --fornow--debug
LDAA SPDR ; get our byte
LDAB variable_byte_count
CMPB #0 ; wouldn't have to
BNE byte2_output
STAA variable_temp_word+1 ; just save the current byte away
INCB ; increment byte count
STAB variable_byte_count
BRA end_out
byte2_output:
STAA variable_temp_word ; save the current byte, and move to
STAA variable_head_word
LDAA variable_temp_word+1 ; valid data holding location
STAA variable_head_word+1 ;
LDAB #$0
STAB variable_byte_count
end_out:
LDAA SPSR ; clear SPIF (maybe?)
CLI
RTI
* end of interrupt program.
interrupt_code_exit:
JMP $0000 ; this gets fixed above
|
|
1 Message in This Thread: 
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|