This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I have a problem with lpc2148 uart receiver (with interrupt)

Hello Sir,
when I use lpc2148 UART receiver interrupt then microcontroller is not receiving any value
but if I use a simple receiver then it's working correctly and receive correct data.
I'm check this code on both hardware or proteus simulator but it's not working
this is my interrupt code,

#include <lpc21xx.h>
volatile char x;
void initUart0(void);
void Uart0ISR(void) __irq;
void delay(int time)
{
        int i,j;
        for(i=0;i<time;i++)
          for(j=0;j<1275;i++);
}
int main(void)
{
        IO1DIR = 0xFFFF0000;
        IO0DIR = (1<<3);
        initUart0();
        while(1){
         IO1PIN=x<<16;
                delay(1);
        }
}

void initUart0(void)
{

        PINSEL0|=0x00000005;
        U0LCR = 0x83;
        U0DLM = 0x00;
        U0DLL = 19;
        U0LCR = 0X03;
        U0FCR = 0x01;
        VICVectAddr1 = (unsigned long)Uart0ISR;
        VICVectCntl1 = 0x20 | 6;
        VICIntEnable |= (1<<6);
}

void Uart0ISR(void) __irq
{
         x      = U0RBR;
         IOPIN0 ^=(1<<3);
         VICVectAddr = 0x0;

}

and this is my simple code, it is working on both hardware or software correctly


#include <lpc21xx.h>
volatile char x;
void initUart0(void);
char uartoRec();

void delay(int time)
{
        int i,j;
        for(i=0;i<time;i++)
          for(j=0;j<10275;i++);
}
int main(void)
{
        IO1DIR = 0xFFFF0000;
        initUart0();
        while(1){
                IOPIN1 = uartoRec()<<16;
        }
}

void initUart0(void)
{

        PINSEL0|=0x00000005;
        U0LCR=(1<<7);
  U0DLM = 0x00;
  U0DLL = 19;
        U0LCR=0X03;
}
char uartoRec()
{
        while(!(U0LSR&(0x01)));
        x = U0RBR;
        return x;
}


thank you

Parents
  • Good of you to initialize the UART with not a single comment or named constant to make a reader understand how you initialize it.

    Another thing - x is an 8-bit value and you do a 16-bit shift.

    And an ISR is also expected to look at the available flags to figure out the interrupt reason - the UART can produce interrupts for more than just reception of a character.

Reply
  • Good of you to initialize the UART with not a single comment or named constant to make a reader understand how you initialize it.

    Another thing - x is an 8-bit value and you do a 16-bit shift.

    And an ISR is also expected to look at the available flags to figure out the interrupt reason - the UART can produce interrupts for more than just reception of a character.

Children