Using CTS / RTS Hardware Flow Control On Arduino

I Have a device that must utilize RTS, CTS, DTR hardware flow control to operate correctly. I have an Arduino ATMega1280 dev board. I am new at the arduino realm.

  • What pins should I use for CTS, RTS, and DTR on the ATMega1280?

  • How do I set this up in my arduino code?

I have found no examples on the internet about this, except to not use hardware flow control and just tie the RTS/CTS together. I cannot do this on this device. Again, it must use hardware flow control.

I Have a device that must utilize RTS, CTS, DTR hardware flow control to operate correctly.

You might get (better) answers if you told us what this super secret device is.

How do I set this up in my arduino code?

You'll have to write it - H/W handshaking isn't directly supported by the hardware serial library. Even XON/XOFF would be roll-your-own.

The answer depends, in large part, on the volume and speed of the data involved.

There's no provision in the Arduino library for RTS/CTS. Adding it is do-able, but not trivial. Especially on the receive side: the receiver interrupt code detects whether the just-received character is going to overflow the buffer, but RTS/CTS handshaking usually depends on the receiver dropping CTS several characters in advance of overflow.

On the transmit side, you may be able to get away with just checking the hadshake line before each write to the serial port, if your mystery gadget drops CTS when it still has enough room in its buffer to receive the largest chunk of data you write at a time. E.g., it's common for devices with a large (by Arduino standards) buffer of 512 bytes or more to drop CTS when they have 32, or even 64, bytes available. If your biggest write is smaller than that threshold, you can do everything at the application level. If not, you'll have to replace HardwareSerial::write.

A similar situation applies on the receive side: if your gadget writes relatively-small chunks at relatively-low rates, you may be able to get away with twiddling your CTS at the application level. If not, you're going to need to modify the receiver interrupt routine and HardwareSerial::read to track how much space is left in the buffer, and set CTS accordingly.