0
\$\begingroup\$

I am working on ATSAM4E8C on custom board. The uart0 and its interrupt is working fine but while on uart1 I faced an strange issue. The uart1 is sending the data but interrupt handler is not calling while data reception. I have also confirmed the data reception using polling. Then I copy pasted the same code in ASF where it is working fine (the interrupt handler is invoking). Below is the code. The same code is working in ASF (Echo the received character). Any help is appreciated.

void clk_init()

{

PMC->CKGR_MOR |= (CKGR_MOR_KEY_PASSWD | CKGR_MOR_MOSCRCEN); //Enable Fast RC oscillator but DO NOT switch to RC now

/* Wait the Fast RC to stabilize */
while (!(PMC->PMC_SR & PMC_SR_MOSCRCS));

/* Change Fast RC oscillator frequency */
PMC->CKGR_MOR = (PMC->CKGR_MOR & ~CKGR_MOR_MOSCRCF_Msk) |
CKGR_MOR_KEY_PASSWD | CKGR_MOR_MOSCRCF_12_MHz;

/* Wait the Fast RC to stabilize */
while (!(PMC->PMC_SR & PMC_SR_MOSCRCS));

/* Switch to Fast RC */
PMC->CKGR_MOR = (PMC->CKGR_MOR & ~CKGR_MOR_MOSCSEL) |
CKGR_MOR_KEY_PASSWD;

}

void UART1Init() {

PIOA->PIO_PDR|=PIO_PDR_P5;  //Disable PIO
PIOA->PIO_PDR|=PIO_PDR_P6;

//Enable peripheral
PIOA->PIO_ABCDSR[0]&=~PIO_ABCDSR_P5;
PIOA->PIO_ABCDSR[1]|=PIO_ABCDSR_P5;

PIOA->PIO_ABCDSR[0]&=~PIO_ABCDSR_P6;
PIOA->PIO_ABCDSR[1]|=PIO_ABCDSR_P6;

//Enable uart clock
PMC->PMC_PCER1|=(1<<13);
//Set Baud rate
UART1->UART_BRGR= 78; // baud rate is 9600

UART1->UART_MR|=UART_MR_PAR_NO;
UART1->UART_CR|=UART_CR_TXEN|UART_CR_RXEN;
UART1->UART_IER|=UART_IER_RXRDY;
irq_register_handler(UART1_IRQn, 0);

}

void U1WriteData(char data) {

while(!(UART1->UART_SR&UART_SR_TXEMPTY));    //Wait For Transmitter to become ready
//Now write
UART1->UART_THR=data;

}

int main (void) {

clk_init();
UART1Init();

while(1)
{
}

}

void UART1_Handler() {

uint8_t data=UART1->UART_RHR;

U1WriteData(data);

}

\$\endgroup\$
0
\$\begingroup\$

Ok, it worked...The exception table in startup code was incorrect. I just replace the exception table from AFS to my project and it worked.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.