I'm using an STM32F103C8T6 (aka blue pill).
GPIO Init and interrupt handler:
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);
/*Configure GPIO pins : PC13 PC15 */
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
while(1);
}
void EXTI0_IRQHandler(void)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_14);
}
The problem is that the interrupt handler (EXTI0_IRQHandler) is never called. I tried also with other pins (e.g. using EXTI15_10_IRQHandler). I checked the switch and LED separately (in the main function) and those work. I also tried with PULLUP and PULLDOWN (which makes no difference).
Is there more needed to trigger the interrupt function?
1 Answer 1
Do the steps from my comment, Here is the sample code. I had a different hardware connections so I used a different pins.
int main(void) {
RCC->APB2ENR = RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN;
//confure PB2 PC13 as inputs, PB0 output
AFIO->EXTICR[0] = AFIO_EXTICR1_EXTI2_PB;
AFIO->EXTICR[3] = AFIO_EXTICR4_EXTI13_PC;
EXTI->IMR = EXTI_IMR_MR2 | EXTI_IMR_MR13;
EXTI->RTSR = EXTI_RTSR_TR2;
EXTI->FTSR = EXTI_FTSR_TR13;
NVIC_EnableIRQ(EXTI2_IRQn);
NVIC_EnableIRQ(EXTI15_10_IRQn);
while (1);
}
void EXTI2_IRQHandler(void) {
if (EXTI->PR & EXTI_PR_PR2) {
EXTI->PR = EXTI_PR_PR2;
GPIOB -> ODR |= GPIO_ODR_0;
}
}
void EXTI15_10_IRQHandler(void) {
if (EXTI->PR & EXTI_PR_PR13) {
EXTI->PR = EXTI_PR_PR13;
GPIOB -> ODR &= ~GPIO_ODR_0;
}
}
one pin turns led on another turns off
-
\$\begingroup\$ Thanks for this comment, I use HAL so I first need to find out what all those numbers mean (good exercise for me). Btw, is there a reason you use PC13 as input since for my board PC13 is connected to an output (builtin LED)? \$\endgroup\$Michel Keijzers– Michel Keijzers2017年08月22日 08:57:20 +00:00Commented Aug 22, 2017 at 8:57
-
1\$\begingroup\$ I havw only one board with 103 as it is an obsolete family of micros. And on this board I have different connections than the "bluepil". Just change to the one you have. I just wanted to give you the working example - so I have tested it on my actual hardware \$\endgroup\$0___________– 0___________2017年08月22日 09:55:17 +00:00Commented Aug 22, 2017 at 9:55
-
\$\begingroup\$ When I came home it suddenly worked (only change: I took the breadboard including stm32 by car) ... so maybe it was some electronic problem (loose wire). But I will study your example to see the difference between Hal and 'direct calls'. \$\endgroup\$Michel Keijzers– Michel Keijzers2017年08月22日 19:55:14 +00:00Commented Aug 22, 2017 at 19:55
-
\$\begingroup\$ I honestly advise the bare registers way. \$\endgroup\$0___________– 0___________2017年08月22日 19:57:11 +00:00Commented Aug 22, 2017 at 19:57
-
1\$\begingroup\$ No SPL is dead and unsupported for years. Just include CMSIS headers, download the Reference Manual and enjoy :) \$\endgroup\$0___________– 0___________2017年08月22日 20:30:59 +00:00Commented Aug 22, 2017 at 20:30
Explore related questions
See similar questions with these tags.
EXTI0_IRQn
a constant or should it be something likeEXTI0_IRQ0
? \$\endgroup\$