Arduino hardware serial (i.e. 8u2, 16u2 USB) is HARDWARE flow control possible?

Hi all

Using a standard Arduino (like a MEGA2560 with a 16U2 serial <-> USB interface), it it possible to start and stop serial data transfer via hardware (i.e. RTS/CTS)?

I know that there is "DTR true/false" and "RTS true/false" already in the code (in fact, I use the DTR code, connected to a "RESET" JButton in the serial monitor to do an Arduino reset [see pic below]).

There is an inherent problem in the serial code that if it gets too much data too fast, the whole thing (serial monitor and IDE) completely lock up and the only recovery is to send an external SIGKILL to all the running JAVA processes.

What I want to do is add some code that checks when the buffer is getting full and shut off CTS to allow the buffer to drain rather than overflow.

I already know where to read the buffer usage and how to turn CTS true or false, but I can't seem to stop serial data flow via hardware.

So my questions are:
(1) IS it possible at all?
(2) If so, HOW to do it?

My external serial terminal (MINICOM) responds to RTS/CTS just fine, but the internal Arduino IDE doesn't seem to. Any help will be greatly appreciated!

(click for full size)
arduino_serial.jpg

There is an inherent problem in the serial code that if it gets too much data too fast, the whole thing (serial monitor and IDE) completely lock up and the only recovery is to send an external SIGKILL to all the running JAVA processes.

I doubt that this happens because of to much data or data arriving to fast. I never had such a problem and I use Linux too.

What I want to do is add some code that checks when the buffer is getting full and shut off CTS to allow the buffer to drain rather than overflow.

On which side do you plan to do that? On the microcontroller? You know how much RAM it has? Fix the problem on the PC!

(1) IS it possible at all?

Yes, but not in hardware but in software. Simply stop sending data. It depends on the application if that makes sense.

(2) If so, HOW to do it?

Make a custom board that connects one of the GPIOs of the XXU2 to the main MCU and periodically check that input. If it goes HIGH, stop sending to the serial interface.

As I already stated, it's nonsense to stop a relatively slow MCU to wait for an incredible fast PC. Today's PCs are more than fast enough to handle the serial data an Arduino is able to deliver.

pylon:
Q: I doubt that this happens because of to much data or data arriving to fast. I never had such a problem and I use Linux too.
A: The problem occurs when the Arduino tries to send serial data to the IDE's "serial monitor" at a continuous high speed of 115200 baud.

Q: On which side do you plan to do that? On the microcontroller? You know how much RAM it has? Fix the problem on the PC!
A: My PC is no problem I can take in 1.8 megabits per second reliably (i.e. through a TTY port using Minicom). The problem is the slow, clumsy way that the Arduino IDE handles incoming serial data.

Q: Yes, but not in hardware but in software. Simply stop sending data. It depends on the application if that makes sense.
A: Of course in software. What I want to do is know when the Arduino serial monitor buffer is getting full (already know how to do that) and THEN via the USB/Serial link tell the Arduino board to stop for a bit until the Arduino IDE buffer empties somewhat.

Q: Make a custom board that connects one of the GPIOs of the XXU2 to the main MCU and periodically check that input. If it goes HIGH, stop sending to the serial interface.
A: That would work, but I want a "generic" non-hack solution.

Q: As I already stated, it's nonsense to stop a relatively slow MCU to wait for an incredible fast PC. Today's PCs are more than fast enough to handle the serial data an Arduino is able to deliver.
A: The problem is not the PC as I said before. The Arduino serial monitor chokes when fed too much data too quickly. It's a JAVA problem, no doubt.

Establish a handshaking protocol between the PC and Arduino app. A generic one is xon/xoff.

Establish a handshaking protocol between the PC and Arduino app. A generic one is xon/xoff.

As I wrote you can do that but it usually doesn't make sense. As I don't know what kind of data you're transferring, I'm not able to suggest what to do in the specific case.

The problem occurs when the Arduino tries to send serial data to the IDE's "serial monitor" at a continuous high speed of 115200 baud.

My serial monitor is able to receive at 115200 baud without ceasing. Is your PC ancient?
What's the problem? Do some characters get lost? Did you check the memory on the PC?

My PC is no problem I can take in 1.8 megabits per second reliably (i.e. through a TTY port using Minicom). The problem is the slow, clumsy way that the Arduino IDE handles incoming serial data.

Nobody says you have to use the serial monitor of the IDE. Use any serial terminal you have and that works.

Of course in software. What I want to do is know when the Arduino serial monitor buffer is getting full (already know how to do that) and THEN via the USB/Serial link tell the Arduino board to stop for a bit until the Arduino IDE buffer empties somewhat.

That means you want to change the IDE software (that's the only part of the game that knows when it's not able to get all the bytes from the driver) or even worse, change the driver to do so.
Of course you can do that, your sketch must implement that but usually data sent to the PC cannot be sent later on, especially not if you have a constant stream of data. Remember an UNO has 2kB of RAM, so let's say you have a simple sketch so you can free 500 bytes for buffering, that will be filled in about 50ms at that speed. Excuse me but your trying a change at the wrong end.

That would work, but I want a "generic" non-hack solution.

You can use the XON/XOFF variant, but that's much more of a hack because you have to change either the Linux driver or the IDE software. The simplest solution is still to simply use another serial terminal if your IDE isn't reliable enough to keep up with your data stream.