Skip to main content
M_J
Associate II
Jun 30, 2023 7:35 AM UTC
Question

Stm32

How to use timer interrupt in GPIO interrupt

    This topic has been closed for replies.

    8 replies

    MM..1
    Super User
    Jun 30, 2023 7:43 AM UTC

    Priority?

    M_J
    M_JAuthor
    Associate II
    Jun 30, 2023 8:45 AM UTC

    Timer 

    AScha.3
    Super User
    Jun 30, 2023 10:15 AM UTC

    Why ?

    If you feel a post has answered your question, please click on " Best Answer ".
    MM..1
    Super User
    Jun 30, 2023 11:23 AM UTC

    primary your personal sended code nobody see then nobody help.

    volatile uint8_t count = 0;
    			HAL_GPIO_TogglePin(GPIOB, Red_Led_Pin);
    			HAL_Delay(100);

    For ISR variables need volatile. Your count++ and if else is litle complicated. 

    And your code isnt timer interrupt in GPIO. You only start timer with IT method aplied...

    HAL_TIM_Base_Start_IT(&htim3);

    And use Delay in callback is mistake if systick isnt higher priority code hang here

     

    M_J
    M_JAuthor
    Associate II
    Jun 30, 2023 12:21 PM UTC
    /**
     * @brief GPIO Initialization Function
     * @param None
     * @retval None
     */
    static void MX_GPIO_Init(void)
    {
     GPIO_InitTypeDef GPIO_InitStruct = {0};
    /* USER CODE BEGIN MX_GPIO_Init_1 */
    /* USER CODE END MX_GPIO_Init_1 */
    
     /* GPIO Ports Clock Enable */
     __HAL_RCC_GPIOC_CLK_ENABLE();
     __HAL_RCC_GPIOH_CLK_ENABLE();
     __HAL_RCC_GPIOB_CLK_ENABLE();
    
     /*Configure GPIO pin Output Level */
     HAL_GPIO_WritePin(GPIOB, Green_Led_Pin|Red_Led_Pin, GPIO_PIN_RESET);
    
     /*Configure GPIO pin : Push_Button_Pin */
     GPIO_InitStruct.Pin = Push_Button_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(Push_Button_GPIO_Port, &GPIO_InitStruct);
    
     /*Configure GPIO pins : Green_Led_Pin Red_Led_Pin */
     GPIO_InitStruct.Pin = Green_Led_Pin|Red_Led_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    
     /* EXTI interrupt init*/
     HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
     HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
    
    /* USER CODE BEGIN MX_GPIO_Init_2 */
    /* USER CODE END MX_GPIO_Init_2 */
    }
    
    /* USER CODE BEGIN 4 */
    
    /* USER CODE END 4 */
    
    /**
     * @brief This function is executed in case of error occurrence.
     * @retval None
     */
    void Error_Handler(void)
    {
     /* USER CODE BEGIN Error_Handler_Debug */
     /* User can add his own implementation to report the HAL error return state */
     __disable_irq();
     while (1)
     {
     }
     /* USER CODE END Error_Handler_Debug */
    }
    
    #ifdef USE_FULL_ASSERT
    /**
     * @brief Reports the name of the source file and the source line number
     * where the assert_param error has occurred.
     * @param file: pointer to the source file name
     * @param line: assert_param error line source number
     * @retval None
     */
    void assert_failed(uint8_t *file, uint32_t line)
    {
     /* USER CODE BEGIN 6 */
     /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
     /* USER CODE END 6 */
    }
    #endif /* USE_FULL_ASSERT */
    M_J
    M_JAuthor
    Associate II
    Jun 30, 2023 12:27 PM UTC

    If I press the user button for 2 sec.  Then red led will tern on .... Again I press button then red led will tern off.....If I continue press the button led will be tern off........ 

    I did some changes but my problem is not solved ...

     

    LCE
    Principal III
    Jun 30, 2023 1:07 PM UTC

    Dude, tell the people what you want to achieve.

    Even your starting post "How to use timer interrupt in GPIO interrupt" is ridiculous, we have no time for guessing.

    M_J
    M_JAuthor
    Associate II
    Jun 30, 2023 1:41 PM UTC

    Extremely  Sorry ... next time definitely I will try