UART Interrupt on SAM 3X8E

Hello...can uart interrupt functionality be done by directly using the registers of SAM 3X8E.I am trying to use UART interrupt of Due board by directly accessing registers of the controller in it. But no success yet...
Please have a look at it.....any help always welcomed......
THanks.......
#define __CORTEX_M (0x03)
#include<stdio.h>
#include<stdint.h>
#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB)

// enum IRQn = {8};
//{
// UART_IRQn = 8;
//
//}
//;
volatile unsigned int recbyte;
unsigned int sr_reg;

#define PMC_MCKR* (volatile unsigned long*) (0x400E0630)
#define PMC_PCER0* (volatile unsigned long*) (0x400E0610)
#define PMC_WPMR* (volatile unsigned long*) (0x400E06E4)
#define PIO_PDR* (volatile unsigned long*) (0x400E0E04)
#define UART_CR* (volatile unsigned long*) (0x400E0800)
#define UART_MR* (volatile unsigned long*) (0x400E0804)
#define UART_BRGR* (volatile unsigned long*) (0x400E0820)
#define UART_THR* (volatile unsigned long*) (0x400E081C)
#define UART_SR* (volatile unsigned long*) (0x400E0814)
#define UART_RHR* (volatile unsigned long*) (0x400E0818)
//#define PIO_PUER* (volatile unsigned long*) (0x400E0E640)
#define PIO_ABSR* (volatile unsigned long*) (0x400E0E70)
#define UART_IER* (volatile unsigned long*) (0x400E0808)
#define UART_IDR* (volatile unsigned long*) (0x400E080C)
#define NVIC_ISER0* (volatile unsigned long*) (0xE000E100)
//void NVIC_SetPriorityGrouping(void);

void NVIC_EnableIRQ(void);

void NVIC_DisableIRQ(void);

void setup()
{
//clk_define();
uart_define();
//void NVIC_SetPriorityGrouping(void);
//void NVIC_EnableIRQ(void);
//NVIC_SetPriorityGrouping(UART_IRQN,0x0);
NVIC_EnableIRQ(UART_IRQn);

}
void UART_IRQHandler(void)
{
sr_reg = UART_SR;
if((UART_SR & 0x0000001) == 0x01)
{
recbyte = UART_RHR;
UART_THR = recbyte;

}
}

void clk_define(void)
{
PMC_WPMR=0x00;
PMC_MCKR=0x01;
PMC_PCER0=0x100;
}
void uart_define(void)
{
PMC_WPMR=0x00;
PIO_ABSR=0x00;
PIO_PDR=0x300;
UART_CR=0x50; //control reg
UART_MR=0x800; //mode reg
UART_IDR=0XFFFFFFFF;
UART_BRGR=0x222; //baud rate
UART_IER=0x01; //interrupt enable
NVIC_ISER0=0x100;
// NVIC_EnableIRQ(UART_IRQn);
//NVIC_SetPriorityGrouping(UART_IRQN,0x0);

}
void loop()
{
}

Format your code in code tags (the # button at the top when you are editing), and instead of using magic numbers with no explanations how about a few comments and/or use the predefined bit macros.

IE

PIO_PDR=0x300;

do we have to go and look up what the bits are?


Rob

maharaj_44:
Hello...can uart interrupt functionality be done by directly using the registers of SAM 3X8E.I am trying to use UART interrupt of Due board by directly accessing registers of the controller in it. But no success yet...

Of course it can be done or how else would it work for the Arduino Serial class(es)?

Have you looked at those sources to see how it is done there? Good starting point
I would have thought.

[Whoops, think I mis-spoke, apparantly the existing code polls - but yes interrupts
will work, you have to read the datasheet thoroughly and proceed carefully. Look
at libsam sources too]