cancel
Showing results for 
Search instead for 
Did you mean: 

IR remote

OKuma
Associate II

I'm trying to code IR remote which uses NEC protocol using STM32f030 .

I'm able to do the code under while(1) as as a GPIO input

But i'm not able to implement it as an interrupt .

Kindly help me regarding the same

12 REPLIES 12

You don't need any delay.

Simply capture every edge and decode the protocol from that.

Did you read the AN Piranha gave above?

JW

OKuma
Associate II

Yeah I went through those documentation

All I need to do is Apply an interrupt on every edge and have to count to to a particular value and see if the value is 0 or 1

but i'm not able to capture every edge

whenever i press a button on remote I get interrupt only on 1 the first falling edge not after that .

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM17)
	{
 
		if(Is_First_Captured ==0)
		{
			IC_Value1 = HAL_TIM_ReadCapturedValue(&htim17, TIM_CHANNEL_1);
			Is_First_Captured =1;
		}
		else if(Is_First_Captured ==1)
		{
			IC_Value2 = HAL_TIM_ReadCapturedValue(&htim17, TIM_CHANNEL_1);
			if(IC_Value2 > IC_Value1)
			{
				Difference = IC_Value2 - IC_Value1;
			}
			else if(IC_Value2 > IC_Value1)
			{
 
				Difference = ((0xffff-IC_Value1)+IC_Value2) +1;
			}
			else
			{
				Error_Handler();
			}
			Frequency = HAL_RCC_GetPCLK1Freq() / Difference ;
			Is_First_Captured =0;
		}
 
 
 
	}
}

static void MX_TIM17_Init(void)
{
 
  /* USER CODE BEGIN TIM17_Init 0 */
 
  /* USER CODE END TIM17_Init 0 */
 
  TIM_IC_InitTypeDef sConfigIC = {0};
 
  /* USER CODE BEGIN TIM17_Init 1 */
 
  /* USER CODE END TIM17_Init 1 */
  htim17.Instance = TIM17;
  htim17.Init.Prescaler = 16;
  htim17.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim17.Init.Period = 1000000;
  htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim17.Init.RepetitionCounter = 0;
  htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim17) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_IC_Init(&htim17) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
  sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
  sConfigIC.ICFilter = 0;
  if (HAL_TIM_IC_ConfigChannel(&htim17, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM17_Init 2 */
 
  /* USER CODE END TIM17_Init 2 */
 
}

> sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;

I don't use Cube/HAL, but probably here you should set something else for both edges capture.

JW