Dear Friends,
I use UART of MSP430 to communicate with a PC via a UART-to-RS232 module. It functions well, but I need to change delay time between transmitting every byte. The source code was as follows,
int Uart0Tx(char* pcTx, int nLn)
{
int i;
for(i=0;i<nLn;i++)
{
while(!(UC0IFG & UCA0TXIFG)){}; // till UART Transmit buffer is empty
UCA0TXBUF = pcTx[i]; // send the character
Sleep(10);
}
return i;
}
void Sleep(uint32 n_ms)
{
while (n_ms--)
{
__delay_cycles(DELAY_1ms);
}
}
When I use UART with baudrate 9600, I set Sleep(10); while I use UART with baudrate 115200, I must set Sleep(100).
If I don't change the Sleep(n), the received side always miss some bytes.
Did I make anything wrong with UART? Is there any more robust skill to handle UART?
Thank you very much.
Sunglin.