2013-10-15 03:21 PM
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) { }}#endifso Can you see any problem ? thanks for your help2013-10-15 05:12 PM
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.2013-10-16 03:32 AM
How is the interrupt request cleared?
2013-10-16 06:48 AM
void EXTI9_5_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line7) != RESET)
{
/* Clear the EXTI line 7 pending bit */
EXTI_ClearITPendingBit(EXTI_Line7);
//...
}
}