Hi I'm working with keil And I'm going to use a GPIO interrupt. And the pin PIO0_1 I wrote this program
#include <LPC13xx.h>
void PIOINT0_IRQHandler(void) { LPC_GPIO2->DATA=0xaaa; LPC_GPIO0->IC = (1<<1); }
int main(void){
LPC_GPIO0->DIR = 0x000; LPC_GPIO2->DIR = 0xfff;
LPC_GPIO0->IS = 0x0; LPC_GPIO0->IBE = 0x2; LPC_GPIO0->IEV = 0x0; LPC_GPIO0->IE = 0x2;
NVIC_SetPriority(EINT0_IRQn,0); NVIC_EnableIRQ(EINT0_IRQn);
while(1){ LPC_GPIO2->DATA=0xf0f; LPC_GPIO2->DATA=0x0f0; }
}
But it does not work in keil simulator. Anyone knows the problem? Thanks.
Thanks. startup_LPC13xx.s:
; External Interrupts DCD I2C_IRQHandler ; 16+40: I2C DCD TIMER16_0_IRQHandler ; 16+41: 16-bit Counter-Timer 0 DCD TIMER16_1_IRQHandler ; 16+42: 16-bit Counter-Timer 1 DCD TIMER32_0_IRQHandler ; 16+43: 32-bit Counter-Timer 0 DCD TIMER32_1_IRQHandler ; 16+44: 32-bit Counter-Timer 1 DCD SSP0_IRQHandler ; 16+45: SSP0 DCD UART_IRQHandler ; 16+46: UART DCD USB_IRQHandler ; 16+47: USB IRQ DCD USB_FIQHandler ; 16+48: USB FIQ DCD ADC_IRQHandler ; 16+49: A/D Converter DCD WDT_IRQHandler ; 16+50: Watchdog Timer DCD BOD_IRQHandler ; 16+51: Brown Out Detect DCD FMC_IRQHandler ; 16+52: IP2111 Flash Memory Controller DCD PIOINT3_IRQHandler ; 16+53: PIO INT3 DCD PIOINT2_IRQHandler ; 16+54: PIO INT2 DCD PIOINT1_IRQHandler ; 16+55: PIO INT1 DCD PIOINT0_IRQHandler ; 16+56: PIO INT0 DCD SSP1_IRQHandler ; 16+57: SSP1
LPC13xx.h:
I2C_IRQn = 40, /*!< I2C Interrupt */ TIMER_16_0_IRQn = 41, /*!< 16-bit Timer0 Interrupt */ TIMER_16_1_IRQn = 42, /*!< 16-bit Timer1 Interrupt */ TIMER_32_0_IRQn = 43, /*!< 32-bit Timer0 Interrupt */ TIMER_32_1_IRQn = 44, /*!< 32-bit Timer1 Interrupt */ SSP0_IRQn = 45, /*!< SSP Interrupt */ UART_IRQn = 46, /*!< UART Interrupt */ USB_IRQn = 47, /*!< USB Regular Interrupt */ USB_FIQn = 48, /*!< USB Fast Interrupt */ ADC_IRQn = 49, /*!< A/D Converter Interrupt */ WDT_IRQn = 50, /*!< Watchdog timer Interrupt */ BOD_IRQn = 51, /*!< Brown Out Detect(BOD) Interrupt */ EINT3_IRQn = 53, /*!< External Interrupt 3 Interrupt */ EINT2_IRQn = 54, /*!< External Interrupt 2 Interrupt */ EINT1_IRQn = 55, /*!< External Interrupt 1 Interrupt */ EINT0_IRQn = 56, /*!< External Interrupt 0 Interrupt */ SSP1_IRQn = 57, /*!< SSP1 Interrupt */ } IRQn_Type;
gpio.h:
#define PORT0 0 #define PORT1 1 #define PORT2 2 #define PORT3 3 void PIOINT0_IRQHandler(void); void PIOINT1_IRQHandler(void); void PIOINT2_IRQHandler(void); void PIOINT3_IRQHandler(void); static LPC_GPIO_TypeDef (* const LPC_GPIO[4]) = { LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3 }; void GPIO_IRQHandler(void); void GPIOInit( void ); void GPIOSetInterrupt( uint32_t portNum, uint32_t bitPosi, uint32_t sense, uint32_t single, uint32_t event ); void GPIOIntEnable( uint32_t portNum, uint32_t bitPosi ); void GPIOIntDisable( uint32_t portNum, uint32_t bitPos i ); uint32_t GPIOIntStatus( uint32_t portNum, uint32_t bitPosi ); void GPIOIntClear( uint32_t portNum, uint32_t bitPosi ); void GPIOSetValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal ); void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir );
According to these files I wrote this program.
#include <LPC13xx.h> #define fosc 12 #include "delay.h" #include "gpio.h" void PIOINT0_IRQHandler(void) { uint32_t regVal; gpio0_counter++; regVal = GPIOIntStatus( PORT0, 1 ); if ( regVal ) { p0_1_counter++; GPIOIntClear( PORT0, 1 ); } return; } int main(void){ GPIOSetDir( PORT0, 1, 0 ); GPIOSetInterrupt( PORT0, 1, 0, 0, 0 ); GPIOIntEnable( PORT0, 1 ); while(1); }
But it does not work: Rising edge of the pulse reaches the pins. Interrupt flag is activated. But the interrupt subroutine is not implemented.
At least, you also need to do:
NVIC_EnableIRQ(xxx);
xxx might be EINT0_IRQn.
-> Interrupt flag is activated. Which Interrupt Flag?