cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f107vc - external interrupt problem

sukrubahadirarslan
Associate III
Posted on October 16, 2013 at 00:21

hello forum . I am trying to use external interrupt but I can't do it and I can't understand what is wrong.

here is my code :

#include ''stm32f10x.h''

#include ''stm32_eval.h''

#include <stdio.h>

GPIO_InitTypeDef gpio_initstructureled;

GPIO_InitTypeDef gpio_initstructurebutton;

EXTI_InitTypeDef exti_initstructureexternalinterrupt;

NVIC_InitTypeDef nvic_initstructure;

void EXTI9_5_IRQHandler()

{

uint8_t leddurumu;

leddurumu = GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_7);

if(leddurumu == Bit_SET)

{GPIO_ResetBits(GPIOD,GPIO_Pin_7);}

else

{GPIO_SetBits(GPIOD,GPIO_Pin_7);}

}

int main(void)

{

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);

gpio_initstructureled.GPIO_Pin = GPIO_Pin_7;

gpio_initstructureled.GPIO_Mode = GPIO_Mode_Out_PP;

gpio_initstructureled.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOD,&gpio_initstructureled);

gpio_initstructurebutton.GPIO_Pin = GPIO_Pin_9;

gpio_initstructurebutton.GPIO_Mode = GPIO_Mode_IPU;

gpio_initstructurebutton.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOB,&gpio_initstructurebutton);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource9);

exti_initstructureexternalinterrupt.EXTI_Line = EXTI_Line9;

exti_initstructureexternalinterrupt.EXTI_Mode = EXTI_Mode_Interrupt;

exti_initstructureexternalinterrupt.EXTI_Trigger = EXTI_Trigger_Falling;

exti_initstructureexternalinterrupt.EXTI_LineCmd = ENABLE;

EXTI_Init(&exti_initstructureexternalinterrupt);

nvic_initstructure.NVIC_IRQChannel = EXTI9_5_IRQn ;

nvic_initstructure.NVIC_IRQChannelPreemptionPriority =0x0f;

nvic_initstructure.NVIC_IRQChannelSubPriority = 0x0f;

nvic_initstructure.NVIC_IRQChannelCmd = ENABLE ;

NVIC_Init(&nvic_initstructure);

  while (1)

  {

  }

}

#ifdef  USE_FULL_ASSERT

/**

  * @brief  Reports the name of the source file and the source line number

  *         where the assert_param error has occurred.

  * @param  file: pointer to the source file name

  * @param  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t* file, uint32_t line)

  /* User can add his own implementation to report the file name and line number,

     ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

so Can you see any problem ? 

thanks for your help 
3 REPLIES 3
Posted on October 16, 2013 at 02:12

Looks reasonable, I'd definitely want the NVIC setup before the EXTI. I don't see the value of the multiple globals.

What are you compiling with? And can you puts some break-points in the handler?

How about reading the button GPIO and using it's state to drive the LED, confirm that's all working.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John F.
Senior
Posted on October 16, 2013 at 12:32

How is the interrupt request cleared?

Posted on October 16, 2013 at 15:48

void EXTI9_5_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line7) != RESET)
{
/* Clear the EXTI line 7 pending bit */
EXTI_ClearITPendingBit(EXTI_Line7);
//...
}
}

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