Jan Thogersen

Strange SPI status flag behavior

Discussion created by Jan Thogersen on Mar 13, 2006
Latest reply on Jul 5, 2006 by Ramiro Galloso
Hi,

I'm trying to get the SPI up and running on an MC9S12DP256B however, I see some strange behavior.

Here is the setup:
Target: MC9S12DP256B
Compiler: MetroWerks C
Debugger: USB Multilink / HiWave

My SPI procedures are like this:

void SPI_INIT(void) {
SPI0CR1 = 0x50; // SPI enabled, master mode
SPI0CR2 = 0;
SPI0BR = 0x77; // Very slow baud
}

void SPI_ThrowCatch(unsigned char data) {
while(!(SPI0SR & 0x20)); /* Wait for SPTEF set */
SPI0DR = mydata;
while(!(SPI0SR & 0x80)); /* Wait for SPIF set */
return SPI0DR;
}

Now what happens is that when I try to send a byte it actually gets send (I have checked with a scope) however, the procedure stalls at the SPIF check! It never gets any further.
I don’t use any interrupts but the global interrupt is enabled. The uP never leaves this proc! I have tried setting up the SPI in all different ways with no result. Then I checked the assembler, and I see that compiler optimizes the byte check to a bit check… And that is my best answer to my problems. Maybe the flag can’t be checked just as a bit. In the datasheet it is described that to clear the flags one has to read the SPI0SR. I have tried to remove all optimizing in the compiler. However it still makes the check in bit level instead on byte level.

NB: EDIT! I have now tried: while(!((unsigned char) (SPI0SR & 0x80))); with no result. So it's not the bit check causing the problem!

Anyone have an idea about what could cause my problem?

Best regards
Jan Thogersen

Message Edited by Trace on 03-13-200607:17 AM

Outcomes