Skip to main content
Visitor II
August 20, 2022
Question

HAL UART receive help - varying number char receive

  • August 20, 2022
  • 4 replies
  • 1283 views

hello dear forum,

I want receive varying no of char from UART in IT mode

HAL_UARTEx_ReceiveToIdle_IT() function is good but

how to know amount of received chars ?

thank you

    This topic has been closed for replies.

    4 replies

    Graduate II
    August 20, 2022

    Hard to know, suppose you just have to count them.

    On most STM32 there's an interrupt for each byte, its the HAL that wants a number to trigger the callback there.

    Perhaps have a protocol that infers length early.

    Have a method that understands inter-message gaps.

    Have a stateful digest of the arrived data so you don't wait or spin.

    Visitor II
    August 21, 2022

    Two ways,

    Best for reaction time, (hw fifoed) byte interrupt, sometime transmission break pause may be used, sometime interrupt on detected special value will enable DMA transfer to reduce interrupt frequency (not latency).

    Best for low cpu usage is to use dma to cycle through a big buffer and time periodically sweep it.

    Super User
    August 21, 2022

    UART_HandleTypeDef has a member RxXferCount. It is the count of received bytes.

    Graduate II
    August 27, 2022
    void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);

    The second parameter is the size of received data.