AnsweredAssumed Answered

Stm32 Hal , ISR on TRGO not working

Question asked by Ferraro.Leonardo on Apr 21, 2016
Latest reply on Apr 25, 2016 by Nesrine M

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 ?

Outcomes