I have found it is important to read the Rx buffer before any SPI
transaction as any existing chars will get the whole thing out of sync. Also
I time the transaction from the char received from the slave. My experience
is with an F149.

This is the code I use:

void spi_wr_rd(u8_t *tx_data, u8_t *rx_data)
{
        *rx_data = RXBUF0;              // nuke any previous data and clear the 
Rx flag
        while( !(UTXIFG0 & IFG1) );     // Tx must be ready for this to work, 
but wait
anyway
        TXBUF0 = *tx_data;              // send a byte out
        while( !(URXIFG0 & IFG1) );     // wait for a response
        *rx_data = RXBUF0;              // and read it
}

This code seems to be reliable in my application, but your mileage may vary
:-)

Hope this helps

Graeme





Reply via email to