Skip to main content
John Craven
Senior
January 16, 2017
Question

Cancel a pending UART recieve

  • January 16, 2017
  • 5 replies
  • 858 views
Posted on January 16, 2017 at 23:02

If i start an UART receive with an interrupt looking for the next inbound byte/char;

HAL_UART_Receive_IT(&huart1, &UART1_Data, 1);

how can i cancel the receive before receiving the next byte/char?

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    January 16, 2017
    Posted on January 16, 2017 at 23:08

    I'd imagine you could flag it yourself and handle in the callback.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    John Craven
    Senior
    January 16, 2017
    Posted on January 16, 2017 at 23:13

    when you say flag it, do you mean force an interrupt by setting a interrupt bit in the uart and then handling the interrupt?

    Tesla DeLorean
    Guru
    January 17, 2017
    Posted on January 17, 2017 at 02:57

    I mean on your side, presumably you're going to want it to receive again at some point, and if you don't keep servicing it you'll have it overrun.

    Flag that you want to cancel, eat the byte if you don't want it, and don't light off another.

    Why are you looking to cancel it? Do you have some secondary buffering, or are you using this method to pull and process data a byte at a time.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    T J
    Senior III
    January 16, 2017
    Posted on January 17, 2017 at 00:29

    did you fix it ?

    would you like to use the DAM rx functions ?

    I get an interrupt on each and every character.

    John Craven
    Senior
    June 15, 2017
    Posted on June 15, 2017 at 17:29

    Updating this thread. My original post and other similar posts have been heard by the HAL developers.

    New HAL functions were added recently for UARTs including;

    /* Transfer Abort functions */

    HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);

    HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);

    HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);

    HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);

    HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);

    HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);

    as of the time of this update, not all HAL series have been updated, but will be as each new series FW is released.

    I will test HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart) in my original project shortly.