EmbeddedRelated.com
Forums

FreeRTOS GPIO Interrupt, LPC2378

Started by Baishun Wu May 26, 2011
Hello,

I am currently working on a board with LPC2378 using FreeRTOS. I would like
to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I
have tested the reading of the ports work well. But the interrupt part never
works.

The following is a my code:
// All the include stuffs

void readPos()__attribute__((naked));

int trigger;

int main(){
// initialize GPIO and other stuffs

// Then I started to initialize the interrupt.
IO2_INT_EN_R |= 0xf;
IO2_INT_EN_F |= 0xf;

VICIntEnClr != (1<<17);
VICiIntSelect &= ~(1<<17);
ViICVectCntl17 = 2;
ViICVectAddr17 = (unsigned long) readPos;
VICIntEnable |= (1<<17);

while(1){
//output trigger to uart and display on a PC's screen every
// 1second.
}

return 0;

}

void readPos(){
portSAVE_CONTEXT();

trigger++;

IO2_INT_CLR = 3<<2;
VICVectAddr = 0;

portRESTORE_CONTEXT();

}

I suppose if the interrupt works fine, I would see the "trigger" to
increment whenever there are inputs into the ports. But "trigger" always
stays at 0.

Thanks in advanced for any help and ideas.

Baishun

An Engineer's Guide to the LPC2100 Series

Hi,

I don't think this is a FreeRTOS question, and including FreeRTOS in the
title of you post could be confusing.

If you are having problems with the interrupts, I would recommend
simplifying the code as much as possible first, then get the interrupt
working (without any FreeRTOS code), and only once the interrupt is
working as you require, add in the additional bells and whistles.

I'm not sure you can generate an interrupt on both edges, but will bow
to those more knowledgeable about the LPC2000 specifics to answer that
part of the question (although I could look it up in the manual, I will
leave that to you).
Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers.
More than 7000 downloads per month.

On 26/05/2011 16:55, Baishun Wu wrote:
>
>
> Hello,
>
> I am currently working on a board with LPC2378 using FreeRTOS. I would
> like to do interrupt for GPIO port 2.2 and 2.3 at both falling and
> rising edge. I have tested the reading of the ports work well. But the
> interrupt part never works.
>
> The following is a my code:
> // All the include stuffs
>
> void readPos()__attribute__((naked));
>
> int trigger;
>
> int main(){
> // initialize GPIO and other stuffs
>
> // Then I started to initialize the interrupt.
> IO2_INT_EN_R |= 0xf;
> IO2_INT_EN_F |= 0xf;
>
> VICIntEnClr != (1<<17);
> VICiIntSelect &= ~(1<<17);
> ViICVectCntl17 = 2;
> ViICVectAddr17 = (unsigned long) readPos;
> VICIntEnable |= (1<<17);
>
> while(1){
> //output trigger to uart and display on a PC's screen every
> // 1second.
> }
>
> return 0;
>
> }
>
> void readPos(){
> portSAVE_CONTEXT();
>
> trigger++;
>
> IO2_INT_CLR = 3<<2;
> VICVectAddr = 0;
>
> portRESTORE_CONTEXT();
>
> }
>
> I suppose if the interrupt works fine, I would see the "trigger" to
> increment whenever there are inputs into the ports. But "trigger" always
> stays at 0.
>
> Thanks in advanced for any help and ideas.
>
> Baishun

You can use both edges, there is no problem with that.
For P2.2 & P2.3 you can to set bits 2 & 3 of both registers , this is value C , use set P2.0, P2.1, P2.2, P2.3 using value F but this is not a problem.
You are using a strange way to set the interrupt, you were probably used in 21xx series.
In 23xx/24xx there is no VICVectCntl register and it is a mistake that Keil includes a define that points VICVectCntl to the VICVectPriority location.

The correct code for a vectored interrupt is:
VICVectAddr17 = (unsigned long) readPos; /* set interrupt vector 17 */
VICVectPriority17 = 2 ; /* default priority is 15 (lowest), can be set between 0-15 */
VICIntEnable |= ((unsigned long)1<<17); /* Enable EINT3 Interrupt */

I suppose you are using Keil, in that case you should add __irq to yout interrupt function
__irq void readPos(vild) {
}

there is also this line in your code VICIntEnClr != (1<<17) , what is is supposed to do?
I have only seen != for not equal, it doesn't have an effect in the actual value of the VICIntEnClr, did you mean |
Alex

----- Original Message -----
From: Baishun Wu
To: l...
Sent: Thursday, May 26, 2011 6:55 PM
Subject: [lpc2000] FreeRTOS GPIO Interrupt, LPC2378

Hello,

I am currently working on a board with LPC2378 using FreeRTOS. I would like to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I have tested the reading of the ports work well. But the interrupt part never works.

The following is a my code:
// All the include stuffs

void readPos()__attribute__((naked));

int trigger;

int main(){
// initialize GPIO and other stuffs

// Then I started to initialize the interrupt.
IO2_INT_EN_R |= 0xf;
IO2_INT_EN_F |= 0xf;

VICIntEnClr != (1<<17);
VICiIntSelect &= ~(1<<17);
ViICVectCntl17 = 2;
ViICVectAddr17 = (unsigned long) readPos;
VICIntEnable |= (1<<17);

while(1){
//output trigger to uart and display on a PC's screen every
// 1second.
}

return 0;

}

void readPos(){
portSAVE_CONTEXT();

trigger++;

IO2_INT_CLR = 3<<2;
VICVectAddr = 0;

portRESTORE_CONTEXT();

}

I suppose if the interrupt works fine, I would see the "trigger" to increment whenever there are inputs into the ports. But "trigger" always stays at 0.

Thanks in advanced for any help and ideas.

Baishun
Hi Alex,

I couldn't pass this up. :)

__irq void readPos(vild)

Would that be "wild" in english. (;

Larry

--- In l..., "Alexan_e" wrote:
>
> You can use both edges, there is no problem with that.
> For P2.2 & P2.3 you can to set bits 2 & 3 of both registers , this is value C , use set P2.0, P2.1, P2.2, P2.3 using value F but this is not a problem.
> You are using a strange way to set the interrupt, you were probably used in 21xx series.
> In 23xx/24xx there is no VICVectCntl register and it is a mistake that Keil includes a define that points VICVectCntl to the VICVectPriority location.
>
> The correct code for a vectored interrupt is:
> VICVectAddr17 = (unsigned long) readPos; /* set interrupt vector 17 */
> VICVectPriority17 = 2 ; /* default priority is 15 (lowest), can be set between 0-15 */
> VICIntEnable |= ((unsigned long)1<<17); /* Enable EINT3 Interrupt */
>
> I suppose you are using Keil, in that case you should add __irq to yout interrupt function
> __irq void readPos(vild) {
> }
>
> there is also this line in your code VICIntEnClr != (1<<17) , what is is supposed to do?
> I have only seen != for not equal, it doesn't have an effect in the actual value of the VICIntEnClr, did you mean |>
> Alex
>
> ----- Original Message -----
> From: Baishun Wu
> To: l...
> Sent: Thursday, May 26, 2011 6:55 PM
> Subject: [lpc2000] FreeRTOS GPIO Interrupt, LPC2378
>
> Hello,
>
> I am currently working on a board with LPC2378 using FreeRTOS. I would like to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I have tested the reading of the ports work well. But the interrupt part never works.
>
> The following is a my code:
> // All the include stuffs
>
> void readPos()__attribute__((naked));
>
> int trigger;
>
> int main(){
> // initialize GPIO and other stuffs
>
> // Then I started to initialize the interrupt.
> IO2_INT_EN_R |= 0xf;
> IO2_INT_EN_F |= 0xf;
>
> VICIntEnClr != (1<<17);
> VICiIntSelect &= ~(1<<17);
> ViICVectCntl17 = 2;
> ViICVectAddr17 = (unsigned long) readPos;
> VICIntEnable |= (1<<17);
>
> while(1){
> //output trigger to uart and display on a PC's screen every
> // 1second.
> }
>
> return 0;
>
> }
>
> void readPos(){
> portSAVE_CONTEXT();
>
> trigger++;
>
> IO2_INT_CLR = 3<<2;
> VICVectAddr = 0;
>
> portRESTORE_CONTEXT();
>
> }
>
> I suppose if the interrupt works fine, I would see the "trigger" to increment whenever there are inputs into the ports. But "trigger" always stays at 0.
>
> Thanks in advanced for any help and ideas.
>
> Baishun
>

You made me laugh, thanks.
Two out of 4 letters wrong, how did I manage to do that...

So here is the correct one of course
__irq void readPos(void){
}

Alex :-)
----- Original Message -----
From: Larry Viesse
To: l...
Sent: Friday, May 27, 2011 12:31 AM
Subject: [lpc2000] Re: FreeRTOS GPIO Interrupt, LPC2378

Hi Alex,

I couldn't pass this up. :)

__irq void readPos(vild)

Would that be "wild" in english. (;

Larry

--- In l..., "Alexan_e" wrote:
>
> You can use both edges, there is no problem with that.
> For P2.2 & P2.3 you can to set bits 2 & 3 of both registers , this is value C , use set P2.0, P2.1, P2.2, P2.3 using value F but this is not a problem.
> You are using a strange way to set the interrupt, you were probably used in 21xx series.
> In 23xx/24xx there is no VICVectCntl register and it is a mistake that Keil includes a define that points VICVectCntl to the VICVectPriority location.
>
> The correct code for a vectored interrupt is:
> VICVectAddr17 = (unsigned long) readPos; /* set interrupt vector 17 */
> VICVectPriority17 = 2 ; /* default priority is 15 (lowest), can be set between 0-15 */
> VICIntEnable |= ((unsigned long)1<<17); /* Enable EINT3 Interrupt */
>
> I suppose you are using Keil, in that case you should add __irq to yout interrupt function
> __irq void readPos(vild) {
> }
>
> there is also this line in your code VICIntEnClr != (1<<17) , what is is supposed to do?
> I have only seen != for not equal, it doesn't have an effect in the actual value of the VICIntEnClr, did you mean | >
> Alex
>
>
>
>
>
> ----- Original Message -----
> From: Baishun Wu
> To: l...
> Sent: Thursday, May 26, 2011 6:55 PM
> Subject: [lpc2000] FreeRTOS GPIO Interrupt, LPC2378
>
>
>
> Hello,
>
> I am currently working on a board with LPC2378 using FreeRTOS. I would like to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I have tested the reading of the ports work well. But the interrupt part never works.
>
> The following is a my code:
>
>
> // All the include stuffs
>
> void readPos()__attribute__((naked));
>
> int trigger;
>
> int main(){
> // initialize GPIO and other stuffs
>
> // Then I started to initialize the interrupt.
> IO2_INT_EN_R |= 0xf;
> IO2_INT_EN_F |= 0xf;
>
> VICIntEnClr != (1<<17);
> VICiIntSelect &= ~(1<<17);
> ViICVectCntl17 = 2;
> ViICVectAddr17 = (unsigned long) readPos;
> VICIntEnable |= (1<<17);
>
> while(1){
> //output trigger to uart and display on a PC's screen every
> // 1second.
> }
>
> return 0;
>
> }
>
> void readPos(){
> portSAVE_CONTEXT();
>
> trigger++;
>
> IO2_INT_CLR = 3<<2;
> VICVectAddr = 0;
>
> portRESTORE_CONTEXT();
>
> }
>
> I suppose if the interrupt works fine, I would see the "trigger" to increment whenever there are inputs into the ports. But "trigger" always stays at 0.
>
> Thanks in advanced for any help and ideas.
>
> Baishun
>
I usually blame the batteries in my keyboard for causing that. It can't be my fast hunt and peck typing.

Have a good day,
Larry

--- In l..., "Alexan_e" wrote:
>
> You made me laugh, thanks.
> Two out of 4 letters wrong, how did I manage to do that...
>
> So here is the correct one of course
> __irq void readPos(void){
> }
>
> Alex :-)
> ----- Original Message -----
> From: Larry Viesse
> To: l...
> Sent: Friday, May 27, 2011 12:31 AM
> Subject: [lpc2000] Re: FreeRTOS GPIO Interrupt, LPC2378
>
> Hi Alex,
>
> I couldn't pass this up. :)
>
> __irq void readPos(vild)
>
> Would that be "wild" in english. (;
>
> Larry
>
> --- In l..., "Alexan_e" wrote:
> >
> > You can use both edges, there is no problem with that.
> > For P2.2 & P2.3 you can to set bits 2 & 3 of both registers , this is value C , use set P2.0, P2.1, P2.2, P2.3 using value F but this is not a problem.
> > You are using a strange way to set the interrupt, you were probably used in 21xx series.
> > In 23xx/24xx there is no VICVectCntl register and it is a mistake that Keil includes a define that points VICVectCntl to the VICVectPriority location.
> >
> > The correct code for a vectored interrupt is:
> > VICVectAddr17 = (unsigned long) readPos; /* set interrupt vector 17 */
> > VICVectPriority17 = 2 ; /* default priority is 15 (lowest), can be set between 0-15 */
> > VICIntEnable |= ((unsigned long)1<<17); /* Enable EINT3 Interrupt */
> >
> > I suppose you are using Keil, in that case you should add __irq to yout interrupt function
> > __irq void readPos(vild) {
> > }
> >
> > there is also this line in your code VICIntEnClr != (1<<17) , what is is supposed to do?
> > I have only seen != for not equal, it doesn't have an effect in the actual value of the VICIntEnClr, did you mean |> >
> > Alex
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Baishun Wu
> > To: l...
> > Sent: Thursday, May 26, 2011 6:55 PM
> > Subject: [lpc2000] FreeRTOS GPIO Interrupt, LPC2378
> >
> >
> >
> > Hello,
> >
> > I am currently working on a board with LPC2378 using FreeRTOS. I would like to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I have tested the reading of the ports work well. But the interrupt part never works.
> >
> > The following is a my code:
> >
> >
> > // All the include stuffs
> >
> > void readPos()__attribute__((naked));
> >
> > int trigger;
> >
> > int main(){
> > // initialize GPIO and other stuffs
> >
> > // Then I started to initialize the interrupt.
> > IO2_INT_EN_R |= 0xf;
> > IO2_INT_EN_F |= 0xf;
> >
> > VICIntEnClr != (1<<17);
> > VICiIntSelect &= ~(1<<17);
> > ViICVectCntl17 = 2;
> > ViICVectAddr17 = (unsigned long) readPos;
> > VICIntEnable |= (1<<17);
> >
> > while(1){
> > //output trigger to uart and display on a PC's screen every
> > // 1second.
> > }
> >
> > return 0;
> >
> > }
> >
> > void readPos(){
> > portSAVE_CONTEXT();
> >
> > trigger++;
> >
> > IO2_INT_CLR = 3<<2;
> > VICVectAddr = 0;
> >
> > portRESTORE_CONTEXT();
> >
> > }
> >
> > I suppose if the interrupt works fine, I would see the "trigger" to increment whenever there are inputs into the ports. But "trigger" always stays at 0.
> >
> > Thanks in advanced for any help and ideas.
> >
> > Baishun
>

Maybe you must declare the trigger variable as a volatile int.

* *
73, Fred
PE0FKO

2011/5/26 Baishun Wu

> Hello,
>
> I am currently working on a board with LPC2378 using FreeRTOS. I would like
> to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I
> have tested the reading of the ports work well. But the interrupt part never
> works.
>
> The following is a my code:
> // All the include stuffs
>
> void readPos()__attribute__((naked));
>
> int trigger;
>
> int main(){
> // initialize GPIO and other stuffs
>
> // Then I started to initialize the interrupt.
> IO2_INT_EN_R |= 0xf;
> IO2_INT_EN_F |= 0xf;
>
> VICIntEnClr != (1<<17);
> VICiIntSelect &= ~(1<<17);
> ViICVectCntl17 = 2;
> ViICVectAddr17 = (unsigned long) readPos;
> VICIntEnable |= (1<<17);
>
> while(1){
> //output trigger to uart and display on a PC's screen every
> // 1second.
> }
>
> return 0;
>
> }
>
> void readPos(){
> portSAVE_CONTEXT();
>
> trigger++;
>
> IO2_INT_CLR = 3<<2;
> VICVectAddr = 0;
>
> portRESTORE_CONTEXT();
>
> }
>
> I suppose if the interrupt works fine, I would see the "trigger" to
> increment whenever there are inputs into the ports. But "trigger" always
> stays at 0.
>
> Thanks in advanced for any help and ideas.
>
> Baishun
>
>
>
It might help us if you post the code you are using in the while loop. Maybe there is something wrong in that code.

Larry

--- In l..., pe0fko wrote:
>
> Maybe you must declare the trigger variable as a volatile int.
>
> * *
> 73, Fred
> PE0FKO
> 2011/5/26 Baishun Wu >
> >
> > Hello,
> >
> > I am currently working on a board with LPC2378 using FreeRTOS. I would like
> > to do interrupt for GPIO port 2.2 and 2.3 at both falling and rising edge. I
> > have tested the reading of the ports work well. But the interrupt part never
> > works.
> >
> > The following is a my code:
> >
> >
> > // All the include stuffs
> >
> > void readPos()__attribute__((naked));
> >
> > int trigger;
> >
> > int main(){
> > // initialize GPIO and other stuffs
> >
> > // Then I started to initialize the interrupt.
> > IO2_INT_EN_R |= 0xf;
> > IO2_INT_EN_F |= 0xf;
> >
> > VICIntEnClr != (1<<17);
> > VICiIntSelect &= ~(1<<17);
> > ViICVectCntl17 = 2;
> > ViICVectAddr17 = (unsigned long) readPos;
> > VICIntEnable |= (1<<17);
> >
> > while(1){
> > //output trigger to uart and display on a PC's screen every
> > // 1second.
> > }
> >
> > return 0;
> >
> > }
> >
> > void readPos(){
> > portSAVE_CONTEXT();
> >
> > trigger++;
> >
> > IO2_INT_CLR = 3<<2;
> > VICVectAddr = 0;
> >
> > portRESTORE_CONTEXT();
> >
> > }
> >
> > I suppose if the interrupt works fine, I would see the "trigger" to
> > increment whenever there are inputs into the ports. But "trigger" always
> > stays at 0.
> >
> > Thanks in advanced for any help and ideas.
> >
> > Baishun
> >
> >
>