Skip to main content
mehmet.karakaya
Associate III
August 20, 2022
Question

HAL UART receive help - varying number char receive

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

Tesla DeLorean
Guru
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.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
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.

Pavel A.
August 21, 2022

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

Piranha
Principal III
August 27, 2022
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);

The second parameter is the size of received data.