Serial Port Programming Part 9 - Hardware Flow Control - RTS,CTS

What is Flow Control?

Technically, flow control is a mechanism in which receiver can control the transmission speed. This is done in case of superfast sender and slow receiver. If we don't have flow control, in this case, the receive buffer in the receiver will be overwritten with the new data.

Hardware Flow Control in RS-232:

RS-232 provides two control lines for hardware flow control:

  • RTS (Request to Send)
  • CTS (Clear to Send)
RTS/CTS is handshaking method which uses one wire in each direction to allow each device to indicate to the other whether or not it is ready to receive data at a given moment of time.

The RTS pin of one device will be connected to CTS pin of the other device. RTS pin is output and CTS pin is input.

In case of connecting DTE to DTE(null modem cabling), we connect RTS of one device to CTS of other device.


In case of connecting DTE to DCE (straight through cabling), we connect RTS to RTS and CTS to CTS.

A device which is ready to accept data will keep the RTS line asserted (high), when it finds that the receiver buffer is going to be full in some time, it will deassert(low) the RTS line. The other device should look at is CTS state while transmitting, i.e., transmit only when the CTS pin is high. If it is low, wait until the CTS pin goes high.

If one of the device (for example device1 in device1, device2) is fast enough to receive data at any speed, CTS pin of device2 can be tied to high and RTS pin of device1 can be used for other functionality

How to enable Hardware Flow Control?

stty -F /dev/tty<port> crtscts

Or in the code, set 'CRTSCTS' in the c_cflag of struct termios structure.

Comments

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto