EXTI PI2 not working on STM327508-DK
I have viewed every example on the internet, I think and seen many different commands and approaches. As long as the interrupt is disabled, the program works, but it crashes when enabled. Here are snippets related to EXTI. Maybe I have mixed code from too many sources and something conflicts.
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
__HAL_RCC_GPIOI_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
// GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI2_IRQn, 2, 3);
NVIC_EnableIRQ(EXTI2_IRQn);
EXTI->IMR |= 1<<2;
EXTI->RTSR |= 1<<2; // Enable the 'rising edge' trigger (button release)
SYSCFG->EXTICR[0] = 0x800; // EXTICR[0] is EXTICR1. Line2 is 3rd set of 4 bits, PortI is 8th port starting with A
void EXTI2_IRQHandler(void)
{
if (EXTI->PR & (1<<2))
{
EXTI->PR |= (1<<2); // Clear the EXTI status flag
// NVIC_ClearPendingIRQ(EXTI2_IRQn); // Clear previous interrupt in NVIC
HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_1); // Toggle PI1
}
}
.
