We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
dear all i have written the foll. code for uart0 interrupt in lpc2148. i have baudrate=9609 transmission of first letter 'D' is done but my interrupt is not generated and due to this second letter 'E' is not getting trasmitted. pls guide me.
#include <Philips\LPC2148.h> void timer0ISR(void) __attribute__ ((interrupt ("IRQ"))); void eint0ISR(void) __attribute__ ((interrupt ("IRQ"))); void uart0ISR(void) __attribute__ ((interrupt ("IRQ"))); void init_pll(void); void init_mam(void); void init_vpb(void); void init_port(void); void delay(void); void init_timer0(void); void init_extint0(void); void init_uart0(void); void init_vic(void); unsigned char timer0_flag=0; unsigned char eint0_flag=0; unsigned char txf=0; unsigned char rxdat; void init_pll(void) { //system clock //PLLCFG = 0x00100100; //p=2 (PSEL=01) and m=5-1 (MSEL=00100) PLLCFG = 0x22; //48Mhz m = 4-1 = 3 i.e 00010 // PLLCFG = 0x23; //60Mhz m=5-1=4 i.e 00011 PLLCON = 0x01; PLLFEED = 0xaa; PLLFEED = 0x55; while((PLLSTAT & 0x400) == 0); PLLCON = 0x03; PLLFEED = 0xaa; PLLFEED = 0x55; //usb clock //PLL48CFG = 0x00100011; //p=2 (PSEL=01) and m=4-1 (MSEL=00011) PLL48CFG = 0x23; PLL48CON = 0x01; PLL48FEED = 0xaa; PLL48FEED = 0x55; while((PLL48STAT & 0x400) == 0); PLL48CON = 0x03; PLL48FEED = 0xaa; PLL48FEED = 0x55; } void init_mam(void) { MAMTIM = 0x00000001; MAMCR = 0x02; } void init_vpb(void) { VPBDIV = 0x01; } void init_timer0(void) { T0IR = 0xff; //clr the pending flags of interrupt //T0CTCR = 0x00; //timer mode T0PR = 1000; //prescalar maximum count value keep it 1000 and change T0MR0 T0PC = 0; T0MCR = 0x0003; //MR0I=interrupt when TC=MR and reset T0MR0 = 1000; //match the final value (using ) //T0TC = 0; T0TCR = 0x02; //reset the timer T0TCR = 0x01; //enable the timer } void init_extint0(void) { EXTINT = 0x01; //clr interrupt bit INTWAKE = 0x0000; EXTMODE = 0x01; //EINT0 edge sensitive EXTPOLAR = 0x01; //EINT0 rising edge } void init_uart0(void) { /* formula for BR calculation: =PCLK x mulval / [(16 x (16 x U0DLM + U0DLL))x(MULVAL + DIVADDVAL) 9609 = 48Mhz x 5 / [(16 x (16 x 0 + 223)) x (5 + 7)] */ U0LCR = 0x83; U0FDR = 0x52; U0DLM = 0x00; //U0DLM = 5 and U0DLL = 223 (0xDF) for 48Mhz U0DLL = 0xDf; //keeping DIVADDVAL = 0x02; MULVAL = 0x05; U0LCR = 0x03; U0FCR = 0xC5; U0IER = 0x00000003; //RI and TI interrupt } void init_vic(void) { //TIMER0 //VICSOFTINTCLEAR = 0x00000010; //timer0 interrupt clr VICINTENABLE = 0x00000010; //enable timer0 interrupt VICINTSELECT = 0x00000000; //select timer0 interrupt ad IRQ i.e bit 4=0 //VICDEFVECTADDR = (unsigned long int)timer0ISR; do not use when more than one interrupts are used VICVECTADDR0 = (unsigned long int)timer0ISR; VICVECTCNTL0 = 0x20 | 0x04; //bit 5 is enabled the slot to produce unique interrupt address for enabled timer0 interrupt //EINT0 VICINTENABLE |= 0x00004000; //enable EINT0 interrupt VICINTSELECT = 0x00000000; //select EINT0 interrupt as IRQ i.e bit 14=0 VICVECTADDR1 = (unsigned long int)eint0ISR; VICVECTCNTL1 = 0x20 | 0x0e; //UART0 VICINTENABLE |= 0x00000040; //enable UART0 interrupt VICINTSELECT = 0x00000000; //select UART0 interrupt as IRQ i.e bit 6=0 VICVECTADDR2 = (unsigned long int)uart0ISR; VICVECTCNTL2 = 0x20 | 0x06; } void init_port(void) { PINSEL0 = 0x00000005; //p0.15 and p0.7 as GPIO P0.1=RXD P0.0=TXD //PINSEL1 = 0x00000000; PINSEL1 = 0x00000001; //p0.16 as EINT0 PINSEL2 = 0x00000000; IO0DIR = 0xffffffff; IO0CLR = 0xffffffff; } void delay(void) { unsigned int i,j; for(i=0;i<50000;i++) { j = 0; } } //interrupt void timer0ISR(void) { T0IR = 0xff; if(timer0_flag) IO0SET |= 0x00008000; else IO0CLR |= 0x00008000; timer0_flag = ~timer0_flag; VICVECTADDR = 0x00; } void eint0ISR(void) { EXTINT = 0x01; if(eint0_flag) IO0SET |= 0x00000080; else IO0CLR |= 0x00000080; eint0_flag = ~eint0_flag; VICVECTADDR = 0x00; } void uart0ISR(void) { unsigned char a; /* if((U0LSR & 0x20) == 1) //transmit flag enable { txf = 0; } if((U0LSR & 0x01) == 1) //receive flag enable { rxdat = U0RBR; } */ if((U0IIR & 0x0e) == 0x0010) { while(!(U0LSR & 0x20)); txf = 0; } else if((U0IIR & 0x0e) == 0x0100) { while(!(U0LSR & 0x01)); rxdat = U0RBR; } else if((U0IIR & 0x0e) == 0x0110) { a = U0LSR; } else if((U0IIR & 0x0e) == 0x1100) { while(!(U0LSR & 0x01)); rxdat = U0RBR; } VICVECTADDR = 0x00; } void main(void) { init_pll(); init_mam(); init_vpb(); init_port(); init_timer0(); init_extint0(); init_uart0(); init_vic(); U0THR = 'D'; txf = 1; while(txf); U0THR = 'E'; txf = 1; while(txf); while(1) { if(rxdat == 'A') { IO0SET |= 0x00004000; } if(rxdat == 'B') { IO0CLR |= 0x00004000; } /* IO0SET = 0xffffffff; delay(); IO0CLR = 0xffffffff; delay(); */ } }
my other interrupts of EINT0 and timer0 are working fine. but uart0 interrupt is not generated
hello pls reply i cant find the solution thank you
The LPC2148 is not one I'm particularly familiar with, but I doubt that lines like
else if((U0IIR & 0x0e) == 0x1100)
are going to do much.