*SPI routines for HC11
*MASTER SPI initialization routine
SPI_INITM	LDAA	#$20	;configure PORTD bit 5  as ;general purpose output
	STAA	DDRD	
	BCLR	PORTD,$20	;make SS=0
	LDAA	#$56		;SPI enable, Master, CPHA=1 ;clock:32
	STAA	SPCR	
	RTS		
* SLAVE SPI initialization routine
* SLAVE SPI receiver interrupts enabled
SPI_INITS	LDAA	#$C6	;SPIE, SPE, Slave, CHPA=1 ;clock:32
	STAA	SPCR	
	RTS		

* SPI_SENDCH - sends character stored at XSPI over SPI
* returns the character received form SLAVE in RSPI

SPI_SENDCH  	LDAA	SPSR	;wait for SPIF
            	ANDA	#$80	;isolate SPIF bit
		BEQ	SPI_SENDCH	
            	LDAA	XSPI	;get character to send
            	STAA	SPDR	;send it
SPS05		LDAA	SPSR	;wait for end of transmission
		ANDA	#$80	
		BEQ	SPS05	
           	LDAA	SPDR	;read the byte just received
            	STAA	RSPI	;save it to RSPI, and return
            	RTS		


