In master mode, everytime you clock out a byte, you also clock in a byte, and SPIF is set when clock in and clock out are done. I see S12C datasheet talks about SPIF flag like about receive flag. But in fact S12C SPIE and SPIF bits behave very similar like on old HC11 family. And HC11 manual calls them SPI Transfer Complete Flag (SPIF) and SPI Interrupt Enable Bit (SPIE).
I'm not sure why your code doesn't work. Do you put all data to be send to Tx queue and enable SPTIE interrupt? If so, then substituting SPTIE with SPIE and SPTIF with SPIF won't be enough. Difference is that after you service(clear) SPIF, SPIF will stay 0 until another transfer is done. And SPTIF is always 1, unless you fill transmit buffer. To switch from SPTIE to SPIE, first byte should be put to SPDR not from SPI ISR.
Should I use the SPITE to send data and the receive data interrupt to toggle the SS line?
This approach may work, but you should keep in mind that S12C transmit data register is double buffered and sending two SPI bytes you should service both SPIF==1 events. I mean SPTEF==1 and SPIF==1 events and MAX3100 CS should come like this:
SPTEF:
~\1/~\2/~~~~~~~~~~~~~~~~~~~~~~~~~
SPIF :
________________/3\_____________/4\______
CS :
\_____________________________________/~~
It is on every second SPTEF interrupt you should disable SPTIE and enable SPIE. Then on second SPIE interrupt you may toggle CS.
One warning though. S12C SPI receiver isn't really double buffered. Data will be lost if SPDR isn't read before second clock in/clock out is done. SPIE ISRs have to not be delayed too much, else you may loose received data. (This issue is fixed on S12XD family. On S12XD you may complete clocking out 2 bytes, then read 2 clocked in bytes from SPDR.) So it is better to
SPTEF:
~\1/~~~~~~~~~~~~~~\2/~~~~~~~~~~~~~~
SPIF :
________________/3\_____________/4\______
CS :
\_____________________________________/~~
on first SPTIF interrupt write data to SPIDR, disable SPTIE, enable SPIE. On first SPIE write second byte to SPIDR, on second SPIE toggle CS.
Hope it helps
Message Edited by kef on 2009-10-26 09:15 PM