2014-01-06 02:32 AM
In my test code below the four leds flash (as expected). The EXTI15_10_IRQHandler fires when i bring PA13 to high or to low. However when i bring PC13 to high/low, nothing happens. it took me almost a week on google but not sure what i am doing wrong.
I tried Pin0, Pin1 PortA and PortB, the same problem the EXTI0_IRQHandler and EXTI1_IRQHandler fire in PortA onlyAny help is always appreciated!#include ''stm32f4xx.h''#include ''stdio.h''#include ''string.h''#include ''stm32f4xx_syscfg.h''char Res=0;char i=0;char myFlag=0;void Delay(uint32_t ms);void InitGPIO(void);void InitUSART(void);void EXTILineC13_Config(void);void EXTILineA13_Config(void);void ActiveLed(char Led_Id);int main(void){ InitGPIO(); EXTILineC13_Config(); EXTILineA13_Config(); while (1){ }}void Delay(uint32_t ms){ uint32_t TimeOut; TimeOut = 168000*ms; while (--TimeOut);}void EXTILineC13_Config(void){ EXTI_InitTypeDef aEXTI; NVIC_InitTypeDef aNVIC; GPIO_InitTypeDef aGPIO; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); aGPIO.GPIO_Mode=GPIO_Mode_IN; aGPIO.GPIO_PuPd=GPIO_PuPd_NOPULL; aGPIO.GPIO_Pin=GPIO_Pin_13; aGPIO.GPIO_Speed=GPIO_Speed_100MHz; GPIO_Init(GPIOC,&aGPIO); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource13); aEXTI.EXTI_Line=EXTI_Line13; aEXTI.EXTI_Mode=EXTI_Mode_Interrupt; aEXTI.EXTI_Trigger=EXTI_Trigger_Rising; aEXTI.EXTI_LineCmd=ENABLE; EXTI_Init(&aEXTI); aNVIC.NVIC_IRQChannel=EXTI15_10_IRQn; aNVIC.NVIC_IRQChannelPreemptionPriority=0x0F; aNVIC.NVIC_IRQChannelSubPriority=0x0F; aNVIC.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&aNVIC);}void EXTILineA13_Config(void){ EXTI_InitTypeDef aEXTI; NVIC_InitTypeDef aNVIC; GPIO_InitTypeDef aGPIO; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); aGPIO.GPIO_Mode=GPIO_Mode_IN; aGPIO.GPIO_PuPd=GPIO_PuPd_NOPULL; aGPIO.GPIO_Pin=GPIO_Pin_13; aGPIO.GPIO_Speed=GPIO_Speed_100MHz; GPIO_Init(GPIOA,&aGPIO); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource13); aEXTI.EXTI_Line=EXTI_Line13; aEXTI.EXTI_Mode=EXTI_Mode_Interrupt; aEXTI.EXTI_Trigger=EXTI_Trigger_Rising; aEXTI.EXTI_LineCmd=ENABLE; EXTI_Init(&aEXTI); aNVIC.NVIC_IRQChannel=EXTI15_10_IRQn; aNVIC.NVIC_IRQChannelPreemptionPriority=0x0F; aNVIC.NVIC_IRQChannelSubPriority=0x0F; aNVIC.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&aNVIC);}void InitUSART(void){ USART_InitTypeDef aUSARTInit; GPIO_InitTypeDef aGPIOInit; NVIC_InitTypeDef aNVICInit; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA , ENABLE); aGPIOInit.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10; aGPIOInit.GPIO_Speed=GPIO_Speed_100MHz; aGPIOInit.GPIO_Mode=GPIO_Mode_AF; aGPIOInit.GPIO_OType=GPIO_OType_PP; aGPIOInit.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOA,&aGPIOInit); GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); aUSARTInit.USART_BaudRate=2400; aUSARTInit.USART_Mode=USART_Mode_Tx|USART_Mode_Rx; aUSARTInit.USART_Parity=USART_Parity_No; aUSARTInit.USART_StopBits=USART_StopBits_1; aUSARTInit.USART_WordLength=USART_WordLength_8b; aUSARTInit.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_Init(USART1,&aUSARTInit); USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); USART_Cmd(USART1,ENABLE); aNVICInit.NVIC_IRQChannel=USART1_IRQn; aNVICInit.NVIC_IRQChannelPreemptionPriority=0; aNVICInit.NVIC_IRQChannelSubPriority=3; aNVICInit.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&aNVICInit);}void InitGPIO(void){ GPIO_InitTypeDef aGPIORec; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD , ENABLE); aGPIORec.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; aGPIORec.GPIO_Speed = GPIO_Speed_50MHz; aGPIORec.GPIO_Mode = GPIO_Mode_OUT; aGPIORec.GPIO_OType = GPIO_OType_PP; aGPIORec.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &aGPIORec); }void EXTI15_10_IRQHandler(void){ if (EXTI_GetITStatus(EXTI_Line13)!=RESET){ if (myFlag==0) { ActiveLed(0x0F); myFlag=1; Delay(50); } else { myFlag=0; ActiveLed(0); Delay(50); } EXTI_ClearITPendingBit(EXTI_Line13); } }int fputc(int c,FILE *f){ USART_SendData(USART1,c); while (USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET){} return 1;}void USART1_IRQHandler(void){ if (USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET){ Res=USART_ReceiveData(USART1); }}void ActiveLed(char Led_Id){ if (Led_Id & 1) GPIO_SetBits(GPIOD, GPIO_Pin_12); else GPIO_ResetBits(GPIOD, GPIO_Pin_12); if (Led_Id & 2) GPIO_SetBits(GPIOD, GPIO_Pin_13); else GPIO_ResetBits(GPIOD, GPIO_Pin_13); if (Led_Id & 4) GPIO_SetBits(GPIOD, GPIO_Pin_14); else GPIO_ResetBits(GPIOD, GPIO_Pin_14); if (Led_Id & 8) GPIO_SetBits(GPIOD, GPIO_Pin_15); else GPIO_ResetBits(GPIOD, GPIO_Pin_15);}/************************END OF FILE****************************/2014-01-06 02:58 AM
You get to have ONE pin per EXTI Line
ie PA11 Exti Line 11 PC12 Exti Line 12 PD13 Exti Line 132014-01-06 07:58 PM
Great! it works after disabling EXTILineA13_Config function!
Thanks a lot Clive1!