EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

GPIO Interrupt on LPC1768

Started by Wagner Loebel April 1, 2010
Hi all...

Can anybody give a simple "recipe" on how to setup a GPIO (P0.21) on LPC1768 to generate an interrupt ?

The Keil code bundle has an example that shows how to work with interrupt on EINT0 but I need it on another pin.
Thanks in advance.

An Engineer's Guide to the LPC2100 Series

Hi:

GPIO Interrupts are associated to the EINT3 Interrupt Vector, even if you don't use the External Interrupt Pin #3

Section 5.6 of the User Manual describes the registers that you need to initialize to get the interrupt.

Regards,

Alex
--- In l..., "Wagner Loebel" wrote:
>
> Hi all...
>
> Can anybody give a simple "recipe" on how to setup a GPIO (P0.21) on LPC1768 to generate an interrupt ?
>
> The Keil code bundle has an example that shows how to work with interrupt on EINT0 but I need it on another pin.
> Thanks in advance.
>

Hi Alex

Thanks for your reply.

I found a code in a slovenian forum that helped me a lot. Someone else finds its usefull.

http://213.250.2.95/elektronik.si/phpBB2/viewtopic.php?p6164&sid~16cff4b66d5f5c70695fc7fd2b867d

Chers,

Wagner

----- Original Message -----
From: alexander_ribero
To: l...
Sent: Friday, April 02, 2010 12:39 AM
Subject: [lpc2000] Re: GPIO Interrupt on LPC1768

Hi:

GPIO Interrupts are associated to the EINT3 Interrupt Vector, even if you don't use the External Interrupt Pin #3

Section 5.6 of the User Manual describes the registers that you need to initialize to get the interrupt.

Regards,

Alex

--- In l..., "Wagner Loebel" wrote:
>
> Hi all...
>
> Can anybody give a simple "recipe" on how to setup a GPIO (P0.21) on LPC1768 to generate an interrupt ?
>
> The Keil code bundle has an example that shows how to work with interrupt on EINT0 but I need it on another pin.
>
>
> Thanks in advance.
>
Hi Wagner

You will need to use a GPIO port interrupt on the pin that you want -
this is possible on PORT 0 and PORT 2, which shares the EINT3 interrupt.
The following is a snippet of code to do this:
#define PORT0_BIT21 0x00200000
IO0IntClr = PORT0_BIT21; // clear possible interrupts
on the defined port inputs
fnEnterInterrupt(irq_EINT3_ID, PRIORITY, (void (*)( void
))EINT3_Interrupt);// configure and enter the handling interrupt routine
in the vector table
IO0IntEnF |= PORT0_BIT21; // set falling edge
The configuration is very simple (also characteristics such as pull-up
may be set) but assumes that you have a routine to enter the interrupt.
(Note that the handler is the EINT3 handler, which needs to be shared
with EINT3 if used)

Handling the interrupt is simple if only one known port bit is used; the
following handler is however more general purpose and can dispatch a
handler for each pin if required (using the handler list in
gpio_handlers_0[])

static __interrupt void EINT3_Interrupt(void)
{
unsigned long ulInterrupts;
unsigned long ulBit;

if (IOIntStatus & P0int) {
// an interrupt from port 0 is pending
ulInterrupts = IO0IntStatR;
// get rising edge interrupts on port 0
ulInterrupts |= IO0IntStatF;
// also falling edge interrupts
IO0IntClr = ulInterrupts;
// clear the ones which will be handled
ulBit = 0x00000001;
iInterrupt = 0;
while (ulInterrupts >= ulBit) {
// for each input change that has been detected on port 0
if (ulInterrupts & ulBit) {
// an enabled input has changed
uDisable_Interrupt();
// protect the call from interrupts
(gpio_handlers_0[iInterrupt])();
// call the application handler
uEnable_Interrupt();
// release
ulInterrupts &= ~ulBit;
}
iInterrupt++;
ulBit <<= 1;
}
}
}

Normally it would handle PORT 2 also (if used) as well as the EINT3
itself.

This code is available in the present uTasker LPC17XX Beta version
(http://www.utasker.com/forum/index.php?topic2.0
), whereby a first
full release will be available shortly which will additionally include
USB CDC device and possibly USB mass storage to go with the utFAT for SD
card, plus boot loaders based on Ethernet and USB.
This also includes an LPC17XX simulator so all port interrupts can be
fully tested and verified before moving to the hardware (see screen
shot: http://www.uTasker.com/Demos/uSimLPC17XX.jpg
).

Regards

Mark

www.uTasker.com

--- In l..., "Wagner Loebel"
wrote:
>
> Hi all...
>
> Can anybody give a simple "recipe" on how to setup a GPIO (P0.21) on
LPC1768 to generate an interrupt ?
>
> The Keil code bundle has an example that shows how to work with
interrupt on EINT0 but I need it on another pin.
> Thanks in advance.
>

The 2024 Embedded Online Conference