user6930: Does there exist (any user developed etc.) version of the Hardware UART serial library that has support for RTS/CTS based flow control? 
More interested in the Tx side (Arduino sends data, while the peripheral can back-pressure). The library should enable the Arduino to stop transmitting within 1 character of seeing a 'not ready' indication from the peripheral.
Thank you.

user7508: I am not aware of any such library. You could try to implement one
yourself, and maybe share it with the community. :-)
If you take this route, you will have to copy the file
HardwareSerial.cpp from the Arduino core, make your
changes there, and have your version replace the one from the core. Here
are some ideas that may help to get you started:

Wire the 'ready' signal from the device to an interrupt-capable pin of
the Arduino.
Inside the interrupt handler:


when 'ready' is deasserted, disable the UDRE interrupt by issuing
cbi(*_ucsrb, UDRIE0)
when ready is asserted, enable it again, but only if the output
buffer is not empty:
if (_tx_buffer_head != _tx_buffer_tail) sbi(*_ucsrb, UDRIE0);

Patch HardwareSerial::write() to enable the interrupt only if
'ready' is asserted.
Note that the UDRE IRQ can be explicitly called
by HardwareSerial::flush()
and by HardwareSerial::write() if interrupts are globally
disabled. You will have to condition this on the 'ready' signal.
Note also that HardwareSerial::write() can write directly to the
UART if the buffer is empty. This also has to be
conditioned on the 'ready' signal.


6930: <p>Does there exist (any user developed etc.) version of the Hardware UART serial library that has support for RTS/CTS based flow control? 
More interested in the Tx side (Arduino sends data, while the peripheral can back-pressure). The library should enable the Arduino to stop transmitting within 1 character of seeing a 'not ready' indication from the peripheral.</p>

<p>Thank you.</p>
 7508: <p>I am not aware of any such library. You could try to implement one
yourself, and maybe share it with the community. :-)</p>

<p>If you take this route, you will have to copy the file
<a href="https://github.com/arduino/ArduinoCore-avr/blob/1.6.23/cores/arduino/HardwareSerial.cpp" rel="nofollow noreferrer">HardwareSerial.cpp from the Arduino core</a>, make your
changes there, and have your version replace the one from the core. Here
are some ideas that may help to get you started:</p>

<ul>
<li>Wire the 'ready' signal from the device to an interrupt-capable pin of
the Arduino.</li>
<li>Inside the interrupt handler:

<ul>
<li>when 'ready' is deasserted, disable the UDRE interrupt by issuing
<code>cbi(*_ucsrb, UDRIE0)</code></li>
<li>when ready is asserted, enable it again, but only if the output
buffer is not empty:
<code>if (_tx_buffer_head != _tx_buffer_tail) sbi(*_ucsrb, UDRIE0);</code></li>
</ul></li>
<li>Patch <code>HardwareSerial::write()</code> to enable the interrupt only if
'ready' is asserted.</li>
<li>Note that the UDRE IRQ can be explicitly called
<a href="https://github.com/arduino/ArduinoCore-avr/blob/1.6.23/cores/arduino/HardwareSerial.cpp#L219" rel="nofollow noreferrer">by <code>HardwareSerial::flush()</code></a>
and <a href="https://github.com/arduino/ArduinoCore-avr/blob/1.6.23/cores/arduino/HardwareSerial.cpp#L262" rel="nofollow noreferrer">by <code>HardwareSerial::write()</code></a> if interrupts are globally
disabled. You will have to condition this on the 'ready' signal.</li>
<li>Note also that <a href="https://github.com/arduino/ArduinoCore-avr/blob/1.6.23/cores/arduino/HardwareSerial.cpp#L242" rel="nofollow noreferrer"><code>HardwareSerial::write()</code> can write directly to the
UART</a> if the buffer is empty. This also has to be
conditioned on the 'ready' signal.</li>
</ul>
