cancel
Showing results for 
Search instead for 
Did you mean: 

External interrupts on PC14 and PC15 of STM32F103C8T6.

Antony1
Associate II

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);
}

1 ACCEPTED SOLUTION

Accepted Solutions

Is this a genuine ST part?

Are all VDD/VSS pins (including the analog ones) properly connected (as measured directly on the pins)?

Try simplifying the code to bare minimum, use a single pin. Still problems?

Read out the EXTI registers at the end of ISR and check if the interrupt flag is cleared.

JW

View solution in original post

4 REPLIES 4

Is this a genuine ST part?

Are all VDD/VSS pins (including the analog ones) properly connected (as measured directly on the pins)?

Try simplifying the code to bare minimum, use a single pin. Still problems?

Read out the EXTI registers at the end of ISR and check if the interrupt flag is cleared.

JW

MM..1
Chief III

try not or all EXTI in one line

EXTI_InitTypeDef myEXTI_InitStructure;
	myEXTI_InitStructure.EXTI_Line = EXTI_Line13;
	myEXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	myEXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	myEXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&myEXTI_InitStructure);
 
	myEXTI_InitStructure.EXTI_Line = EXTI_Line14;
	EXTI_Init(&myEXTI_InitStructure);
 
	myEXTI_InitStructure.EXTI_Line = EXTI_Line15;
	EXTI_Init(&myEXTI_InitStructure);

Thanks for reply, Jan.

The problem is solved - there was no problame at all, like always it was "human error". It's just I made a mistake in my debugger code, that showed not existing problem. So, EXTI_IRQ was never fire more then once on each pulse and corresponding pending bits in EXTI_PR register were cleared as expected. Initialization code above is correct. There it is. Sorry and thanks for your time spent on this

But I'll answer your qyestiones, maybe it will solve someones real problame, similar to this.

1. The part is genuine, it was my first thought. Well, to be clear, I've used about hundred of this IC's in last couple years from same supplier. The marking looks real, all peripheral works as it shoud, and I use ADC, DAC, DMA, PWM, SPI, UART, Timers and other. So, it is not a "Blue Pill" with some "CS32F103", "GD32F103" or "STM32FEBKC6".

2. All VDD/AVDD/VSS connected properly, soldering made by me. The board I'm working right now are electricaly cheked - there is no broken conductors on the board.

3. Obviosly second thougt (and what I did) is simplifying initializatione code above to write into registers like GPIOC_BSRR, RCC_APB2ENR, AFIO_EXTICR4, EXTI_IMR, EXTI_PR, etc without any unnecessary callings.

4. Interrupt flags are cleared in IRQ handler correctly.

Thanks for reply, MM..1.

There were no mistakes in init code, it was an error in my debugger code. IRQ was never fire more then once on each pulse. Initialization code above is correct. Thanks for your time.