Skip to main content
PPULA.1
Associate
January 20, 2021
Solved

I am using stm32l011K4U3 microcontroller on a custom made pcb. I am trying to use EXTI on PC14 pin (which is also oscillator input pin). The interrupt is triggering continuously even though there is no raising or falling edge on the pin.

  • January 20, 2021
  • 4 replies
  • 1223 views

I am unable to clear the EXTI pending register it always stays high and probably that is what is causing interrupt to trigger again and again. I am attaching snippets of code .Please Help me figure out the issue .

#include "stm32l0xx.h" // Device header
#include "RTE_Components.h" // Component selection
 
volatile int HPA,HPB,HPC,interrupt,interrupt1;
 
void clock_init(void);
void gpio_init(void);
void exti_interrupt_init(void);
 
 
int main(void){
	clock_init();
	gpio_init();
 exti_interrupt_init();
	__enable_irq();
 
	while(1){
	//NOTHING TO DO
	}
 
}
 
void clock_init(void){
 
	RCC->APB1ENR|=RCC_APB1ENR_PWREN; //PWR clock enable
	PWR->CR=0x800;										//set vcore to 1.8V	
	
	while((PWR->CSR & PWR_CSR_VOSF));		// wait till core voltage is setelled
	
	RCC->CR &=~(1<<RCC_CR_PLLON_Pos);	//disable pll
	
	RCC->CSR&=~(1<<RCC_CSR_LSEON_Pos);	//TURN OFF LSE
	RCC->CR&=~(1<<RCC_CR_HSEON_Pos);		//TURN OFF HSE
	
	RCC->CR |= 1<<RCC_CR_HSION_Pos;			//enable internal HSI16 MHz oscillator
	RCC->CFGR|=RCC_CFGR_PLLDIV2 | RCC_CFGR_SW_PLL | RCC_CFGR_PLLMUL4;//select pll as system clock, pllvco=hsi*6=16*6=96Mhz, core freq=pllvc0/plldiv=96Mhz/3=32Mhz
	
	RCC->CR|=RCC_CR_PLLON;	//enable pll
	while(!(RCC->CR & RCC_CR_PLLRDY));		// wait till pll is on
	
	//RCC->APB1ENR|=RCC_APB1ENR_TIM2EN | RCC_APB1ENR_I2C1EN |RCC_APB1ENR_LPTIM1EN |RCC_APB1ENR_USART2EN ;	//ENABLE clock for timer 2,i2c1
	RCC->APB2ENR=RCC_APB2ENR_SYSCFGEN;	//ENABLE clock for SYSCFGEN
	}
	
	
	void gpio_init(void){
 
	RCC->IOPENR |= 0b111; //clk for portA,B,C
	
	
	/*hall sensor pins*/
 
	GPIOC->MODER &=~((0b11)<<28);	//PC14(HPC) AS INPUT	
	
 
	
}
 
void exti_interrupt_init(void){
 
	SYSCFG->EXTICR[3]|=SYSCFG_EXTICR1_EXTI3_PC;
	EXTI->IMR|=1<<EXTI_IMR_IM14_Pos;	//INTERRUPT UNMASK ON 14
	EXTI->RTSR|=1<<EXTI_RTSR_RT14_Pos;	//ENABLE RISING INTERRUPT
	EXTI->FTSR|=1<<EXTI_FTSR_FT14_Pos;//ENABLE FALLING INTERRUPT
	NVIC_EnableIRQ(EXTI4_15_IRQn);	//ENABLE IRQ4-15
 
 
}
 
 
 
 
void EXTI4_15_IRQHandler(void){
	interrupt++;	//	KEEP TRACK OF NUMBER OF INTERRUPTS
	if (EXTI->PR & (1<<14)) { // CLEAR PENDING INTERRUPT !!!!!!!! HERE IS THE ISSURE IT NEVER GETS CLEARED 
 EXTI->PR = (1<<14);
	}
	HPC=(GPIOC->IDR & 0x8000);	//PC15
	HPB=(GPIOA->IDR & 0x0001);	//PA0
	HPA=(GPIOC->IDR & 0x4000);	//PC14
}
 
 

This topic has been closed for replies.
Best answer by waclawek.jan

Try to read out all the relevant registers' content (GPIOC, EXTI, SYSCFG), to check whether they are set as you expect them.

> SYSCFG->EXTICR[3]|=SYSCFG_EXTICR1_EXTI3_PC;

Are you sure?

JW

4 replies

waclawek.jan
waclawek.janBest answer
Super User
January 20, 2021

Try to read out all the relevant registers' content (GPIOC, EXTI, SYSCFG), to check whether they are set as you expect them.

> SYSCFG->EXTICR[3]|=SYSCFG_EXTICR1_EXTI3_PC;

Are you sure?

JW

PPULA.1
PPULA.1Author
Associate
January 21, 2021

Thank you for the reply . SYSCFG->EXTICR[3]|=SYSCFG_EXTICR1_EXTI3_PC; is to select the source input for the EXTIx external interrupt which in my case is PORTC . I checked this in the register window too .

I have checked the register contents and they seem to change as I expect . Only issue is the PC14 EXTI pending register which is always set high even though I am trying to clear it in the interrupt as soon as I enter it .

I have tried a different pin ,namely PC15 as external interrupt and I see that it is triggering as expected . PC14,PC15 both have same interrupt handler EXTI4_15_IRQHandler.

I was thinking may be this has got something to do with the nature of the pin PC14 which is a clock input for the mcu and I am probably missing setting to do . Any help would be great . Thank you

waclawek.jan
Super User
January 21, 2021

SYSCFG->EXTICR[3]|=SYSCFG_EXTICR1_EXTI3_PC; 

On which address is this register, and what is its value?

JW

PPULA.1
PPULA.1Author
Associate
January 21, 2021

Thanks a lot . My understanding of SYSCFG_EXTICR1_EXTI3_PC was wrong . It was not enabling exti for PC14 . Thank you very much