Arm Mbed OS support forum

Send data over UART

Hi everyone,
I am trying to send data over UART port between two microcontrollers. I must write this data received over UART comunication on a file, then how is the correct way to do that? I mean, Which is the correct way or the typical way to determine the end of a package of data? I am thinking to send a special character over uart to check the end of the data package or there is a better way to do that?

thanks for your help.

Three of the simpler approaches are

  1. Use a fixed sized packet

  2. Include a “count” value at the beginning of the packet to indicated the number of bytes that will be sent.

  3. Use a special character to indicate the termination of the transfer.

If the data is being sent in ASCII format then method ‘3’ would be the best. The carriage return (\r) or line-feed(\n) are normally used.

If the data to be sent is variable in size and binary then method ‘2’ would seem more appropriate.

If there is an issue of reliability, a more complex handshake approach may be needed.

Jim

1 Like

@jimherd thanks for your advice.