I am interfacing IR remote which works on RC5 protocol with STM32F405VG. I have a PCB where I am using TSOP 1738 to receive RC5 packets. I have connected the CRO. Whenever I am pressing any buttons on the remote, I am receiving the full packet.

Now to interface this on the PCB . I using timer to capture the duration between the rising/ falling edges. But it seems not to be working. I am new to the STM32 environment. Can anyone please check and confirm if the configuration set for the timers are correct or not. Here is the code:

GPIO_InitTypeDef GPIO_InitStructure;   //For GPIO pin where TSOP is connected
NVIC_InitTypeDef NVIC_InitStructure;   //Global interrupts
TIM_ICInitTypeDef TIM_ICInitStructure; //Timers

/*  Clock Configuration for TIMER */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE);

/* Pin configuration: input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;    //Pin2 of Port C
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;   //Input mode
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);    //Init GPIO


/* Enable the TIM global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

int PrescalerValue=0;
PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 6000000) - 1;

/* TIMER frequency input */
TIM_PrescalerConfig(TIM3, PrescalerValue, TIM_PSCReloadMode_Immediate);

/* TIM configuration */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
 TIM_PWMIConfig(TIM3, &TIM_ICInitStructure); 

/* Select the TIM3 Input Trigger: TI1FP1 */
TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);

/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

/* Configures the TIM Update Request Interrupt source: counter overflow */
TIM_UpdateRequestConfig(TIM3,  TIM_UpdateSource_Regular);

/* Set the TIM auto-reload register for each IR protocol */
TIM3->ARR = RC5TimeOut;

/* Clear update flag */
TIM_ClearFlag(TIM3, TIM_FLAG_Update);

/* Enable TIM3 Update Event Interrupt Request */
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

/* Enable the CC2/CC1 Interrupt Request */

/* Enable the timer */

And here is the code of Timer3 interrupt handler

void TIM3_IRQHandler(void)
  static uint32_t ICValue1;
  static uint32_t ICValue2;

 /* IC1 Interrupt*/
 if((TIM_GetFlagStatus(TIM3, TIM_FLAG_CC1) != RESET))
     TIM_ClearFlag(TIM3, TIM_FLAG_CC1);
    /* Get the Input Capture value */
   ICValue2 = TIM_GetCapture1(TIM3);

}  /* IC2 Interrupt */   
 else  if((TIM_GetFlagStatus(TIM3, TIM_FLAG_CC2) != RESET))
   TIM_ClearFlag(TIM3, TIM_FLAG_CC2);
   /* Get the Input Capture value */
  ICValue1 = TIM_GetCapture2(TIM3);

/* Checks whether the TIM3 flag is set or not.*/
else if ((TIM_GetFlagStatus(TIM3, TIM_FLAG_Update) != RESET))
  /* Clears the TIM3 pending flags*/
  TIM_ClearFlag(TIM3, TIM_FLAG_Update);



After initializing, interrupt handler starts working but IC1 or IC2 interrupt event never occurred even though I keep pressing the remote key. Please help thanks.


Change the line:

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

To this:

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

To complete connection of the input capture alternative function mode.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.