cancel
Showing results for 
Search instead for 
Did you mean: 

How to use "TIM2_CH1" Timer interrupt to make toggle LED at PA0 every 1sec

kdong.6
Associate

How to use "TIM2_CH1" Timer interrupt to make toggle LED at PA0 every 1sec 

-I verify PA0 LED is good work(test with "HAL_GPIO_Toogglepin()")

-contains cubeMX project files, Truestudio projets

-my addtional user code down below

-cubeMX select option is also captured

==============usercode==============

 /* USER CODE BEGIN 2 */

 HAL_TIM_Base_Start_IT(&htim2);

 /* USER CODE END 2 */

 /* USER CODE BEGIN 3 */

 HAL_Delay(1000);

 }

 /* USER CODE END 3 */

/* USER CODE BEGIN 4 */

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

   HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);

 HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_1);

 HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_2);

}

/* USER CODE END 4 */

==============usercode==============

0690X000006C7NJQA0.png0690X000006C7NOQA0.png

0690X000006C7NTQA0.png

3 REPLIES 3

Any other plans for TIM2?

Realistically time span stuff you'd use the Update interrupt and set the prescaler and period to divide down the source clock. Looks like you have an STM32F1 running at 64 MHz

So either prescaler=64000-1, period = 1000-1, or the other way round

For a 72 MHz clock, prescaler=36000-1, period=2000-1

Sorry not touching CubeMX stuff.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

As PA0 connects to TIM2_CH1_ETR one presumably could do this entirely without interrupts, and program CH1 into output compare toggle mode, and let the TIM flip the pin automatically.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Read out and check the relevant TIM registers, including whether interrupt is enabled in DIER. Check, whether interrupt is enabled in NVIC and in disassembly check whether the respective interrupt service handler (ISR) address is present in the proper place in interrupt table.

I don't Cube/CubeMX.

JW