Hi everyone,
I'm modifying a piece of code written for the UNO to run on the DUE. The code basically listens for commands over serial from a PC and then acts on those commands. I've got everything ported over except for the lines dealing with serial communication. The specific part I have yet to port over looks very similar to an example detailed in the datasheet for the ATmega328P (Arduino UNO); the code from the datasheed (p.184) looks like:
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
From datasheet -- The function simply waits for the transmit buffer to be empty by checking the UDRE Flag, before loading it with new data to be transmitted.
on the DUE side I've written it up as:
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( USART1->US_CSR & US_CSR_TXRDY))
;
/* Put data into buffer, sends the data */
USART1->US_THR = data;
}
However, the function isn't working properly - it always stays in the while loop after a message is sent over serial from PC. I was hoping someone could help me out with this since I'm not real familiar with this lower level stuff. I'm not sure if/how I have to setup the serial connection by enabling transmission as well as the baud rate. For now I've got things setup like:
// Reset and disable receiver & transmitter
USART1->US_CR = US_CR_RSTRX | US_CR_RSTTX | US_CR_RXDIS | US_CR_TXDIS;
// Configure mode
USART1->US_MR = 0;
// Enable transmitter
USART1->US_CR = US_CR_TXEN;
Can anyone help or offer pointers as to what I may be doing wrong? Thanks!