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
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.
[modify] LPC2148 UART receiver interrupt code sir, I am added comment in this code, now this modified code is working on proteus but on hardware, it shows the 0xFF value of entered character
#include <lpc214x.h> volatile long x; void initUart0(void); void delay(int time) //delay function { int i,j; for(i=0;i<time;i++) for(j=0;j<10275;j++); } void Uart0ISR(void) __irq; void initClocks(void) { PLL0CON = 0x01; //Enable PLL PLL0CFG = 0x24; //Multiplier and divider setup PLL0FEED = 0xAA; //Feed sequence PLL0FEED = 0x55; while(!(PLL0STAT & 0x00000400)); //is locked? PLL0CON = 0x03; //Connect PLL after PLL is locked PLL0FEED = 0xAA; //Feed sequence PLL0FEED = 0x55; VPBDIV = 0x01; // PCLK is same as CCLK i.e.60 MHz } int main(void) { IO0DIR = 0xFF0000; initClocks(); //init Clocks initUart0(); // init uart0 while(1){ IOSET0 = x<<16; // { ascii value set on IOPIN 16 - IOPIN 23} delay(500); IOCLR0 = x<<16; // clear IOPIN delay(5); } } void initUart0(void) { PINSEL0 = 0x5; /* Select TxD for P0.0 and RxD for P0.1 */ U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit | DLAB set to 1 */ U0DLL = 78; //baud Rate 9600 at 12MHZ U0DLM = 1; U0FDR = 0xF1; /* MULVAL=15(bits - 7:4) , DIVADDVAL=0(bits - 3:0)*/ U0LCR &= 0x0F; // Set DLAB=0 to lock MULVAL and DIVADDVAL U0IER=0x1; // Enable RBR interrupt VICVectAddr1 = (unsigned long)Uart0ISR; VICVectCntl1 = 0x20 | 6; VICIntEnable |= (1<<6); //BaudRate is now ~9600 and we are ready for UART communication! } void Uart0ISR(void) __irq { long int regVal; regVal = U0IIR; x = U0RBR; //read data VICVectAddr = 0x0; }/* char uartoRec() { while(!(U0LSR&(0x01))); x = U0RBR; return x; } */