Electronic – RTS and CTS flow control

flow control

I recently ordered two Bluetooth dongles for my Arduinos so I can have them communicate over long range. The dongles that I ordered have pin labeled CTS-I and a pin labeled RTS-0. I did a little bit of googling and found that they have something to do with "flow control," what is that?

I have the Arduinos communicating properly without these pins in use. What are these two pins intended to be used for? Should I want to use them? How can I use them?

Best Answer

Flow control is a general term for a means by which an entity that wants to push information to another can avoid sending it faster than the recipient can accept. One of the earliest forms of flow control that still exists in common usage is commonly called xon/xoff; it was used in communication between teletypes, in situations where one teletype was using its paper-tape reader to send data to another teletype. Although a teletype printer could usually keep up with a paper tape reader (both operated at ten characters/second), that would be contingent upon things like an adequate supply of paper. An operator who noticed that it was necessary to replace the paper in a teletype which was receiving a transmission could type Control-S to send an XOFF character, which would ask the paper-tape reader at the other end to stop. After the paper was replaced, the operator could type Control-Q to restart the paper-tape reader. Those characters are still used to this day, although the far end of the connection will usually be a computer rather than a tape reader.

RTS/CTS protocol is a method of handshaking 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 any given moment. One device sends on RTS and listens on CTS; the other does the reverse. A device should drive its handshake-output wire low when it is ready to receive data, and high when it is not. A device that wishes to send data should not start sending any bytes while the handshake-input wire is low; if it sees the handshake wire go high, it should finish transmitting the current byte and then wait for the handshake wire to go low before transmitting any more.

Note that while devices should ideally never send more than a byte after their handshake input goes high (if the line goes high just as they start transmitting a character, they must allow that character to be transmitted completely), many PC serial ports do not comply with this even when handshaking is enabled. The serial ports allow software to detect the state of the incoming handshake wire, and expect software to decide when data should be enqueued for transmission. Unfortunately, the only way to achieve good performance with a serial port is to enqueue data for transmission slightly in advance of when it will actually be sent, and many PC serial ports will always transmit any queued-up data as fast as they can without regard for the handshake wires. Consequently, it's not uncommon for PC serial ports to send a dozen or so characters even after they've been asked to wait.