External interrupts on PC14 and PC15 of STM32F103C8T6.
Hello, guys.
I need to improve one old project. There is no free pins on MCU left, except PC13-PC15 and I need three external interrupts. Code with initialization for making PC13-PC15 as inputs lower. I do not use LSE or RTC anyway.
For PC13 all works fine, interrupt works as desired. In IRQ routine flags are cleared as expected. But after first change of pin state for PC14 or PC15 interrupt keeps fire, as if corresponding pending bits are not cleared in IRQ handler.
In project I used StdPeriphLib v.3.5.0. I checked, there is no mistakes on low level acces to registers in functiones and definings of corresponding setting bits. Also there is no external noise on PC14 and PC15. To be sure about this, I've tryde different external "strong pullups", also oscilloscope shows no noises on this pins. VBAT pin externally connected to VDD with a 100nF capacitor, as said in reference manual. Also external impulses are coming with clear fronts, there are no parasitic capacitance or connections on the board.
So, it is not an external hardware issue. In some how the code is wrong. Any ideas and suggestiones will be helpfull. Thanks.
void ABCInputsInit(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
//PWR_BackupAccessCmd(ENABLE);
//RCC_LSEConfig(RCC_LSE_OFF);
//BKP_TamperPinCmd(DISABLE);
//PWR_BackupAccessCmd(DISABLE);
GPIO_InitTypeDef myGPIO_InitStructure;
myGPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
myGPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
myGPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &myGPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource14);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource15);
EXTI_InitTypeDef myEXTI_InitStructure;
myEXTI_InitStructure.EXTI_Line = EXTI_Line13|EXTI_Line14|EXTI_Line15;
myEXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
myEXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
myEXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&myEXTI_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitTypeDef myNVIC_InitStructure;
myNVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
myNVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0A;
myNVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0A;
myNVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&myNVIC_InitStructure);
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
//EXTI_ClearFlag(EXTI_Line13);
EXTI_ClearITPendingBit(EXTI_Line13);
APhase = SET;
}
if(EXTI_GetITStatus(EXTI_Line14) != RESET)
{
//EXTI_ClearFlag(EXTI_Line14);
EXTI_ClearITPendingBit(EXTI_Line14);
BPhase = SET;
}
if(EXTI_GetITStatus(EXTI_Line15) != RESET)
{
//EXTI_ClearFlag(EXTI_Line15);
EXTI_ClearITPendingBit(EXTI_Line15);
CPhase = SET;
}
//NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
}