I'm speaking by SPI to a SRAM. With serial clock=1MHz reading function is:
unsigned char RAM_read_byte(void)
{
volatile unsigned char data;
volatile unsigned int i;
//read the byte
data=UCB0RXBUF; //to flush buffer, without does not work
while (!(UCB0IFG&UCTXIFG)); // USCI_B0 TX buffer ready?
UCB0TXBUF=0;
while (!(UCB0IFG&UCTXIFG)); // USCI_B0 TX buffer ready?
for(i=0; i<10; i++){}
while (!(UCB0IFG&UCRXIFG)); // USCI_B0 RX buffer ready?
data=UCB0RXBUF;
return data;
}
and for writing:
void RAM_write_byte(unsigned char data)
{
volatile unsigned int i;
//send the data
while (!(UCB0IFG&UCTXIFG)); // USCI_B0 TX buffer ready?
UCB0TXBUF=data;
while (!(UCB0IFG&UCTXIFG)); // USCI_B0 TX buffer ready?
for(i=0; i<10; i++){}
}
If i omit the delay loop for(i=0; i<10; i++){} nothing works. If serial clock rises to 10MHz i can exclude the delay loop.
UCTXIFG sets when transmit buffer is empty, so this should mean that data has been transmitted, so no delay should be needed.
Decreasing further the clock, delay must be increased. UCTXIFG works only if interrupt enabled?
Thanks for help, Enzo