askvity

What is serial flow control?

Published in Serial Communication 4 mins read

Serial flow control is the method a serial device uses to manage the amount of data transmitted to itself. It prevents data loss when the receiving device can't process data as quickly as it's being sent.

Understanding Serial Flow Control

Flow control is crucial for reliable serial communication. Without it, a fast sender could easily overwhelm a slower receiver, leading to dropped data and communication errors.

Methods of Serial Flow Control

There are primarily two types of serial flow control:

  • Hardware Flow Control: Uses dedicated hardware signals (RTS/CTS) to signal when the receiver is ready to receive data. Sometimes called pacing or hardware handshaking instead of flow control.
  • Software Flow Control: Uses special characters (XON/XOFF) within the data stream to signal when to start or stop transmitting.

Hardware Flow Control (RTS/CTS)

This method utilizes two signals:

Signal Direction Description
RTS Output Request To Send: The sending device asserts this signal to indicate it has data to send.
CTS Input Clear To Send: The receiving device asserts this signal to indicate it is ready to receive data. The sending device waits for CTS to be asserted before sending data.

How it works:

  1. The sending device asserts RTS.
  2. The receiving device, if ready, asserts CTS.
  3. The sending device transmits data.
  4. If the receiving device becomes busy, it de-asserts CTS.
  5. The sending device stops transmitting until CTS is re-asserted.

Software Flow Control (XON/XOFF)

This method uses special control characters embedded in the data stream:

  • XON (Transmit On): Typically represented by ASCII character 17 (Ctrl-Q). Tells the sender to resume transmitting.
  • XOFF (Transmit Off): Typically represented by ASCII character 19 (Ctrl-S). Tells the sender to pause transmitting.

How it works:

  1. The receiving device, when becoming busy, sends an XOFF character to the sender.
  2. The sender, upon receiving XOFF, pauses its transmission.
  3. The receiving device, when ready again, sends an XON character to the sender.
  4. The sender, upon receiving XON, resumes its transmission.

Advantages and Disadvantages

Feature Hardware Flow Control (RTS/CTS) Software Flow Control (XON/XOFF)
Reliability More reliable; uses dedicated hardware signals. Less reliable; susceptible to data corruption if XON/XOFF characters appear in the data stream.
Overhead Lower overhead; no control characters within the data stream. Higher overhead; control characters can reduce the effective data throughput.
Implementation Requires dedicated hardware lines; may not be available on all serial ports. Easier to implement; requires only the ability to send and receive specific characters.
Suitability Best for high-speed communication where reliability is critical. Suitable for lower-speed communication and when hardware flow control is unavailable or impractical.
Data Stream Doesn't interfere with the data stream, as flow control is handled out-of-band. Can potentially interfere with the data stream, especially if the application doesn't properly escape XON/XOFF characters.

Practical Insights

  • Choose hardware flow control (RTS/CTS) whenever possible for its reliability and efficiency, especially in high-speed applications.
  • Software flow control (XON/XOFF) is a viable alternative if hardware flow control isn't available or supported.
  • Properly configure both the sending and receiving devices to use the same flow control method.
  • Be aware of potential issues with software flow control if your data stream might contain XON/XOFF characters. Implement appropriate escaping mechanisms if needed.

Related Articles