2020-02-15 02:51 AM
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
2020-02-21 12:11 AM
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
2020-02-21 03:09 AM
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 */
}
2020-02-21 08:19 AM
> sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
I don't use Cube/HAL, but probably here you should set something else for both edges capture.
JW