Am using LPC2148 dev board and this is the code I have implemented
main() {
initClock();
initTimer0();
led_init(); // init p0.21
rs232_init();
while(1) {
led_toggleState(); // toggle led
delay(1000); // 1 sec delay
}
}
void initTimer0() {
T0CTCR = 0x0; //Set Timer 0 into Timer Mode
T0PR = 59999; //Increment T0TC at every 60000 clock cycles
//Count begins from zero hence subtracting 1
//60000 clock cycles @60Mhz = 1 mS
T0TCR = 0x02; //Reset Timer
}
void initClock() {
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
}
void rs232_init() {
PINSEL0 = 0x05; // Enable UART0 pins
U0LCR = 0x83; // 8-bit data, 1 stop bit, no parity
U0DLL = 0x87; // Set baud rate to 9600 bps
U0DLM = 0x01;
U0LCR = 0x03; // Enable UART0
U0IER = IER_RBR | IER_THRE; // Enable THRE and RBR interrupt
U0FCR = 0x07;
VICVectAddr0 = (unsigned long)RS232_ISR;
VICVectCntl0 = 0x00000026;
VICIntEnable = 0x00000040;
}
void __attribute__ ((interrupt("IRQ"))) RS232_ISR(void) {
int iir_value;
iir_value = U0IIR; // read the interrupt identification register
// Check if the interrupt was caused by a received character
if (iir_value & IIR_RDA) {
char rx = U0RBR; // read the received character
U0THR = rx;
// Check if the interrupt was caused by the transmitter becoming empty
} else if (iir_value & IIR_THRE) {
U0LSR; // read the line status register to clear the interrupt flag
}
VICVectAddr = 0x00; // Acknowledge the interrupt
}
In the main function, led blinks every 1sec and if any uart0, recv interrupt occurs, interrupt handler should be reached, but it is never reached I transmit a char from my PC, the code should read it and transmit it back to the Pc, but it is not doing that. Appreciate any help
I found out that we need to update the Startup.S in this way.