Skip to main content
Graduate II
September 20, 2024
Solved

Does HAL_UARTEx_ReceiveToIdle_IT deliver in chunks?

  • September 20, 2024
  • 2 replies
  • 1226 views

If I call HAL_UARTEx_ReceiveToIdle_IT to receive 512 bytes, will it wait till all 512 bytes are received before calling HAL_UARTEx_RxEventCallback or could it possibly call it several times, delivering fragments of the whole packet?

I'm asking because I see it getting called with smaller Sizes... and as far as I can see on my oscilloscope, there is no glitching in the stream being sent from the other device. No gaps or dropouts. There are some long sequences of 0x00 but they all have valid start and stop bits.

If the defined behaviour is to call the callback only on IDLE or when the full specified size has been received, then I'll need to look elsewhere for the issue. I'm just trying to get some clarity on what this method could do.

 

    This topic has been closed for replies.
    Best answer by TDK

    It calls HAL_UARTEx_RxEventCallback in the following cases:

    • When IDLE is detected.
    • When the transfer is half-complete.
    • When the transfer is complete.

    Use HAL_UARTEx_GetRxEventType to figure out which of these happened.

     

    As stated in the source code:

     * @note When HAL_UARTEx_ReceiveToIdle_IT() or HAL_UARTEx_ReceiveToIdle_DMA() API are called, progress
     * of reception process is provided to application through calls of Rx Event callback (either default one
     * HAL_UARTEx_RxEventCallback() or user registered one). As several types of events could occur (IDLE event,
     * Half Transfer, or Transfer Complete), this function allows to retrieve the Rx Event type that has lead
     * to Rx Event callback execution.

     

    2 replies

    Super User
    September 20, 2024

    The timeout for IDLE detection is quite small, maybe you don't notice this on the scope. Or some glitches are mistaken for start bits. Or RX stops because of other errors (FE, PE ...). Defined behavior is call a callback because of IDLE or other "events". If no "event" occur there should not be other reasons to stop. Anyway, recommend to write your own UART code instead of wandering in that "HAL" library. It is not too hard and result will be gratifying.

     

     

    TDKAnswer
    Super User
    September 20, 2024

    It calls HAL_UARTEx_RxEventCallback in the following cases:

    • When IDLE is detected.
    • When the transfer is half-complete.
    • When the transfer is complete.

    Use HAL_UARTEx_GetRxEventType to figure out which of these happened.

     

    As stated in the source code:

     * @note When HAL_UARTEx_ReceiveToIdle_IT() or HAL_UARTEx_ReceiveToIdle_DMA() API are called, progress
     * of reception process is provided to application through calls of Rx Event callback (either default one
     * HAL_UARTEx_RxEventCallback() or user registered one). As several types of events could occur (IDLE event,
     * Half Transfer, or Transfer Complete), this function allows to retrieve the Rx Event type that has lead
     * to Rx Event callback execution.

     

    KMillAuthor
    Graduate II
    September 20, 2024

    Thanks @TDK 

    I have this working now. 

    I was not checking the eventType.

    Now it is working as expected, although I might still take the suggestion that @Pavel A. gave and roll my own UART code.

    Thanks!