********** Setup SPI ******************************************************** MOV #(mSPE|mMSTR|mCPOL),SPIC1 ;set up SPI, now with CPOL=1 for HC165 (5.01) MOV #(mSPPR2|mSPR0),SPIBR ;set frequency to ~1MHz (999,771kHz)*further down JSR RDIPSW ;READ DIP SWITCH SETTING*somewhere elseRDIPSW BSET DIPSWLD,INTPORT ;SET HC165 TO SERIAL SHIFT BRCLR SPTEF,SPIS,* ;wait for transmit buffer MT STA SPID ;PUT DUMMY VALUE IN SPDR TO START XFER BRCLR SPRF,SPIS,* ;WAIT TILL DONE LDA SPID ;GET CLOCKED IN VALUE
;Init SPI port. CPOL=CPHA=0, Master, No interrupts. MOV #%01010000,SPIC1 MOV #%00000000,SPIC2 ;NO SPECIAL FEATURES, SS IS G.P. I/O. MOV #(6 LDA SPIS ;PRIME THE PUMP (FIXES NO SPRF ON 1ST BYTE). And later my SPI output routine is called: SPIOUT EQU * BCLR CS867,PTA ;CMX867 CHIP SELECT LOW. BSR SPIDEL ;EXTRA DELAY FOR SETUP TIME. STA SPID ;SEND THE DATA. BRCLR SPRF,SPIS,* ;WAIT FOR SPRF SET. LDA SPID ;RETURN WITH ANY RX DATA. SPIDEL RTS
12.3 Functional Description
An SPI transfer is initiated by checking for the SPI transmit buffer empty flag (SPTEF = 1) and then writing a byte of data to the SPI data register (SPI1D) in the master SPI device. When the SPI shift register is available, this byte of data is moved from the transmit data buffer to the shifter, SPTEF is set to indicate there is room in the buffer to queue another transmit character if desired, and the SPI serial transfer starts.
and here:
SPTEF — SPI Transmit Buffer Empty Flag
This bit is set when there is room in the transmit data buffer. It is cleared by reading SPI1S with SPTEF set, followed by writing a data value to the transmit buffer at SPI1D. SPI1S must be read with SPTEF = 1 before writing data to SPI1D or the SPI1D write will be ignored.
It is also like this in the QG and possibly other newer devices.