Working code for external interrupt using EINT3 and two external interrupt GPIOs. Generating two signals on pins p29 & p30, and capturing that signal on pins p5(P0.9) & p6(P0.8) each change asociated with one of the four embedded LEDs.
Revision 0:a3cf97864ad5, committed 2016-02-09
- Comitter:
- pistolero992000
- Date:
- Tue Feb 09 02:24:49 2016 +0000
- Commit message:
- Input Capture (External Interrupt) example using two signals and two GPIO for external interrupt.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Feb 09 02:24:49 2016 +0000 @@ -0,0 +1,69 @@ +/* +****************************************************************************************************** + Name : Input Capture + Author : Francisco Pizarro + Version : 1.0 + Copyright : Free + Description : Input capture or External interrupt of two pins + based on: http://anhnvnguyen.blogspot.cl/2010/04/lpc17xx-gpio-basic_05.html +****************************************************************************************************** +*/ + +#include "mbed.h" +#include "LPC17xx.h" +#define GPIO_INT8 1 << 8// GPIO interrupt->p0.9->PIN "p6" +#define GPIO_INT9 1 << 9// GPIO interrupt->p0.9->PIN "p5" +#define LED1 1 << 18// LED1->p1.18 +#define LED2 1 << 20// LED2->p1.20 +#define LED3 1 << 21// LED3->p1.21 +#define LED4 1 << 23// LED4->p1.23 + +DigitalOut Signal1(p30); +DigitalOut Signal2(p29); + +extern "C" { + void EINT3_IRQHandler(void) + { + if (LPC_GPIOINT->IO0IntStatR & GPIO_INT9) { //Evaluates if p5 is interrupted + LPC_GPIOINT->IO0IntClr=GPIO_INT9; // Clears interrupted pin p5 flag + if (LPC_GPIO1->FIOPIN & LED1) { // Toggles LED1 between on & off + LPC_GPIO1->FIOCLR |= LED1; + } else { + LPC_GPIO1->FIOSET |= LED1; + } + } + + if (LPC_GPIOINT->IO0IntStatR & GPIO_INT8) {//Evaluates if p6 is interrupted + LPC_GPIOINT->IO0IntClr=GPIO_INT8; // Clears interrupted pin p5 flag + if (LPC_GPIO1->FIOPIN & LED3) { // Toggles LED3 between on & off + LPC_GPIO1->FIOCLR |= LED3; + } else { + LPC_GPIO1->FIOSET |= LED3; + } + } + } +} + +int main(void) +{ + LPC_GPIO0->FIODIR &= ~GPIO_INT8 | ~GPIO_INT9; //set both p5 (p0.9) & p6 (p0.8) as inputs + LPC_GPIO1->FIODIR |= LED1 | LED2 | LED3 | LED4; // set LED pins as outputs (p0.18+p0.20+p0.21+p0.23) + + LPC_GPIOINT->IO0IntEnR |=GPIO_INT8; // Enable external interrupt on p6 on rising edge trigger + LPC_GPIOINT->IO0IntEnR |=GPIO_INT9; // Enable external interrupt on p5 on rising edge trigger + NVIC_EnableIRQ(EINT3_IRQn); // Enable external NVIC EINT3 + + while(1) { // simple square signal generation to test the interrupts on pins p5 & p6 + Signal1=1; LPC_GPIO1->FIOSET |= LED2; + Signal2=1; LPC_GPIO1->FIOSET |= LED4; wait_ms(100); + Signal2=0; LPC_GPIO1->FIOCLR |= LED4; wait_ms(100); + Signal2=1; LPC_GPIO1->FIOSET |= LED4; wait_ms(100); + Signal2=0; LPC_GPIO1->FIOCLR |= LED4; wait_ms(100); + + Signal1=0; LPC_GPIO1->FIOCLR |= LED2; + Signal2=1; LPC_GPIO1->FIOSET |= LED4; wait_ms(100); + Signal2=0; LPC_GPIO1->FIOCLR |= LED4; wait_ms(100); + Signal2=1; LPC_GPIO1->FIOSET |= LED4; wait_ms(100); + Signal2=0; LPC_GPIO1->FIOCLR |= LED4; wait_ms(100); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Feb 09 02:24:49 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32 \ No newline at end of file