# uart inerrupt

**URL:** <https://community.sparkfun.com/t/uart-inerrupt/16267>\
**Category:** MicroMod\
**Tags:** arm-lpc\
**Created:** [June 21, 2010, 9:51am UTC](https://community.sparkfun.com/t/uart-inerrupt/16267 "2010-06-21T09:51:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![naz](https://avatars.discourse-cdn.com/v4/letter/n/e99b99/32.png) [@naz](https://community.sparkfun.com/u/naz)\
**Post date:** [June 21, 2010, 9:51am UTC](https://community.sparkfun.com/t/uart-inerrupt/16267/1 "2010-06-21T09:51:34Z")

</div>

Hello all,

i have written code for rx interrupt,but it’s not entering into interrupt function,anyone can tell me where i am doing mistake.

void InitSerial (void)

{

VPBDIV = 0x00;

PLL0CFG = 0x24;

PLL0FEED = 0x55;

PLL0CON = 0x03;

PINSEL0 = 0x00050000; // Enable RxD0 and TxD0

U1LCR = 0x83; // 8 bits,no Parity,1 Stop bit

U1DLL = 97; // 9600 Baud @ 12MHz Clock

U1DLM=0x00;

U1LCR = 0x03; // DLAB = 0

U1FCR=0x07;

U1IIR = 0xC1; // FIFO Enable, No pend. Int

U1FDR = 0x00000010;

VICProtection = 0; // disable protection

//VICIntEnClear = 0xFFFFFFFF; // disable all interruptions

VICIntSelect &= 0xFFFFFF7F; // IRQ -uart1

VICVectAddr1 = (unsigned long)uart1; // Set interrupt vector in 1

VICVectCntl0 = 0x20 | 7; // use it for Serial 0 Int \*/

VICIntEnable |= 0x00000080;

U1IER |= 0x04;

}

int main (void)

{

//char arr[10];

//static int i;

IODIR1 = 0x00FF0000;

InitSerial();

}

int ReceiveChar (void)

{

while (!(U1LSR & 0x01));

return (U1RBR);

}

int SendChar (int ch)

{

while (!(U1LSR & 0x20));

if(ch == ‘\n’)

return (U1THR = CR);

else

return (U1THR = ch);

}

\_\_irq void uart1(void)

{

unsigned int i;

unsigned char ch;

unsigned char RecivedString[50];

ch = ReceiveChar();

if(ch != CR)

{

RecivedString _= ch;_  
_i++;_  
_}_  
_else_  
_{_  
_SendChar(‘\n’);_  
_RecivedString = 0x00;_  
_i = 0;_  
_}_  
_VICVectAddr = 0;_  
_}_

---

<div class="post-metadata">

**Author:** ![cfb](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@cfb](https://community.sparkfun.com/u/cfb)\
**Post date:** [June 21, 2010, 11:25pm UTC](https://community.sparkfun.com/t/uart-inerrupt/16267/2 "2010-06-21T23:25:26Z")

</div>

I can see several doubtful areas. The first one I would check is:

VICVectAddr1 = …

VICVectCntl0 = …

(Read the VIC chapter in the User Manual).

---

<div class="post-metadata">

**Author:** ![stevech](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@stevech](https://community.sparkfun.com/u/stevech)\
**Post date:** [June 22, 2010, 1:49am UTC](https://community.sparkfun.com/t/uart-inerrupt/16267/3 "2010-06-22T01:49:58Z")

</div>

here’s a section of what I use for LPC21xx.

Common ISR for all (both) UARTs.

An array of structs where each member is a UART’s static variables and ring buffer data/pointers.

Coded for IAR’s IDE/compiler. (free if program \< 32KB)

```auto
// Initialization
 switch (uartNo) {
    case 0:      
        // pointer to hardware registers for a UART
        uartBuf->VIC_IEbit = (1<<VIC_UART0); // UART0 Interrupt enable bit
        VICIntEnClear = uartBuf->VIC_IEbit; // disable UARTn interrupt
        uartio = uartBuf->iobase = (struct LPC_UART *)UART0_BASE; // a constant
        PINSEL0 |= (1<<0); // _bit.P0_0 = 1; //Uart0 TX function select pins 0,1
        PINSEL0 |= (1<<2); // _bit.P0_1 = 1; //Uart0 RX function select       
        // setup VIC for interrupts from UART
        VICIntSelect &= ~(1<<VIC_UART0); // mark as vectored, not FIQ
        VICVectAddresses[vectorNo] = (unsigned int)&UART0_isr; // Install ISR in VIC addr slot 
        VICVectControls[vectorNo] = 0x20 | VIC_UART0; // IRQ type, int enabled
        break;
    
  case 1: // same code as case 0 but for the UART1 constants
        uartBuf->VIC_IEbit = (1<<VIC_UART1); // UART0 Interrupt enable bit
        VICIntEnClear = uartBuf->VIC_IEbit; // disable UARTn interrupt
        uartio = uartBuf->iobase = (struct LPC_UART *)UART1_BASE; // a constant
        PINSEL0 |= (1<<16); // _bit.P0_8 = 1; //Uart1 TX function select
        PINSEL0 |= (1<<18); // _bit.P0_9 = 1; //Uart1 RX function select
        // setup VIC for interrupts from UART
        VICIntSelect &= ~(1<<VIC_UART1);
        VICVectAddresses[vectorNo] = (unsigned int)&UART1_isr; // Install ISR in VIC addr slot 
        VICVectControls[vectorNo] = 0x20 | VIC_UART1; // IRQ type, int enabled
        break;

///... omitted code here

/ *************************************************************************
Interrupt Function: handle UART0 TX and RX. 
************************************************************************* /
__irq__ arm void UART0_isr(void)
{
  UART_isr(0);
}
/ *************************************************************************
Interrupt Function: handle UART1 TX and RX
************************************************************************* /
__irq__ arm void UART1_isr(void)
{
  UART_isr(1);
}

/ *************************************************************************
  *************************************************************************
  *************************************************************************
  *************************************************************************
  Interrupt Function: handle any UARTx TX and RX interrupt
  ************************************************************************* /
__arm void UART_isr(unsigned char uartNo)
{

```
