AnsweredAssumed Answered

Config TIMx for external clock mode 1

Question asked by shams.hamed on Jun 29, 2016
Latest reply on Jun 29, 2016 by shams.hamed
Hi
I want to config TIM3 channel 2 for input pulses and generate pulse with the same frequency at PC0 of STM32F103.
Its my code. Is it true?

void TIM3CH1_Configuration(void)
{
 /* TIM3 configuration:  Input Capture mode ------------------------
     The external signal is connected to TIM3 CH2 pin (PA.07),
     The Rising edge is used as active edge,
  ------------------------------------------------------------ */
  TIM_ICInitTypeDef TIM_ICInitStructure;
  TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
     
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);   
    TIM_DeInit(TIM3);                             
     
    TIM_BaseInitStructure.TIM_Period = 1;  
    TIM_BaseInitStructure.TIM_Prescaler =  0;  
    TIM_BaseInitStructure.TIM_ClockDivision = 0;
    TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;  
    TIM_BaseInitStructure.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM3, &TIM_BaseInitStructure);
     
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;
 
  TIM_ICInit(TIM3, &TIM_ICInitStructure);
 
  /* Select the TIM3 Input Trigger: TI1FP1 */
  TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);// TIM_TS_TI2FP2==>PA7  -   TIM_TS_TI1FP1==>PA6
 
  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
    //TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1);
 
  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
 
  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);
 
  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
   
//  /////////////////NVIC/////////////////////////////////
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn ;   
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;        
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;            
    NVIC_Init(&NVIC_InitStructure);   
//  /////////////////////////////////////////////////////// 
 
}
 
 
 
void TIM3_IRQHandler(void)
{
         
    if (TIM_GetITStatus(TIM3, TIM_IT_CC2) != RESET)
    {  
            /* Clear TIM3 Capture compare interrupt pending bit */
            TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);
 
             
        GPIOC->BSRR = GPIO_Pin_0;
        GPIOC->BRR =  GPIO_Pin_0;
    }
}  

Regards

Outcomes