cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f4 Discovery EXTI Clear pending bit

spencerashiveley
Associate II
Posted on July 20, 2015 at 00:05

Hello all,

I tried searching for a bit but couldn't find anything pertaining to my question.I'm trying to set up an external interrupt but I don't understand why exactly we clear the pending bit in EXTI->PR and not in the NVIC_ICPRx (interrupt clear pending registers). Also on the STM32f4 do I need to set any special clocks for EXTI or just the Portx clock?

#!stm32f4-disco
4 REPLIES 4
Posted on July 20, 2015 at 03:08

You'd need the SYSCFG clock.

The NVIC handles the Cortex-M4 side of the interrupt generation, but as their are often multiple sources the peripheral is where you look for what actually caused the interrupt, and where you clear it as an acknowledgement.

STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\EXTI\EXTI_Example\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
spencerashiveley
Associate II
Posted on July 20, 2015 at 04:47

So if I'm understanding correctly, the NVIC handles interrupts internal to the MPU.  Since I'm interrupting external to the Cortex m4, at the periph, the NVIC isn't set up for that. I go to the peripheral and clear the bit?

megahercas6
Senior
Posted on July 20, 2015 at 17:39

Simple example:

void EXTI_Int(void)
{ 
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOE, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; 
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x10;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
extern uint32_t program_counter;
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
//todo
EXTI_ClearITPendingBit(EXTI_Line13);
}
}

Posted on July 20, 2015 at 19:36

The NVIC is responsible to getting code execution to your IRQHandler. You need to identify and clear the source. For EXTI this is by clearing it on the EXTI peripheral, for things like the USART or ADC reading the data registers can clear the source, ie RXNE or EOC

If things aren't cleared, then the NVIC will cause the IRQHandler to be continuously tail-chained, and your foreground code with never get control again.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..