Thanks for the ideas.
Ok, so I rewrote the code to trigger off the SPIF flag. See code below. But the code hangs at the last flag check statement
while((SPISR & SPIF) == 0); //Wait here until transfer complete
when I insert a statement to check the flag state directly above this, the routine works correctly.
temp = SPISR & SPIF;
while((SPISR & SPIF) == 0); //Wait here until transfer complete
So from this I guess I have a few additional questions. Why am I able to get past the SPIF flag barrier when the status is read before I reach the barrier? Is this the proper barrier test? Why does it only hang up on the last one?
######24-BIT SPI CODE START###########
void MAX5481(unsigned long mosi){
unsigned int tt;
unsigned int temp = 0;
mosi = mosi << 6;
PTAD = PTAD &~SSB; //Pull SSB line low
//#Debug only flag ststus check
temp = SPISR & SPIF;
//Check for SPIF flag set and clear if set
if ((SPISR & SPIF) != 0){
temp = SPIDR; //Should Clear SPIF Implied read of SPISR when SPIF read
}
//#Debug only flag status check
temp = SPISR & SPIF;
temp = SPISR & SPITEF;
//Data is a 24 bit write
//transfer MSByte
tt = (mosi >> 16) & 0x00FF;
SPIDR = tt; //write upper 8 bits to SPI data register
while((SPISR & SPIF) == 0); //Wait here until transfer complete
//#Debug only flag status check
temp = SPISR & SPIF;
temp = SPIDR; //Should Clear SPIF Implied read of SPISR when SPIF read
temp = SPISR & SPIF;
//Transfer midByte
tt = (mosi >> 8) & 0x00FF;
SPIDR = tt; //write middle 8 bits to SPI data register
while((SPISR & SPIF) == 0); //Wait here until transfer complete
//#Debug only flag ststus check
temp = SPISR & SPIF;
temp = SPIDR; //Should Clear SPIF Implied read of SPISR when SPIF read
temp = SPISR & SPIF;
//transfer LSByte
tt = mosi & 0x00FF;
SPIDR = tt; //write lower 8 bits to SPI data register
//#Debug only flag ststus check
temp = SPISR & SPIF;
//???????Code Hangs here unless previous SPIF check statement is inserted
while((SPISR & SPIF) == 0); //Wait here until transfer complete
for(tt=0; tt<10; tt++){
asm("NOP");
}
PTAD = PTAD | SSB; //Set SSB line back high
}
###########CODE END###############