IDLE flag problem with uart

dmastm32uart

void USART2_IRQHandler(void)
 
{
 
 /* USER CODE BEGIN USART2_IRQn 0 */
 
  /* UART IDLE Interrupt */
 
    if(__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE) == SET)  
 
    {
 
     __HAL_UART_CLEAR_IDLEFLAG(&huart2);
 print("time %d",timeCounter");
receivedDataFlag = 1;

 
}
 
}

When I use the this function check line idle states and decide the data received or not received. But this interrup trigger while transmitting. How can I seperate receive data line idle and receive idle ?

I want to trigger just receive data line idle, how can I do that ? What other register should I look at?

I get very interesting result,

Sender send every 100 ms data to my device;

If I use the only receive DMA functions; time return 10, 110, 220,330 (Idle states working)

But If I received than after transmit data with uart this times values return 10,13,15,… a mean transmit function cahnge the line idle state, how is the possible ? IS the UART_FLAG_IDLE related only rx?

EDIT:
By the way I am using rs485 so when I start to transmitting, I set to tranceiver transmitter mode so Sender side receiver mode so my MCU does decide to IDLE this state ? is that possible? How can I protect this situation?

When I start the transmition mode after received data, then completed callback call, When I call the HAL_UART_Receive_DMA(&huart2,(uint8_t*)dma_rx_buf,DMA_BUF_SIZE); function IDLE interrupt trigger every 5 ms but data sending timeout 100 ms

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
 

  HAL_UART_DMAStop(&huart2);
  dmaTransmitCompletedFlag = 1;
  RS485_Set_Receive_Mode();
  HAL_UART_Receive_DMA(&huart2,(uint8_t*)dma_rx_buf,DMA_BUF_SIZE);
  waitForTransmittingData = 0;

}

Best Answer

That interrupt is used for both transmit and receive.

The IDLE is relevant only to reception, it means there is at least one full frame of idle detected.

Using print in an interrupt is unwise, espcially if the print uses the same UART for which the interrupt is.

Related Topic