[email protected] (Daniel Néri) wrote:
> Andreas Schwarz <[email protected]> writes:
>
> > I'm talking to a MMC in SPI-Mode, and if I don't check TXEPT (or
> > alternatively URXIFG0) it doesn't work reliably!
>
> It's actually pretty simple: UTXIFG gets set when UTXBUF becomes
> empty, i.e. when the data has moved from UTXBUF to the transmitter
> shift register and starts to shift out on the output pin. TXEPT is set
> when UTXBUF *and* the transmitter shift register are empty, i.e. after
> the last bit of the data has been shifted out (and no new data has
> been written to UTXBUF).
Then I don't understand why it isn't sufficient to test UTXIFG in my
application:
#define SPI_TXC (IFG2 & UTXIFG0)
#define SPI_RXC (IFG2 & URXIFG0)
...
TXBUF0 = 0x40+command;
while (!SPI_TXC);
for(count=0;count<4;count++) {
TXBUF0 = 0x00;
while (!SPI_TXC);
}
TXBUF0 = 0xFF; // CRC not used, send 0xFF
while (!SPI_TXC);
TXBUF0=DUMMY; // 8 clock cycles
while (!SPI_TXC);
// while(!SPI_RXC); // <- only _here_ I need to test URXIFG or TXEPT to make
it work!
TXBUF0=DUMMY; // send dummy byte to read response
while (!SPI_TXC);
while (!SPI_RXC);
response=RXBUF0;