EXTI15_10_IRQn triggered constantly - STM32L4R5ZI
Hi, I am trying to write an interrupt code to trigger LED(PB14) using user button on my NUCLEO board(PC13). however, as I observed from the debugger, pending bit for line 13 constantly at 1 without pushing the button at all.
The EXTI->PR1 = 1<<13 still executed but it can't clear the pending bit.
Could someone point out my problem? here is my code.
Thank you.
/*--Header--------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdint.h>
#include "stm32l4r5xx.h"
/*--Define--------------------------------------------------------------------------------*/
/*--Global-Variable---------------------------------------------------------------------- */
/*--Function Prototypes-------------------------------------------------------------------*/
void initPort (void);
void Blink(void);
/*--Main----------------------------------------------------------------------------------*/
int main()
{
initPort();
while(1)
{
}
} // EO Main
/*--Function------------------------------------------------------------------------------*/
/************************************************/
/* Name: initPort */
/*-Initiating PC13 as input/interrupt */
/*-Initiating PB14 as LED red */
/* */
/************************************************/
void initPort(void)
{
RCC->AHB2ENR |= 0x04;// Enable GPIO port D
GPIOC->MODER &= ~(1<<26);
GPIOC->MODER &= ~(1<<27); // Enable PC13 as input - Button
EXTI->RTSR1 |= 0x1<<13; // Enable EXTI15-PD13 triggers in raising edge
EXTI->IMR1 |= 0x1<<13; // Un-mask EXTI15 to enable the interrupt in PD13
NVIC->ISER[1] |= 1<<8; //Enable EXTI15_10 - vector position 40
RCC->AHB2ENR |= 1<<1; //Enable GPIO port B
GPIOB->MODER &= ~(1<<29);
GPIOB->MODER |= 1<<28; //Set PD14 as general output LED3
}
void Blink(void)
{
GPIOB->ODR ^= 1<<14; // toggle pin PB14 - LED3
for(int i=0; i<10000; i++);
}
void EXTI15_10_IRQHandler (void)
{
if (EXTI->PR1 & 1<<13) // check if the pending register is on
{
EXTI->PR1 = 1<<13; // clear the pending register by writing 1 to it
}
Blink();
}