Skip to main content
KHuyn
Associate III
Feb 13, 2020 3:46 AM UTC
Solved

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

This topic has been closed for replies.
berendi
berendiBest answer
Principal
Feb 13, 2020 11:17 AM UTC

Set the EXTI source in SYSCFG->EXTICR[].

At reset, all EXTI sources are mapped to GPIOA, so EXTI13 is triggered by edges on PA13. Which happens to be the SWDIO pin, so it is triggered every time the debugger probe makes some request. (disable the onboard debugger, it should stop blinking)

4 replies

berendi
berendiBest answer
Principal
Feb 13, 2020 11:17 AM UTC

Set the EXTI source in SYSCFG->EXTICR[].

At reset, all EXTI sources are mapped to GPIOA, so EXTI13 is triggered by edges on PA13. Which happens to be the SWDIO pin, so it is triggered every time the debugger probe makes some request. (disable the onboard debugger, it should stop blinking)

KHuyn
KHuynAuthor
Associate III
Feb 13, 2020 11:08 PM UTC

That's what I need. Thank you!

** remember to enable SYSCFG register in RCC**

Vmere.1
Associate III
Jun 18, 2022 8:37 AM UTC

This saved me a lot of time. Thank you