cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32 Hal , ISR on TRGO not working

leonardo23
Associate
Posted on April 21, 2016 at 18:03

Hi all

I’m trying to synchronize 2 general pourpose timers ( TIM3 and TIM4 ) on stm32f401re , and firing an interrupt on every trigger signal ( which will toggle LD2 led ) , but nothing happen :

TIM3 should fire a TRGO signal on every counter overflow ( about 1Hz ) , and clock TIM4 through ITR2.

An interrupt should be fired on TRGO

Timers configuration is the following :

void
MX_TIM3_Init(
void
)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
htim3.Instance = TIM3;
htim3.Init.Prescaler = 1200;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 65535;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim3);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
}
/* TIM4 init function */
void
MX_TIM4_Init(
void
)
{
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_MasterConfigTypeDef sMasterConfig;
htim4.Instance = TIM4;
htim4.Init.Prescaler = 0;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 10;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim4);
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1;
sSlaveConfig.InputTrigger = TIM_TS_ITR2;
HAL_TIM_SlaveConfigSynchronization_IT(&htim4, &sSlaveConfig);
}

and the isr callback is the following

void
HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim){
if
(htim->Instance==TIM4){
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
}
}

other parts of the code are automatically generated with stm32cubemx ( system init and TIM4_IRQHandler )

do you know why it doesn’t work ?

1 REPLY 1
Nesrine M_O
Lead II
Posted on April 25, 2016 at 15:00

Hi ferraro.leonardo,

I recommend you to have a look to the timer example under the STM32F4 cube firmware package, it may be helpful: 

STM32Cube_FW_F4_V1.11.0\Projects\STM324xG_EVAL\Examples\TIM\TIM_ParallelSynchro

This example shows how to synchronize TIM2 and Timers (TIM3 and TIM4) in parallel mode.

-Syrine-