Pages: [1]   Go Down
Author Topic: UART Arduino Due SAM3X8E  (Read 928 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using ATMEL AVR studio 6 to program for the Arduino due and following the manual from Atmel: http://www.atmel.com/Images/doc11057.pdf

I'm trying to figure out how to communicate to the SAM3X8E via TX0, in this case I want the due to send something via the TX line at 9600 baud:

#include <asf.h>
#define UART_CR   *(unsigned volatile char *) (0x400E0800) //Control Register
#define UART_IER  *(unsigned volatile char *) (0x400E0008) //Interrupt Enable Register
#define UART_IDR  *(unsigned volatile char *) (0x400E000C) //Interrupt Disable Register
#define UART_BRGR *(unsigned volatile char *) (0x400E0820) //Baud Rate Generator Register
#define UART_MR   *(unsigned volatile char *) (0x400E0804) //Mode Register
#define UART_THR  *(unsigned volatile char *) (0x400E081C) //Transmit Holding Register
#define UART_IMR   (0x400E0010) //Interrupt Mask Register
#define UART_SR    (0x400E0014) // Status Register

void UART_Init(void){
   
   //Control Register, RX disabled, TX enabled, Status reset.
   UART_CR = 0x160;
   //Baud rate, 9600, 84Mhz.
   UART_BRGR = 0x222;
   //Normal mode.
   UART_MR = 0x00;
   
}

void UART_Out(void){
   
   UART_THR = 0x09;
}

int main (void)
{
   board_init();
   UART_Init();
   UART_Out();
   
}

Unfortunately, I can't seem to get anything working smiley-sad
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Before we deal with the software... Communicate TO the Due on TX? If you're sending something to the Due, you'll be receiving it on the Rx line, not the TX line.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8439
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Most (all?) peripherals on an ARM have to have their clocks enabled before they will work. I assume the UART would be the same.

I haven't programmed on the SAM but for an LPC this is required to get the GPIO ports to work

Code:
// Enable AHB clock for GPIO ports
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<30) | (1<<31);

I'm sure there will be something similar.

_____
Rob
« Last Edit: August 04, 2013, 05:46:43 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Earth
Offline Offline
Sr. Member
****
Karma: 13
Posts: 312
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Heh, it always amazes me the # of people who come on the board to ask questions that obviously indicate that they aren't using the Arduino framework at all. Anyway, looking at the Arduino core library source would help here:

Here is the code that Arduino uses to initialize a UART:
Code:
  // Configure PMC
  pmc_enable_periph_clk( _dwId ) ;

  // Disable PDC channel
  _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ;

  // Reset and disable receiver and transmitter
  _pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS ;

  // Configure mode
  _pUart->UART_MR = UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL ;

  // Configure baudrate (asynchronous, no oversampling)
  _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4 ;

  // Configure interrupts
  _pUart->UART_IDR = 0xFFFFFFFF;
  _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME;

  // Enable UART interrupt in NVIC
  NVIC_EnableIRQ(_dwIrq);

  // Enable receiver and transmitter
  _pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN ;

You'll notice that you do need to enable the clock first.
Logged

Pages: [1]   Go Up
Jump to: