2023-02-22 01:44 PM
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == GPIO_PIN_10)
{
Switch10 = 1;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
}
if(GPIO_PIN == GPIO_PIN_11)
{
Swtich10 = 0;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);
}
}
int main (void)
{
while(1)
{
if(Switch10)
{
Test();
}
}
}
2023-02-22 01:55 PM
The code as presented is incomplete, and unhelpful for diagnostics
You're turning it off with a different pin.
Show pin and exti initialization code.
Show IRQHandler code.
2023-02-22 02:22 PM
Yes, I forget to mention I have second switch to turn off the same LED.
void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
}
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
2023-02-23 12:56 PM
Yes, I forget to mention I have second switch to turn off the same LED.
void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
}
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
I have initialized static int Switch10. And found out that in real time debugging the static int Switch10 increment as counter it does not stay as static.I think, thats why it does not alllow for second time press to turn on the LED. Any comment about this?. Thank you
2023-02-23 02:05 PM
There is probably something happening in the background that you're not showing us in code. We don't know what you're doing in Test function? You've have a spelling mistake in the the HAL_GPIO_EXTI_Callback so that means you're not copying/pasting the code as is.
2023-02-23 08:19 PM
A push button has decounce to counteract by HW or SW.
Want sometime rugged? Activate the EXTI interrupt after clearing the PR bits from main loop (if bare metal obviously) and make the callback self interrupt disable it. Ping pong it with some delay to pass the debounce period. It has the other benefit not to put the operating application to a grinding halt with a DDOS style attack by injecting MHz square wave to the EXTI interrupt pin.
Example code here for STM32C0316 (IRQ_SelfSettle.c)