Loading...
Searching...
No Matches
SerialUARTClass Class Reference

Serial port on one RP2040 UART; sketches use Serial1 and Serial2. More...

#include <SerialUART.h>

Inheritance diagram for SerialUARTClass:

Public Member Functions

 SerialUARTClass (uart_inst_t *uart, pin_size_t tx_pin, pin_size_t rx_pin)
 Binds the port to a UART and its pins; nothing is set up until begin().
void begin (unsigned long baud) override
 Starts the port with 8 data bits, no parity and 1 stop bit.
void begin (unsigned long baud, uint16_t config) override
 Starts the port with the given frame format.
void end () override
 Waits for queued bytes to go out, then stops the port and frees its pins.
int available () override
 Number of received bytes waiting to be read.
int peek () override
 Next received byte, left in the buffer.
int read () override
 Takes the next received byte from the buffer.
void flush () override
 Waits until every queued byte has been sent.
size_t write (uint8_t c) override
 Sends one byte, waiting while the hardware FIFO is full.
 operator bool () override
 Whether the port is running.

Detailed Description

Serial port on one RP2040 UART; sketches use Serial1 and Serial2.

Received bytes go into a 256-byte buffer from an interrupt; bytes that arrive while it is full are dropped.

Constructor & Destructor Documentation

◆ SerialUARTClass()

SerialUARTClass::SerialUARTClass ( uart_inst_t * uart,
pin_size_t tx_pin,
pin_size_t rx_pin )
inline

Binds the port to a UART and its pins; nothing is set up until begin().

Parameters
uartpico-sdk UART (uart0 or uart1).
tx_pinArduino pin for TX.
rx_pinArduino pin for RX.

Member Function Documentation

◆ available()

int SerialUARTClass::available ( )
override

Number of received bytes waiting to be read.

Returns
0-256.

◆ begin() [1/2]

void SerialUARTClass::begin ( unsigned long baud)
inlineoverride

Starts the port with 8 data bits, no parity and 1 stop bit.

Parameters
baudBaud rate, e.g. 115200.

◆ begin() [2/2]

void SerialUARTClass::begin ( unsigned long baud,
uint16_t config )
override

Starts the port with the given frame format.

Parameters
baudBaud rate, e.g. 115200.
configFrame format, e.g. SERIAL_8N1 or SERIAL_7E2. Mark and space parity are not supported and give no parity.

◆ end()

void SerialUARTClass::end ( )
override

Waits for queued bytes to go out, then stops the port and frees its pins.

Unread received bytes are discarded.

◆ operator bool()

SerialUARTClass::operator bool ( )
inlineoverride

Whether the port is running.

Returns
true between begin() and end().

◆ peek()

int SerialUARTClass::peek ( )
override

Next received byte, left in the buffer.

Returns
0-255, or -1 if nothing has been received.

◆ read()

int SerialUARTClass::read ( )
override

Takes the next received byte from the buffer.

Returns
0-255, or -1 if nothing has been received.

◆ write()

size_t SerialUARTClass::write ( uint8_t c)
override

Sends one byte, waiting while the hardware FIFO is full.

Parameters
cByte to send.
Returns
1, or 0 if the port has not been started.

The documentation for this class was generated from the following file: