Help on my first hurdle on USART Interrupt Driven USART RX

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Xmega experts,

I have just started out on using an XMega. I am using the Xplained Xmega-A3BU and I am trying to get the USART RX driven USART working.

Can somebody glance over this to see if I have done something obvious wrong.

I can Transmit data out on the TX pin so I know I have set up the CPU and BAUD rates correctly. (in a previous experiment).

I have looked at other posts in the forum but even understanding their stripped down code and reading the data sheet, I cannot get a result.

Thank you very much in advance.
I have posted my stripped down code just for the USART problem
Pep :?

#define F_CPU 32000000UL
#include 
#include 
volatile int vgUsartFlag;
uint8_t gUsartData;

void init_UART(void)	{
	uint16_t BSEL = 146;
	USARTC0.CTRLB |= (USART_RXEN_bm	| USART_TXEN_bm | USART_CLK2X_bm);
	USARTC0.CTRLC |= (USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc);
	USARTC0.CTRLA |= (USART_RXCINTLVL0_bm | USART_RXCINTLVL1_bm);
	PORTC.DIRSET = PIN3_bm; //RX pin set to in
	PORTC.DIRCLR = PIN2_bm; //TX pin set to out
	USARTC0.BAUDCTRLA = (uint8_t)(BSEL);
	USARTC0.BAUDCTRLB = (uint8_t)(BSEL >> 8);
	USARTC0.BAUDCTRLB |= (0b00001110 << 4);
}

void init_clk()	{
	OSC.CTRL |= OSC_RC32MEN_bm ;
	while ((OSC.STATUS & OSC_RC32MRDY_bm) == 0);
	uint8_t clkctrl;
	clkctrl = (CLK.CTRL & (~CLK_SCLKSEL_gm)) | CLK_SCLKSEL_RC32M_gc;
	CCP = CCP_IOREG_gc;
	CLK.CTRL = clkctrl;
	OSC.CTRL &= ~(OSC_RC2MEN_bm | OSC_XOSCEN_bm | OSC_PLLEN_bm);
}

int main (void){
	cli();
	init_clk();
	init_UART();
	sei();
	vgUsartFlag = 0;
	PORTA_DIR = 0xFF;
	while(1)	{
		if(vgUsartFlag > 0)		{
			vgUsartFlag = 0;
			PORTA.OUT &= ~PIN3_bm;
			_delay_ms(200);
		}
		PORTA.OUT |= PIN3_bm;
		USARTC0.DATA = 'E';
		_delay_ms(200);
	}
}
ISR(USARTC0_RXC_vect)	{
	vgUsartFlag = 1;
	gUsartData = USARTC0.DATA;
	USARTC0.DATA = gUsartData;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I see it, you set USARTC0 receive interrupt level to "hi", but you don't actually enable high-level interrupts. You do this with PMIC_CTRL.

EDIT:

PMIC_CTRL|=PMIC_HILVLEN_bm;

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much ErikT. It works :)