Pages: [1]   Go Down
Author Topic: help with Serial setup  (Read 728 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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:
Code:
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:
Code:
// 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!
« Last Edit: April 01, 2013, 03:38:29 pm by titous » Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do you have to use low level code or can you use the Arduino serial library to set the comms, poll the buffer, then get any traffic?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do you have to use low level code or can you use the Arduino serial library to set the comms, poll the buffer, then get any traffic?

no, i don't have to use lower level code, i just need to take the following code snippet and port it to a DUE:
Code:
   if (*txBufPtr)
    {
      if ((UCSRA) & (1 << UDRE))
      {
        UDR = *txBufPtr++;
  
        // we are done with this msg, get the next one
        if (!*txBufPtr)
          nextMessage();
      }
    }
« Last Edit: April 24, 2013, 04:45:14 pm by titous » Logged

Pages: [1]   Go Up
Jump to: