cancel
Showing results for 
Search instead for 
Did you mean: 

How to change default UART Idle line Inactivity time

KAgga.1
Associate III

Hello There,

I'm utilizing IDLE event functionality of UART and use HAL_UARTEx_ReceiveToIdle_IT() for it.
The issue that I'm facing is that some times this API falsely detects an IDLE event upon reception (May be a Transmitter issue). So, to overcome that, I'm looking to increase IDLE inactivity time.

Kindly help on how to configure this.

Regards,
Keshav Aggarwal

13 REPLIES 13

I know about HAL_UART_RECEPTION_TOIDLE and HAL_UART_RECEPTION_TORTO, That is why I told the OP that HAL_UARTEx_ReceiveToIdle_IT() would not work.

Also won't work for LPUART as it doesn't have a flag for RTO.

If you find my answers useful, click the accept button so that way others can see the solution.

What arguments have you passed to HAL_UARTEx_ReceiveToIdle_IT, specifically the size? What is the shortest and longest length of your packet are you receiving? And what are you doing in HAL_UARTEx_RxEventCallback?

If you find my answers useful, click the accept button so that way others can see the solution.

Hello!

>>What arguments have you passed to HAL_UARTEx_ReceiveToIdle_IT, specifically the size?
For HAL_UARTEx_ReceiveToIdle_IT, I have taken the receive buffer to be double the size of the expected rx size i.e., 1024Bytes.

>>What is the shortest and longest length of your packet are you receiving?

It is variable. The longest length I received is near to half of the expected length.

>>And what are you doing in HAL_UARTEx_RxEventCallback?

Some non-blocking manipulations to the Rx data and in the last I recall HAL_UARTEx_ReceiveToIdle_IT(&huart5, Buffer, sizeof(Buffer)) to re-enable the reception.

There is one more thing I noticed in HAL_UART_ErrorCallback that during the reception, I also continuously receive ErrorCode->HAL_UART_ERROR_NE i.e., Noise Error. I also checked the waveform of the Rx line in the DSO which seems to be fine.

Regards,

Keshav Aggarwal

Karl Yamashita
Lead II

So to clarify, your Buffer size is 1024 bytes and the longest packet you'd expect is near half the size, or slightly less than 512 bytes? So that means you are solely relying on the IDLE bit to interrupt, as half or full complete callback will never be called. And some of those packets fall short of all being received into the Buffer before you get an IDLE interrupt?

 

Now i'm not sure if this will work as i have not tried it. So instead of using  HAL_UARTEx_ReceiveToIdle_IT, use HAL_UART_Receive_IT? That way you're not going to get an IDLE callback. Set up the USART to trigger on RTO that is greater than IDLE detection of 8 bits but no longer than when you expect your next packet to be received. Then in HAL_UART_ErrorCallback do what you would have done in HAL_UARTEx_RxEventCallback. As @Pavel A.  pointed out, you can check huart-> RxXferCount for the size that was received before the timeout

 

If you find my answers useful, click the accept button so that way others can see the solution.