Pending Register for EXTI line 13 always active
Im trying some bare Metal programming on the NUCLEO - H743ZI2.
Im stuck on creating a Button Interrupt on EXTI line 13.
The User Button 1 is located on PC13, im trying to toggle LED2 on PE1.
LED and Button configuration must be correct, since it works with polling. I think im missing something in the Register configuration for the EXTI, but i cant find the problem. I found no "bare metal" examples for the board im using.
The PR1 register is always at 0x2000 after configuration(bit 13 is set to 1), but only if i activate any of the trigger edge settings. I commented out the RCC and SYSCFG lines in the setup_ISR function and it didnt change the behaviour, so i think im missing something in@ these lines to correctly setup the EXTI. I have tried to find a solution without any succes.
#include <main.h>
volatile unsigned char led_on = 1;
uint32_t interrupt = 0;
void setup_usrled_2(void)
{
//LED_PIN = PE1
// peripheral clock enable
RCC -> AHB4ENR |= RCC_AHB4ENR_GPIOEEN;
// 00 overwrite
GPIOE -> MODER &= ~(0b11 << (LED_PIN*2));
// 01 output
GPIOE -> MODER |= (0b01 << (LED_PIN*2));
// 0 Open Drain
GPIOE -> OTYPER &= ~(0b1 << LED_PIN);
GPIOE -> PUPDR &= ~(0b11 << LED_PIN*2);
}
void setup_usrbttn_1(void)
{
//BUTTON_PIN = PC13
// peripheral clock enable
RCC -> AHB4ENR |= RCC_AHB4ENR_GPIOCEN;
// 00overwrite == input mode
GPIOC -> MODER &= ~(0b11 << (BUTTON_PIN*2));
// 00 overwrite
GPIOC -> PUPDR &= ~(0b11 << (BUTTON_PIN*2));
// 10 Pull Down, since USER_B1 is connected to VDD (inactive high)
GPIOC -> PUPDR |= (0b10 << (BUTTON_PIN*2));
}
void setup_bttn1_ISR(void)
{
//BUTTON_PIN = PC13
// peripheral clock enable
RCC -> APB4ENR |= RCC_APB4ENR_SYSCFGEN;
// reset EXTI line 13
SYSCFG -> EXTICR[0] &= ~(SYSCFG_EXTICR4_EXTI13_Msk);
// activate EXTI line 13 for GPIO Port C (PC13)
SYSCFG -> EXTICR[0] |= (SYSCFG_EXTICR4_EXTI13_PC);
// unmask Interrupt for line/interrupt 13
EXTI -> IMR1 |= (0x01 << EXTI_IMR1_IM13_Pos);
// deactivate rising trigger (do not react on release of btn)
EXTI -> RTSR1 &= ~(0x01 << EXTI_RTSR1_TR13_Pos);
// activate falling trigger (react on press of button)
EXTI -> FTSR1 |= (0x01 << EXTI_FTSR1_TR13_Pos);
//activate NVIC
NVIC_SetPriority(EXTI15_10_IRQn, 0x03);
NVIC_EnableIRQ(EXTI15_10_IRQn);
}
void EXTI15_10_IRQHandler(void)
{
if (EXTI->PR1 & (1 << BUTTON_PIN))
{
// clear EXTI status flag
EXTI->PR1 |= (1 << BUTTON_PIN);
led_on = !led_on;
}
NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
}
int main(void)
{
setup_usrbttn_1();
setup_usrled_2();
setup_bttn1_ISR();
interrupt = EXTI->PR1;
while (1)
{
if (led_on)
{
GPIOE->ODR |= (1 << LED_PIN);
}
else
{
GPIOE->ODR &= ~(1 << LED_PIN);
}
}
}