2015-05-27 04:51 PM
Hi all!
I used CubeMX to generate a simple project where there are 3 buttons and 3 leds are connected to my STMF103RBT6. I want to use interrupt, but the code generated by CubeMX is not clearing up any interrupts. Here is the original generated code:void
EXTI15_10_IRQHandler(
void
)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12));
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13));
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14));
/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
/* USER CODE END EXTI15_10_IRQn 1 */
}
So I want to do is turn each corresponding LED whenever a button is pressed. Using the code above, only the button on GPIO_PIN_14 works, no matter what, 23 and 13 does not work:
void
EXTI15_10_IRQHandler(
void
)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
if
(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_12) != RESET)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12));
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_12);
return
;
}
if
(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13) != RESET)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13));
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_13);
return
;
}
if
(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_14) != RESET)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14));
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_14);
return
;
}
/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
/* USER CODE END EXTI15_10_IRQn 1 */
}
I tried to lend code from a NOT CubeMX library, but it does not work. What I am endded up with is something like this, but it still does not work! I would be happy if you can point out what am I doing wrong. (I have tested all buttons and leds without using interrupts and they are fine! so I guess the problem is in the IRQHandler).
#hal #stm32 #flash #exti15_10_irqhandler-stm32
2015-05-27 09:06 PM
Hi, Try this sample.
---void EXTI15_10_IRQHandler(void)
{ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12); HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13); HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14); }void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{ if (GPIO_Pin == GPIO_PIN_12) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12)); } else if (GPIO_Pin == GPIO_PIN_13) { ... } ... }2015-05-28 10:41 AM
Thanks! that seems to work.
But is there a way to find out which GPIO Port has rised that function?HAL_GPIO_EXTI_Callback does not have any argument to check against the port as far as I saw.
2015-05-29 01:19 AM
That is complicate. Only 1 GPIOx.Pn is selected for EXTIn.
--- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; // contains EXTI_MODE // if the mode contains EXTI_MODE, HAL_GPIO_Init() set AFIO_EXTICRn // so only 1 line (GPIOA,B,...) is selected for EXTIn HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);2015-06-10 01:13 PM
So is it pointless to check for the pins which raised this event? I mean in the
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
if foe example I want to do 2 different thing with 2 different buttons I have to put these button on separate intterupt groups? e.g. first one in EXTI15_10 and second button in EXTI9_5 ??
2015-06-10 05:54 PM
void EXTI9_5_IRQHandler(void)
{ // GPIO_PIN_5 ~ GPI_PIN9 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5); } void EXTI15_10_IRQHandler(void) { // GPIO_PIN_10 ~ GPI_PIN15 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10); } void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == GPIO_PIN_5) { // something } else if (GPIO_Pin == GPIO_PIN_10) { // something } }