hello,
I know that you are busy or on holidays, but I need your help for a problem with UART0 interrupt routine on an Olimex LPC2106 board.
Below my code:
#include <LPC210x.h>
#define OSCILLATOR_CLOCK_FREQUENCY 14745600 //in MHz
#define CR 0x0D
#define P0_7 0x00000080
void Init_UART0(unsigned int baud);
unsigned int Get_CCLK(void);
unsigned int Get_PCLK(void);
void UART_putc(char ch);
void UART_puts(char *c);
char UART_getc(void);
void Init_Interrupt(void);
void uart0_irq(void);
unsigned int cclk = 0;
unsigned int pclk = 0;
unsigned int divisor = 0;
unsigned int U0IIR_status = 0;
int main(void)
{
Init_Interrupt();
Init_UART0(9600); //Initialize the UART
/*UART_putc(‘q’); // transmission of characters works properly
UART_putc(‘z’);
UART_putc(‘e’);
UART_putc(‘r’);
UART_putc(‘t’);
UART_putc(‘y’);
*/
while(1){ };
return 0;
}
void UART_putc(char ch)
{
while ((U0LSR & 0x20) == 0);
U0THR = ch;
}
void UART_puts(char *c)
{
while (*c)
{
UART_putc(*c);
c++;
}
}
char UART_getc(void) /* Read character from Serial Port */
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void uart0_irq(void)
{
//check for a character from the UART0 RX FIFO
if((U0LSR & 0x01) == 0x01) //if there is a character
{
IOSET = P0_7; // turn off the LED
}
//exit ISR
U0IIR_status = U0IIR; // clear interrupt
VICVectAddr = 0x00000000;//write to re-enable interrupt for next time
}
void Init_UART0 (unsigned int baud)
{
U0IER = 0x00; // disable all interrupts
U0FCR = 0x07; // enable and reset buffers
divisor = Get_PCLK() / (16 * baud);
U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
U0DLL = divisor & 0xFF;
U0DLM = (divisor >> 8) & 0xFF;
U0LCR &= ~0x80; /* Disable DLAB */
PINSEL0 = 0x00000005; //Enable TxD0, RxD0
IODIR = P0_7;
IOCLR = P0_7; //turn on the LED
U0IER = 0x01; //enable Rx interrupt
}
void Init_Interrupt(void)
{
VICIntSelect = 0x00000000; // use UART0 as IRQ interrupt
VICIntEnable = 0x00000040; // enable UART0 interrupt
VICVectCntl1 = 0x00000026;
VICVectAddr1 = (unsigned)uart0_irq;
}
unsigned int Get_CCLK(void)
{
//return real processor clock speed
return OSCILLATOR_CLOCK_FREQUENCY * (PLLCON & 1 ? (PLLCFG & 0xF) + 1 : 1);
}
unsigned int Get_PCLK(void)
{
//VPBDIV - determines the relationship between the processor clock (cclk)
//and the clock used by peripheral devices (pclk).
unsigned int divider;
switch (VPBDIV & 3)
{
case 0: divider = 4; break;
case 1: divider = 1; break;
case 2: divider = 2; break;
}
return Get_CCLK() / divider;
}
the serial transmission without interrupt works properly, but I want use interrupt with UART0.
The code above must turn off the LED when it receives a character.
Can you tell me what’s wrong with the code, or tell me where I can find examples of UART0 interrupt routine.
thanks for your helps