AnsweredAssumed Answered

problem with SlaveMode and interrupt

Question asked by Munich85 on Feb 6, 2014
Latest reply on Feb 6, 2014 by waclawek.jan

Hi,

I need help with my Stm32F407. In this example I want to clock Tim4 with Tim2 using the slave mode. This is working fine! But when I want to use Tim4 to rise an update-interrupt this line stops the MCU. Somewhere in the 2000 pages of the reference manual must be a hint why this happens but I cannot find it! 

void TIM_Test()
{
      TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
 
      NVIC_InitTypeDef nvicStructure;
      nvicStructure.NVIC_IRQChannel = TIM4_IRQn;
      nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
      nvicStructure.NVIC_IRQChannelSubPriority = 1;
      nvicStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&nvicStructure);
 
      /* ---------------------------------------------------------------
      TIM2 Configuration:
      --------------------------------------------------------------- */
     TIM_DeInit( TIM2 );
     /* Time base configuration */
     TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
     TIM_TimeBaseStructure.TIM_Period =42000000;
     TIM_TimeBaseStructure.TIM_Prescaler = 0;
     TIM_TimeBaseStructure.TIM_ClockDivision = 0;
     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
     TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
     // TIM2 als master für TIM4 über ITR1
     TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
     TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
 
     TIM_ARRPreloadConfig(TIM2, ENABLE);
 
      /* ---------------------------------------------------------------
      TIM4 Configuration:
     --------------------------------------------------------------- */
     //PD14 TIM4_CH3 in Slave Toggle mode
     TIM_DeInit( TIM4 );
     /* Time base configuration */
     TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
     TIM_TimeBaseStructure.TIM_Period =100;
     TIM_TimeBaseStructure.TIM_Prescaler =0;
     TIM_TimeBaseStructure.TIM_ClockDivision = 0;
     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
     TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
 
     //Slave Mode
     TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_External1);//Rising edges of the selected trigger (TRGI) clock the counter
     TIM_SelectInputTrigger(TIM4, TIM_TS_ITR1);
 
     // TIM enable counter
     TIM_Cmd(TIM2, ENABLE);
     TIM_Cmd(TIM4, ENABLE);
 
     TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
}

The last line stops the MCU...but why??

Outcomes