SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By oahmad
#107734
I have setup a board with a momentary button on Port 2.10; I setup the code as a gpio interrupt on falling edge, it doesn't interrupt.

Maybe this is because I'm confused about the difference between an external interrupt and a gpio interrupt
.
I looked at lpc17xx.h and it looks like there is no irq for a gpio interrupt (I am utilizing CMSIS), only for external interrupt 0 through 3. What is the correct irq to use?
Code: Select all

// ***** EINT2 Initialization function *****
// Setup External Interrupt
void EINT2_init (void)
{
	// Set PINSEL4 [21:20] = 00 for P2.10 as GPIO
	LPC_PINCON->PINSEL4 &= ~(0x11 << 20);

	//set the interrupt 2.10 for falling edge
	LPC_GPIOINT->IO2IntEnF &= ~(1<<10);

	// Enable External Interrupt 2
	NVIC_EnableIRQ(EINT2_IRQn );
}

// ***** EINT2 Interrupt Handler*****
void EINT2_IRQHandler(void)
{

	//clear the interrupt
	LPC_GPIOINT->IO2IntClr |= (1<<10);

	leds_invert();  //this has no relevance in this discussion
}
By oahmad
#107736
Hi again,
I just read the LPC17xx user manual more carefully again, and the gpio interrupts for ports 0 and 2 are actually tied to external interrupt 3. Begs the question: why have external interrupts when the gpio interrupts accomplish the same thing? Someone please explain.

So, I changed my code to utilize external interrupt 3, however, it still doesn't interrupt. Any suggestions?

Thanks!
Code: Select all
// ***** EINT3 Initialization function *****
// Setup External Interrupt
void EINT3_init (void)
{
	// Set PINSEL4 [21:20] = 01 for P2.10 as gpio
	LPC_PINCON->PINSEL4 &= ~(0x11 << 20);
	//LPC_PINCON->PINSEL4 |= (0x01 << 20);

	//set the interrupt 2.10 for falling edge
	LPC_GPIOINT->IO2IntEnF &= ~(1<<10);

	// Enabled External Interrupt 0 (the ISP button on RDB1768).
	NVIC_EnableIRQ(EINT3_IRQn );
}

// ***** EINT2 Interrupt Handler*****
//will get triggered either due to the <button> or <vsync>
void EINT3_IRQHandler(void)
{
	// Clear interrupt
	//LPC_SC->EXTINT = EINT0_CLR;

	//*****why doesn't this work???
	LPC_GPIOINT->IO2IntClr |= (1<<10);

	leds_invert();
}
By mjbcswitzerland
#108465
Hi

To enable falling edge interrupt on P2.10 you need to set
IO2IntEnF |= 0x0000400;
rather than clear it.

To clear the interrupt in the EXINT3 IRQ you can write
IO2IntClr = 0x0000400;
There is no need to read and OR the content beforehand.

The EXINT3 shares interrupts with the port change interrupts. Both can be used at the same time by checking the interrupt source when handling it.
EXINT3 has the advantage that it supports also level sensitive interrupt rather than just port changes, which means that it can also operate when the device is in an idle state (no active clocks) to wake up the device, which port changes will not be able to (I didn't verify this but it is usually the case).

Regards

Mark
http://www.uTasker.com

P.S. Below is some more general information about sharing port change interrupts and EXTIN3:
Each port on P0 and P2 can generate a rising of falling edge interrupt - this is
however only the case when these are programmed on a pin by pin basis.

The port change interrupts share the EINT3 interrupt vector.

If P2.13 is configured as EINT3 it will generate interrupts according to its
mask (which can also include level sensitive interrupts, which the port change
interrupts can't do).

If P2.13 is left as GPIO it can either be used as state change interrupt or left
as non-interrupt generating GPIO.

When handing EINT3 IRQ the code has to check whether the source is from EINT3,
from a port 0 change or from a port 2 change. It can use the following registers
to identify which source (or sources) caused the IRQ and then handle the one(s)
which are pending:
EXTINT (for possible EINT3)
IOIntStatus (for possible port 0 and port 2 sources)

In the case of port changes, the following register then indicate exactly which
pin change caused the IRQ:
IO0IntStatR - rising edge pins detected on port 0
IO0IntStatF - falling edge pins detected on port 0
IO2IntStatR - rising edge pins detected on port 2
IO2IntStatF - falling edge pins detected on port 2