Discussion group dedicated to the Philips LPC2000 family of ARM MCUs
Hello
could someone be so kind and say, what is wrong in following code? Or
maybe it is ok, but it doesn't work... I want trigger an interrupt
using UART0. I am using Keil. (UART0 is ok, it sends a string from tab).
thanks in advance
int i,j;
char tab[] = "UART0 is working properly";
void UART0INT() __irq
{
IO0CLR |= 0x20000; //clr P0.17 (it's a LED)
for(i=0;i<5;i++)
{
for(j=0;j<50000;j++){}
}
send_char_u0('A');
VICVectAddr = 0x00000000; //dummy write
}
int main(void)
{
PLL_ON();
LED_init();
VPBDIV = 0x1;
UART0_init();
IO0SET |= 0x20000; //set P0.17
send_string_u0(tab);
VICIntSelect = 0x00000000;
VICVectAddr0 = (unsigned) UART0INT;
VICVectCntl0 = 0x26; //UART0
VICIntEnable = 0x40; //bit 6 = UART0
while(1)
{
}
return 0;
}
Hi,
we could do with the function UART0_init from your code, however I suspect
your problem is that you're not reading U0IIR to clear the UART IRQ. You
also have a huge delay inside your IRQ which kind of defeats the point of
using it. Have a look at the description of U0IIR register.
Here is a working example from a 2129 which should work equally well on your
chip with minor modification:
void main(void)
{
// init the serial ports
init_serial();
// main loop
while(1)
{
for(;;);
}
}
void init_serial (void) // Initialize Serial Interface
{
//UART0
VPBDIV = 0x00000001; //Set PClk to 60Mhz
PINSEL0 = 0x00000005; //Enable TxD0, RxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x00000084; // 9600 Baud Rate @ 60MHz VPB Clock
U0DLM = 0x00000001;
U0LCR = 0x00000003; // DLAB = 0
U0IER = 0x00000001; //enable rx data available interrupt
VICVectCntl1 = 0x00000026;
VICVectAddr1 = (unsigned)uart0_irq;
VICIntEnable |= 0x00000040;
U0FCR = 0x00000001; //Enable FIFO & trigger level to 1 bytes
}
static unsigned int U0IIR_copy;
void uart0_irq(void) __irq
{
//check for a character from the UART0 RX FIFO
if((U0LSR & 0x01) == 0x01) //if there is a character
{
toggle_LED(1); //do this to suit your board
}
//exit ISR
U0IIR_copy = U0IIR;
VICVectAddr = 0x00000000; //dummy write to re-enable interrupt for next
time
}
-----Original Message-----
From: lpc2000@lpc2... [mailto:lpc2000@lpc2...]On Behalf
Of grodo2k
Sent: 21 March 2006 11:38
To: lpc2000@lpc2...
Subject: [lpc2000] interrupts + Keil + LPC2294
Hello
could someone be so kind and say, what is wrong in following code? Or
maybe it is ok, but it doesn't work... I want trigger an interrupt
using UART0. I am using Keil. (UART0 is ok, it sends a string from tab).
thanks in advance
int i,j;
char tab[] = "UART0 is working properly";
void UART0INT() __irq
{
IO0CLR |= 0x20000; //clr P0.17 (it's a LED)
for(i=0;i<5;i++)
{
for(j=0;j<50000;j++){}
}
send_char_u0('A');
VICVectAddr = 0x00000000; //dummy write
}
int main(void)
{
PLL_ON();
LED_init();
VPBDIV = 0x1;
UART0_init();
IO0SET |= 0x20000; //set P0.17
send_string_u0(tab);
VICIntSelect = 0x00000000;
VICVectAddr0 = (unsigned) UART0INT;
VICVectCntl0 = 0x26; //UART0
VICIntEnable = 0x40; //bit 6 = UART0
while(1)
{
}
return 0;
}
Yahoo! Groups Links
Thank you, I'll try it and say if it works by me.
Andrew Berney <amb@amb@...> wrote: Hi,
we could do with the function UART0_init from your code, however I suspect
your problem is that you're not reading U0IIR to clear the UART IRQ. You
also have a huge delay inside your IRQ which kind of defeats the point of
using it. Have a look at the description of U0IIR register.
Here is a working example from a 2129 which should work equally well on your
chip with minor modification:
void main(void)
{
// init the serial ports
init_serial();
// main loop
while(1)
{
for(;;);
}
}
void init_serial (void) // Initialize Serial Interface
{
//UART0
VPBDIV = 0x00000001; //Set PClk to 60Mhz
PINSEL0 = 0x00000005; //Enable TxD0, RxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x00000084; // 9600 Baud Rate @ 60MHz VPB Clock
U0DLM = 0x00000001;
U0LCR = 0x00000003; // DLAB = 0
U0IER = 0x00000001; //enable rx data available interrupt
VICVectCntl1 = 0x00000026;
VICVectAddr1 = (unsigned)uart0_irq;
VICIntEnable |= 0x00000040;
U0FCR = 0x00000001; //Enable FIFO & trigger level to 1 bytes
}
static unsigned int U0IIR_copy;
void uart0_irq(void) __irq
{
//check for a character from the UART0 RX FIFO
if((U0LSR & 0x01) == 0x01) //if there is a character
{
toggle_LED(1); //do this to suit your board
}
//exit ISR
U0IIR_copy = U0IIR;
VICVectAddr = 0x00000000; //dummy write to re-enable interrupt for next
time
}
-----Original Message-----
From: lpc2000@lpc2... [mailto:lpc2000@lpc2...]On Behalf
Of grodo2k
Sent: 21 March 2006 11:38
To: lpc2000@lpc2...
Subject: [lpc2000] interrupts + Keil + LPC2294
Hello
could someone be so kind and say, what is wrong in following code? Or
maybe it is ok, but it doesn't work... I want trigger an interrupt
using UART0. I am using Keil. (UART0 is ok, it sends a string from tab).
thanks in advance
int i,j;
char tab[] = "UART0 is working properly";
void UART0INT() __irq
{
IO0CLR |= 0x20000; //clr P0.17 (it's a LED)
for(i=0;i<5;i++)
{
for(j=0;j<50000;j++){}
}
send_char_u0('A');
VICVectAddr = 0x00000000; //dummy write
}
int main(void)
{
PLL_ON();
LED_init();
VPBDIV = 0x1;
UART0_init();
IO0SET |= 0x20000; //set P0.17
send_string_u0(tab);
VICIntSelect = 0x00000000;
VICVectAddr0 = (unsigned) UART0INT;
VICVectCntl0 = 0x26; //UART0
VICIntEnable = 0x40; //bit 6 = UART0
while(1)
{
}
return 0;
}
Yahoo! Groups Links
SPONSORED LINKS
Microcontrollers
Microprocessor Intel
microprocessors
Pic microcontrollers
---------------------------------
YAHOO! GROUPS LINKS
---------------------------------
---------------------------------
Yahoo! Travel
Find great deals to the top 10 hottest destinations!
[Non-text portions of this message have been removed]
Andrew, thank you very much ;) In fact I am working with CrossWorks but I coudn't
trigger any interrupt there, so I thought, maybe I will do it in Keil. But it didn't work
either. Now it is working ;) It helped me much, thanks again ;)
Grodo Grodo <grodo2k@grod...> wrote: Thank you, I'll try it and say if it
works by me.
Andrew Berney <amb@amb@...> wrote: Hi,
we could do with the function UART0_init from your code, however I suspect
your problem is that you're not reading U0IIR to clear the UART IRQ. You
also have a huge delay inside your IRQ which kind of defeats the point of
using it. Have a look at the description of U0IIR register.
Here is a working example from a 2129 which should work equally well on your
chip with minor modification:
void main(void)
{
// init the serial ports
init_serial();
// main loop
while(1)
{
for(;;);
}
}
void init_serial (void) // Initialize Serial Interface
{
//UART0
VPBDIV = 0x00000001; //Set PClk to 60Mhz
PINSEL0 = 0x00000005; //Enable TxD0, RxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x00000084; // 9600 Baud Rate @ 60MHz VPB Clock
U0DLM = 0x00000001;
U0LCR = 0x00000003; // DLAB = 0
U0IER = 0x00000001; //enable rx data available interrupt
VICVectCntl1 = 0x00000026;
VICVectAddr1 = (unsigned)uart0_irq;
VICIntEnable |= 0x00000040;
U0FCR = 0x00000001; //Enable FIFO & trigger level to 1 bytes
}
static unsigned int U0IIR_copy;
void uart0_irq(void) __irq
{
//check for a character from the UART0 RX FIFO
if((U0LSR & 0x01) == 0x01) //if there is a character
{
toggle_LED(1); //do this to suit your board
}
//exit ISR
U0IIR_copy = U0IIR;
VICVectAddr = 0x00000000; //dummy write to re-enable interrupt for next
time
}
-----Original Message-----
From: lpc2000@lpc2... [mailto:lpc2000@lpc2...]On Behalf
Of grodo2k
Sent: 21 March 2006 11:38
To: lpc2000@lpc2...
Subject: [lpc2000] interrupts + Keil + LPC2294
Hello
could someone be so kind and say, what is wrong in following code? Or
maybe it is ok, but it doesn't work... I want trigger an interrupt
using UART0. I am using Keil. (UART0 is ok, it sends a string from tab).
thanks in advance
int i,j;
char tab[] = "UART0 is working properly";
void UART0INT() __irq
{
IO0CLR |= 0x20000; //clr P0.17 (it's a LED)
for(i=0;i<5;i++)
{
for(j=0;j<50000;j++){}
}
send_char_u0('A');
VICVectAddr = 0x00000000; //dummy write
}
int main(void)
{
PLL_ON();
LED_init();
VPBDIV = 0x1;
UART0_init();
IO0SET |= 0x20000; //set P0.17
send_string_u0(tab);
VICIntSelect = 0x00000000;
VICVectAddr0 = (unsigned) UART0INT;
VICVectCntl0 = 0x26; //UART0
VICIntEnable = 0x40; //bit 6 = UART0
while(1)
{
}
return 0;
}
Yahoo! Groups Links
SPONSORED LINKS
Microcontrollers
Microprocessor Intel
microprocessors
Pic microcontrollers
---------------------------------
YAHOO! GROUPS LINKS
---------------------------------
---------------------------------
Yahoo! Travel
Find great deals to the top 10 hottest destinations!
[Non-text portions of this message have been removed]
SPONSORED LINKS
Microcontrollers
Microprocessor Intel
microprocessors
Pic microcontrollers
---------------------------------
YAHOO! GROUPS LINKS
---------------------------------
---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
[Non-text portions of this message have been removed]
______________________________