I am trying to use a rotary encoder and button with an STM32F103 and FreeRTOS. The external interrupts for a pin0 and pin1 work fine but the button is connected to a Pin13 (EXTI15_10_IRQHandler) which keeps triggering without cause. Of course, I could just use a pin2 (EXTI2_IRQHandler) to 4 or poll the button pin without interrupt but I would like to know the cause of this. What am I missing here?
// button
#define ROEN_BUTTON_GPIO GPIOC
#define ROEN_BUTTON_PIN GPIO_Pin_13
// init method
NVIC_InitTypeDef NVIC_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
/**
* GPIO configuration
* Configure pins as input w/ pullup
*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = ROEN_BUTTON_PIN; // Button
GPIO_Init(ROEN_BUTTON_GPIO, &GPIO_InitStructure);
/* Tell system that you will use PC13 for EXTI_Line13 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, EXTI_Line13);
/* Enable interrupt */
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
/* Interrupt mode */
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
/* Triggers on rising and falling edge */
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
/* PC13 is connected to EXTI_Line13 */
EXTI_InitStruct.EXTI_Line = EXTI_Line13;
EXTI_Init(&EXTI_InitStruct);
/* Enable interrupt */
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
/* Set priority */
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x03;
/* Add to NVIC */
NVIC_Init(&NVIC_InitStruct);
/* Handle PC13 interrupt */
void EXTI15_10_IRQHandler(void) {
/* Make sure that interrupt flag is set */
if (EXTI_GetITStatus(EXTI_Line13) != RESET) {
/* Clear interrupt flag */
EXTI_ClearITPendingBit(EXTI_Line13);
}
}