cancel
Showing results for 
Search instead for 
Did you mean: 

Sending IR datas via timer

fozen.1
Associate

Hi,

I have STM32G0 series MCU. I want to receive and send IR datas. I can receive IR datas successfully with timer via DMA. and then I want to send these datas as IR datas.

I try to use 2 channels. I set one channel as output compare no output for timing base and I set one another as pwm generation. But I could not be successful. What am I doing wrong ?

I have a function in TIM1 capture compare interrupt as below, I don't use HAL_TIM_IRQHandler(&htim1) function there.

void TIM1_CC_IRQHandler(void)
{
  /* USER CODE BEGIN TIM1_CC_IRQn 0 */
#ifndef USE_IRQ_HANDLER	
  /* USER CODE END TIM1_CC_IRQn 0 */
  HAL_TIM_IRQHandler(&htim1);
  /* USER CODE BEGIN TIM1_CC_IRQn 1 */
#endif
	IR_Transmit_Start_IT(&htim1);
  /* USER CODE END TIM1_CC_IRQn 1 */
}
void IR_Transmit_Start_IT(TIM_HandleTypeDef *htim)
{
	
	if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3))
	{
		// new pulse time load to timer 
		htim1.Instance->CCR3 = IR_Receive_Buffer[sendingDataIndex];
 
		if(sendingDataIndex % 2 == 0)
		{	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);}
		else
		{HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_4);	}
		sendingDataIndex++;
		
		
		if(sendingDataIndex >= IR_receivedDataCount)
		{
			IR_receivedDataCount = 0;
			sendingDataIndex = 0;
			HAL_TIM_OC_Stop(&htim1, TIM_CHANNEL_3);
			HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_4);
			//HAL_GPIO_WritePin(GPIOA, IR_TRANSMIT_Pin, GPIO_PIN_SET);
			__HAL_TIM_CLEAR_FLAG(&htim1, TIM_FLAG_CC2);
			__HAL_TIM_CLEAR_FLAG(&htim1, TIM_FLAG_CC3);
			__HAL_TIM_CLEAR_FLAG(&htim1, TIM_FLAG_CC4);
			__HAL_TIM_DISABLE_IT(&htim1, TIM_IT_CC2);
			__HAL_TIM_DISABLE_IT(&htim1, TIM_IT_CC3);
			__HAL_TIM_DISABLE_IT(&htim1, TIM_IT_CC4);
			__HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
 
		}
	}
	
}

When I am ready to send datas, I call below functions.

htim1.Instance->CCR3 = IR_Receive_Buffer[0];
	
	__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_CC3);		
	HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3);

Then program enters the interrupt routine but I have no success. Is there someone did same thing like this ?

1 REPLY 1
Bubbles
ST Employee

Hello @fozen.1​ ,

I'm not sure what kind of IR communication you have in mind, but there is existing AN4834 about IR remote using timers.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.