arduino-pico/docs/piouart.rst
Earle F. Philhower, III 226a318897
Add serial inversion for UART and SerialPIO (#2395)
Use real GPIO pad inversion to allow inverted RX, TX, and controls for
the hardware UART and software PIO-emulated serial ports.

Adds ``setInvertTX(bool)`` and ``setInvertRX(bool)`` calls to both ports,
with ``setInvertControl(bool)`` for the HW UARTS.
2024-08-31 07:46:11 -07:00

42 lines
1.7 KiB
ReStructuredText

"SoftwareSerial" PIO-based UART
================================
Equivalent to the Arduino SoftwareSerial library, an emulated UART using
one or two PIO state machines is included in the Arduino-Pico core. This
allows for up to 4 bidirectional or up to 8 unidirectional serial ports to
be run from the RP2040 without requiring additional CPU resources.
Instantiate a ``SerialPIO(txpin, rxpin, fifosize)`` object in your sketch and then
use it the same as any other serial port. Even, odd, and no parity modes
are supported, as well as data sizes from 5- to 8-bits. Fifosize, if not
specified, defaults to 32 bytes.
To instantiate only a serial transmit or receive unit, pass in
``SerialPIO::NOPIN`` as the ``txpin`` or ``rxpin``.
For example, to make a transmit-only port on GP16
.. code:: cpp
SerialPIO transmitter( 16, SerialPIO::NOPIN );
For detailed information about the Serial ports, see the
Arduino `Serial Reference <https://www.arduino.cc/reference/en/language/functions/communication/serial/>`_ .
Inversion
---------
``SoftwareSerial`` and ``SerialPIO`` can both support inverted input and/or outputs via the methods
``setInvertRX(bool invert)`` and ``setInvertTX(bool invert)``.
SoftwareSerial Emulation
========================
A ``SoftwareSerial`` wrapper is included to provide plug-and-play compatibility
with the Arduino `Software Serial <https://docs.arduino.cc/learn/built-in-libraries/software-serial>`_
library. Use the normal ``#include <SoftwareSerial.h>`` to include it. The following
differences from the Arduino standard are present:
* All ports are always listening
* ``listen`` call is a no-op
* ``isListening()`` always returns ``true``