cancel
Showing results for 
Search instead for 
Did you mean: 

HAL UART receive help - varying number char receive

mehmet.karakaya
Associate III

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

4 REPLIES 4

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
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

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.
Evangelist III

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

Piranha
Chief II
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);

The second parameter is the size of received data.