2022-08-20 10:16 AM
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
2022-08-20 11:58 AM
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.
2022-08-20 09:28 PM
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.
2022-08-21 12:14 PM
UART_HandleTypeDef has a member RxXferCount. It is the count of received bytes.
2022-08-27 07:37 AM
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);
The second parameter is the size of received data.