cancel
Showing results for 
Search instead for 
Did you mean: 

UART and timer interrupt issue

SGonz.2
Associate II

Hello! Can you help me?

I'm receiving data in UART Rx with DMA and send it by USB, it works fine. Now i'm trying to set up a timer to check if I'm receiving data every 250[ms] and send a special message. When I don't configure the timer it works, but when I add the timer and receive data, I only send the special message even when it should send the UART Rx data.

This is my UserDataTreatment function, called inside the UART+DMA callback

void UserDataTreatment(UART_HandleTypeDef *huart, uint8_t* pData, uint16_t Size){
 
  if(huart->Instance == USART1){
	  uint8_t* pBuff = pData;
	  uint8_t  i;
	  uint8_t DataArray[USB_BUFFER_SIZE];
	  for (i = 0; i < Size; i++){
		DataArray[i] = *pBuff;
	    pBuff++;
	  }
	  __HAL_TIM_SetCounter(&htim2, 0);
	  CDC_Transmit_FS(DataArray, Size);
  }
}

And this is my period elapsed callback

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim){
	if(htim->Instance == TIM2){
		CDC_Transmit_FS(disconectMSG1, 5);
	}
}

The idea is to set up a timer, reset it in the UART callback, so if I don't don't receive data, the timer overflows and send the special message.

Thank you!

2 REPLIES 2

> CDC_Transmit_FS(DataArray, Size);

Is it OK to use a local variable here?

JW​

Yes, at least it works when timer are not enabled, but my problem is when I enable timers(TIM2, TIM3, TIM4) USART1, USART2 and USART3 appears to stop working.

Now I'm just sending data to USART1 Rx every 100[ms], if no data is received in 1[s], then make and interrupt and send a USB message, but it only executes the timer interrupt, like no data is received. I have a version without timers and USART works fine.