2021-01-20 01:30 AM
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
}
Solved! Go to Solution.
2021-01-20 03:59 AM
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
2021-01-20 03:59 AM
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
2021-01-20 10:18 PM
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
2021-01-20 11:52 PM
SYSCFG->EXTICR[3]|=SYSCFG_EXTICR1_EXTI3_PC;
On which address is this register, and what is its value?
JW
2021-01-21 01:08 AM
Thanks a lot . My understanding of SYSCFG_EXTICR1_EXTI3_PC was wrong . It was not enabling exti for PC14 . Thank you very much