cancel
Showing results for 
Search instead for 
Did you mean: 

external interrupt issue

me780411
Associate
Posted on June 17, 2013 at 21:08

Hi there

I'm pretty new to stm world I'm trying to generate an external interruption by pushing the user button on a stm32f4 discovery dev board, I tried to implement the staf via the API provided with the discovery dev board, the program compiles well however if I put a break point inside the IRQ handler and try the program, it doesn't enter the IRQ handler scope when I press the user button Here is my code in the main.c

#include ''stm32f4xx.h''
//Define the gpio init structure
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; //interruption vector structure
EXTI_InitTypeDef EXTI_InitStructure;// ext interupt structure
RCC_ClocksTypeDef RCC_ClockFreq; // the clock frequency structure
void main()
{
/* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode ********/
/* Enable GPIOA clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* Enable SYSCFG clock */
SYSCFG_CompensationCellCmd(ENABLE);
/* Configure PA0 pin as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect EXTI Line0 to PA0 pin via SYSCFG */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
/* Configure EXTI Line0 */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI Line0 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Output clock on MCO1 pin(PA8) and MCO2 pin (PC9)***********************/ 
/* Enable GPIOC peripheral */ 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
/* Configure MCO1 pin(PA8) in alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
/* Configure MCO2 pin(PC9) in alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOC, &GPIO_InitStructure); 
while(1){}
}

here us my code in the stm32f4xx_it.c

void EXTI0_IRQHandler(void)
{
int x = 2; 
}

2 REPLIES 2
Posted on June 17, 2013 at 22:10

 /* Enable SYSCFG clock */

 SYSCFG_CompensationCellCmd(ENABLE); // <<< NO NOT THIS

  /* Enable SYSCFG clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); // <<< THIS

The MCO pins don't appear to be configured properly.

The IRQ Handler doesn't check/clear the interrupt.

Strongly recommend reviewing

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

STM32F4-Discovery_FW_V1.1.0\Project\Peripheral_Examples\EXTI\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anhhuy0701
Associate II
Posted on October 29, 2013 at 15:32