UART Receive not working on SAM3X8E

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

BillyK
Posts: 1
Joined: Sun Oct 11, 2015 8:38 pm

UART Receive not working on SAM3X8E

Sun Oct 11, 2015 8:45 pm

Hello,

I am using an Arduino Due to send and receive serial characters through the UART. I tried loading up Atmel's example from ASF with the PDC, and when running it, I received the header at the beginning of the program as expected. However, when it sent characters back, they were all zeroes. Then, I tried to write my own test echo program that sends a character at the beginning of the program, and waits to echo back all other characters received. The character in the beginning sends fine, and the interrupt is triggered upon receiving a character, however the character received always equals 0. The code I used is pasted below. Any ideas as to how I can get it to receive characters properly? Thanks for your help!

Code: Select all

#include <asf.h>

void UART_Handler() {
	uint32_t status = UART->UART_SR;
	if((status & UART_SR_RXRDY) == UART_SR_RXRDY) {
		while((UART->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY);
		//UART->UART_THR = UART->UART_RHR;
		uint8_t test = UART->UART_RHR;
		UART->UART_THR = test;
	}
}

int main (void)
{
	// Insert system clock initialization code here (sysclk_init()).
	sysclk_init();
	board_init();

	// Insert application code here, after the board has been initialized.
	pmc_enable_periph_clk(ID_PIOA);
	pio_configure_pin(PIO_PA8_IDX, (PIO_PERIPH_A | PIO_DEFAULT));
	pio_configure_pin(PIO_PA9_IDX, (PIO_PERIPH_A | PIO_DEFAULT));
	
	pmc_enable_periph_clk(ID_UART);
	UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ;

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

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

	// Configure baudrate (asynchronous, no oversampling)
	UART->UART_BRGR = (sysclk_get_cpu_hz() / 9600) >> 4 ;

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

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

	// Enable receiver and transmitter
	UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
	
	while((UART->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY);
	UART->UART_THR = 'x';
	
	while(1) {
		
	}
	
}

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest