Menu Close

Serial Communication Protocol

A communication protocol is an agreement between two devices about how they should transfer data to each other.  In this entry we will talk about serial communication protocols.  Serial communication is a single channel that transmits data in a series of bits.  A series of bits in the protocol make up a data packet.  The communication protocol has to address the following issues:

  • What is the order of the bits?
  • How does the receiver know when to start looking for information?
  • How does the receiver know when the data packet starts?
  • How does the receiver know when the data packet has ended?
  • What does the data inside the packet mean?

The issue of when to look for data must be decided before creating the protocol.  The start of a transmission can take several forms.  Depending on the devices several methods can be used.  A few of them are listed below:

  • Set a separate channel from a low bit to a high bit to indicate that the receiver should start listening for the data packet.
  • Set the transmission channel from a low bit to a high bit for a specific period of time then follow with data.
  • Have the receiver continually looking for data then use an agreed upon start bit to indicate the start of the transmission with an end bit to indicate the end of the transmission.  This method usually gets placed into a circular buffer where the data packets can be

For this example, we will have our receiver continuously looking for data.  The data we are going to receive has a set amount of bits that it will send and does not have a need to be variable.  We will design our data packet so that it has a start and end byte.  The table below shows what our data packet will look like.  This data is coming from an AHRS on a helicopter.  It gives us all the data we need to understand the orientation and position of the helicopter within our reference frames.  By using a 16 bit integer we are able to use 65,535 values for our data.  The higher number of bits we use the more resolution our data has.  As our data packet grows so does the time to send it through our communications link which leaves the user deciding what is more important speed or resolution.

Description Type
Start Byte Ascii Charater “A” – 8 bit
Roll Angle 16 bit integer
Pitch Angle 16 bit integer
Yaw Angle 16 bit integer
Acceleration X 16 bit integer
Acceleration Y 16 bit integer
Acceleration Z 16 bit integer
Roll rate 16 bit integer
Pitch Rate 16 bit integer
Yaw Rate 16 bit integer
Latitude 16 bit integer
Longitude 16 bit integer
Altitude 16 bit integer
End Byte Ascii Character “B” – 8 bit

If you data is going to be variable in length then at the start of your packet you should have information about the size of the data that is coming so you can collect the full packet before you start processing assuming you need to wait for the entire packet to arrive.  An example of this would be a photograph.  Depending on if you are using compression the image size can vary slightly with each image sent.  To handle this you would encode in the start of the packet a place that shows the size and possible the number of bits that make up the whole packet.

This is the short version of creating a communication protocol.  I will add to it as time goes on.

Terms used in serial communications

  • Asynchronous – transmission does not occur at the same time or have the same period or phase.  Timing signals are derived from special characters in the data stream.
  • Synchronous – transmission that requires a common clock signal between communicating devices to coordinate their transmissions.
  • Bit – a single data point having either 0 or 1 state.
  • Byte – sequence of 8 bits which represents one character of alphanumeric data.
  • Start-bit – The first bit of data used to show the start of the transmission.
  • Stop-Bit – The last bit of data used to show the end of the transmission.
  • Baud – A data transmission rate for modems.  Example 9600 baud = 9600 bits/second = 1200 bytes/second
  • Parity bit – a bit that is used in error detection in which a 0 or 1 is added to each group of bits so that it will have either an odd number of 1’s or an even number of 1’s.  If the parity is odd then any group with even bits contains an error.
  • Read Timeout – the longest amount of time the connection will wait to read data.

Leave a Reply

Your email address will not be published. Required fields are marked *