Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

GPIO interrupts in LPC1768 with KEIL

Status
Not open for further replies.

baby_2

Advanced Member level 4
Joined
Jul 20, 2016
Messages
105
Helped
2
Reputation
4
Reaction score
1
Trophy points
18
Activity points
873
Hello
Here is my code
Code:
#include <LPC17xx.H>

void delay()
{
    int i,j;
    for(i=0;i<2000;i++)
        for(j=0;j<5000;j++);
}

void EINT3_IRQHandler()
{
    LPC_GPIO0->FIOSET=(1<<23);
    LPC_GPIOINT->IO0IntClr = (1<<17);
    delay();

}    


int main()
{
LPC_GPIO0->FIODIR=(1<<23);
LPC_GPIO0->FIODIR=(1<<21);
LPC_GPIOINT->IO0IntEnF = 1<<17;
NVIC_EnableIRQ(EINT3_IRQn);
    
LPC_GPIO0->FIOSET=(1<<21);
        while(1){
        
    }
    }

but it doesn't any action when I press my switch button that it is connected to P0.17

what is my problem?
 

If you are trying to implement delay function inside interrupt, may be arm is too earler for you.
 

I removed delay line in my code but it doesn't work again
 

I correct my code to

Code:
#include <LPC17xx.H>

void delay()
{
	int i,j;
	for(i=0;i<2000;i++)
		for(j=0;j<5000;j++);
}

void EINT3_IRQHandler() 
{
	if(LPC_GPIO0->FIOSET & (1<<22)){
		LPC_GPIO0->FIOCLR |=(1<<22);
	}
	else
	{
		LPC_GPIO0->FIOSET |=(1<<22);
	}

}	


int main()
{
LPC_GPIO0->FIODIR=0x00;
LPC_GPIO0->FIODIR |=(1<<22);
LPC_GPIO0->FIODIR |=(1<<21);
LPC_GPIOINT->IO0IntEnF = 1<<17;
NVIC_EnableIRQ(EINT3_IRQn);
LPC_GPIO0->FIOSET=(1<<21);
		while(1){
		
	}
		
	}
when I push the button for the first time it turns on the LED but for second time it doesn't turn off the LED. I clear interrupt bit with this code , but it doesn't do anything.

Code:
#include <LPC17xx.H>

void delay()
{
	int i,j;
	for(i=0;i<2000;i++)
		for(j=0;j<5000;j++);
}

void EINT3_IRQHandler() 
{
	if(LPC_GPIO0->FIOSET & (1<<22)){
		LPC_GPIO0->FIOCLR |=(1<<22);
	}
	else
	{
		LPC_GPIO0->FIOSET |=(1<<22);
	}
	//LPC_GPIOINT->IO0IntClr |= (1 << 17);

}	


int main()
{
LPC_GPIO0->FIODIR=0x00;
LPC_GPIO0->FIODIR |=(1<<22);
LPC_GPIO0->FIODIR |=(1<<21);
LPC_GPIOINT->IO0IntEnF = 1<<17;
NVIC_EnableIRQ(EINT3_IRQn);
LPC_GPIO0->FIOSET=(1<<21);
		while(1){
		
	}
		
	}

what is my mistake?
 

Taking a quick look at your code, seems unusual to assign a value to a bit but clearing all others.

For example, instead of = (1<<17) I would expect |= (1<<17)
Another point is that your code would become more readable if you assign a macro to the numerical value (1<<17).

I agree to Easyrider83 that there are a lot things to learn before doing something with that uC.

- - - Updated - - -

what is my mistake?

Where in your code it is supposed to toogle the LED ?

- - - Updated - - -

For some reason, my previous reply was merged with the last reply, reordered to the end.
 
  • Like
Reactions: baby_2

    baby_2

    Points: 2
    Helpful Answer Positive Rating
FIOSET and FIOCLR is write-only bitbang registers. You can't read and modify them, only write.
 

Dear Easyrider83
Thank you for your response
but as you see in LPC17xx user manual it mentions FIOSET is R/W register


How can we find out the statues of a PIN instead of FIOSET register?
 

I remove the FIOSET condition and add a global variable,but it won't turn off the led

Code:
#include <LPC17xx.H>

int x;

void delay()
{
	int i,j;
	for(i=0;i<2000;i++)
		for(j=0;j<5000;j++);
}

void EINT3_IRQHandler() 
{
		
	if(x==1){
		LPC_GPIO0->FIOCLR |=(1<<22);
		x=2;
	}
	else
	{
		x=1;
		LPC_GPIO0->FIOSET |=(1<<22);
	}
	

if((LPC_GPIOINT->IO0IntStatF)>>17 & 0x1){
	LPC_GPIOINT->IO0IntClr=(1<<17);
}	

}	


int main()
{
	x=1;
LPC_GPIO0->FIODIR=0x00;
LPC_GPIO0->FIODIR |=(1<<22);
LPC_GPIO0->FIODIR |=(1<<21);
LPC_GPIOINT->IO0IntEnF = 1<<17;
NVIC_EnableIRQ(EINT3_IRQn);
LPC_GPIO0->FIOSET=(1<<21);
		while(1){
	}
		
	}
 

I have no idea how to explain you that you can't use read-modify-write method to BitBang registers!!!
It is same useless how to use delay inside interrupt routine.

LPC_GPIO0->FIOCLR |=(1<<22);
should be
LPC_GPIO0->FIOCLR =(1<<22);

and
LPC_GPIO0->FIOSET |=(1<<22);
should be
LPC_GPIO0->FIOSET =(1<<22);

Also, routine variables have to volatile. And if you not using 'x' anywhere outside one routine, declare it as static inside routine.
 
  • Like
Reactions: baby_2

    baby_2

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top