cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement UART receive with unfixed data size?

yang2
Associate III
Posted on July 01, 2016 at 07:39

Hello all,

I use STM32F303VC and plant to use UART to receive data, but the receive size of data are different. Does anyone know how to implement it?

Thanks

2 REPLIES 2
slimen
Senior
Posted on July 01, 2016 at 10:27

Hi,

You can refer to the UART examples under 

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef3.html

 package:

STM32Cube_FW_F3_V1.5.0\Projects\STM32303C_EVAL\Examples\UART

Regards

AvaTar
Lead
Posted on July 01, 2016 at 10:39

Use single-character reception, if possible (RX interrupt).

Use a receive buffer sufficient for the maximal message length, including some headroom.

Check for buffer index range, message start character and message termination character, in that order.

On start character, reset the buffer index to zero. On index overflow, too, but ignore the character.

On message termination, copy the message immediately to a processing buffer for further checks/processing. Otherwise, new characters might start to overwrite it in the meantime.

The reception and processing of Modbus-ASCII or GPS (NMEA183) are a good examples to google for.