To configure an external interrupt one must configure the external interrupt (EXTI) peripheral as well as the NVIC peripheral. The general procedure is as follows:
EXTI9_5_IRQn is used for EXT5 to EXT9
EXTI15_10_IRQn is used for EXT10 to EXT15
Write your interrupt service routine (ISR). Inside your interrupt service routine, check the source of the interrupt�either the GPIO pin directly or the external interrupt line. Once you figure out which one triggered the interrupt, perform the interrupt processing scheme associated with it. Make sure that you clear the corresponding pending bit of the external interrupt lines of interest in the EXT_PR (external interrupt pending register) register by writing a '1' to it.
Example code: configure PB1 as interrupt pin
Example code: configure PB1 as interrupt pin
Note: this code is used in uVsion which can be downloaded in https://www.keil.com/demo/eval/armv4.htm
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stm32f4xx.h>
uint32_t i=0;
void EXTI1_IRQHandler(void)
{
if(EXTI->PR & (1<<1))
{
i++; //increase value if interrupt happen
}
EXTI->PR=(1<<1); //clear interrupt flag for EXTI1
}
void exticonf(void)
{
//Config PB1 as interrupt pin
NVIC_EnableIRQ(EXTI1_IRQn); // Enable IRQ for ext. signals, line EXTI1_IRQn
//NVIC_EnableIRQ(EXTI9_5_IRQn); //External Line[9:5] Interrupts
//NVIC_EnableIRQ(EXTI15_10_IRQn); //External Line[15:10] Interrupts
NVIC_SetPriority(EXTI1_IRQn, 15);
SYSCFG->EXTICR[0] = SYSCFG_EXTICR1_EXTI1_PB; // select PB to make IRQ EXTI1
EXTI->RTSR = 0x00000002; // allow positive edge interrupt for EXTI1
EXTI->IMR = 0x00000002; // enable interrupt on EXTI1
}
int main (void) {
RCC->APB2ENR |= 0x00004000; // Clock SYSCFG - system configuration controller, necessary for interrupt
exticonf();
while(1) { };
}
------------------------------------------------------------------------------------------------------
Reference site:
http://www.fmf.uni-lj.si/
http://homepage.cem.itesm.mx/
Reference site:
http://www.fmf.uni-lj.si/
http://homepage.cem.itesm.mx/
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :