David Payne

Avoiding the new initial status read before using the S08 SPI

Discussion created by David Payne on Jul 9, 2007
Latest reply on Mar 17, 2010 by David Payne
Hi,
Starting with the S08 there is a new restriction that requires you to read the SPI status register to test for transmit buffer empty before you write to the data register.
It was not necessary with the older HC08/05's
This issue has been discussed before here:
 
In that post I suggested to test the SPTEF bit in the SPIS on every write as this is how I had converted a HC908GP32 project into a GT16. I came up against this problem again (converting GP32 code to GT16A) This time the SPI is much busier, previously it was only used on initialisation and manual test read.
 
It is really only necessary to do this before the first ever read as the check for SPRF during the transmit/recieve will cover the requirement on subsequent uses.
 
I found the best way to achieve this is to do a read of the SPIS right when you setup the SPI, like this:
Code:
*********** Setup SPI for EEPROM ********************************************  MOV #(mSPE|mMSTR),SPIC1 ;Enable SPI as master 0,0  CLR SPIC2  MOV #mSPR0,SPIBR  ;/4 = 5MHz  LDA SPIS   ;dummy SPTEF check

 
This way you can use a normal SPI send/recieve routine like this:
Code:
OUTBYTE         STA SPID             ;put data in SPI register                BRCLR SPRF,SPIS,*  ;wait till sent (or recieved)                LDA SPID             ;read returned value                RTS                                                         

 
This avoids the unecessary check of SPTEF every time while keeping things where they should be found.
 

Outcomes