Hello, I am trying to create a manual outgoing buffer for the USART0 on my AT91SAM9261.
What I do is handle the functions
sendchar('h');
sendchar('e');
sendchar('l');
sendchar('l');
sendchar('o');
with the code below. The problem is that I only get the last letter, because the lower branch is never firing, because TXRDY is always high. And when I trace through, I verify that TXRDY does *not* go low when I write something to the transmit holding register.
Isn't it supposed to go low, for exactly this purpose?
Like I said, it seems as if I'm overwriting my outgoing holding register before it can get processed, since I'm only getting the last character.
Any thoughts (or sample code) would be greatly appreciated.
Thanks very much in advance.
Code:
void USART0_sendchar(unsigned char c)
{
AT91_USART0_IDR = TXRDY_BIT; // disable this interrupt
if (AT91_USART0_CSR && TXRDY_BIT)
{
// the transmitter is ready, don't bother with buffer
AT91_USART0_THR = c;
}
else
{
// transmitter is not ready, place it on the buffer
// we handle buffer full by ignoring add'l input
if (usart0_tx_counter < USART0_BUFFER_SIZE)
{
usart0_tx_buffer[usart0_tx_idx] = c;
usart0_tx_idx++;
usart0_tx_idx %= USART0_BUFFER_SIZE;
usart0_tx_counter++;
}
}
AT91_USART0_IER = TXRDY_BIT; // enable this interrupt
}