STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
SoftwareSerial Class Reference

Software serial (UART) emulation on any pair of GPIO pins, driven by a timer interrupt. More...

#include <SoftwareSerial.h>

Inheritance diagram for SoftwareSerial:

Public Member Functions

 SoftwareSerial (pin_size_t receivePin, pin_size_t transmitPin, bool inverse_logic=false)
 Create a software serial instance on the given pins.
 
virtual ~SoftwareSerial ()
 Stop this instance: stop listening and disable its timer interrupt.
 
void begin (long speed)
 Set the baud rate and initialize the pins.
 
bool listen ()
 Set this instance as the listening one.
 
void end ()
 Stop this instance: stop listening and disable the timer interrupt.
 
bool isListening ()
 Check if this instance is the active listener.
 
bool stopListening ()
 Stop listening on this instance.
 
bool overflow ()
 Check whether a byte was dropped because the receive buffer was full.
 
int peek ()
 Get the next received byte without removing it from the receive buffer.
 
virtual size_t write (uint8_t byte)
 Send one byte.
 
virtual int read ()
 Read the next byte from the receive buffer.
 
virtual int available ()
 Get the number of bytes in the receive buffer.
 
virtual void flush ()
 Clear the receive buffer and wait for any pending transmission to complete.
 
 operator bool ()
 Allow the instance to be used in a boolean context.
 

Static Public Member Functions

static void setInterruptPriority (uint32_t preemptPriority, uint32_t subPriority)
 Set the priority of the timer interrupt shared by all software serial instances.
 

Detailed Description

Software serial (UART) emulation on any pair of GPIO pins, driven by a timer interrupt.

Note
When the receive and transmit pins are the same, the instance works in half-duplex mode.

Constructor & Destructor Documentation

◆ SoftwareSerial()

SoftwareSerial::SoftwareSerial ( pin_size_t  receivePin,
pin_size_t  transmitPin,
bool  inverse_logic = false 
)

Create a software serial instance on the given pins.

Parameters
receivePinPin used to receive data (RX).
transmitPinPin used to transmit data (TX). Use the same pin as receivePin for half-duplex mode.
inverse_logicOptional, true to invert the logic level of the data. Default: false.

Member Function Documentation

◆ available()

int SoftwareSerial::available ( )
virtual

Get the number of bytes in the receive buffer.

Returns
Number of bytes available to read.

◆ begin()

void SoftwareSerial::begin ( long  speed)

Set the baud rate and initialize the pins.

Starts listening unless the instance is half-duplex.

Parameters
speedBaud rate in bits per second. If FORCE_BAUD_RATE is defined, its value is used instead.

◆ isListening()

bool SoftwareSerial::isListening ( )
inline

Check if this instance is the active listener.

Returns
true if this instance is listening, false otherwise.

◆ listen()

bool SoftwareSerial::listen ( )

Set this instance as the listening one.

Only one instance can listen at a time.

If another instance was listening, it is stopped and replaced by this one.

Returns
true if this instance became the listening one (replacing another one if any), false if it was already listening.

◆ operator bool()

SoftwareSerial::operator bool ( )
inline

Allow the instance to be used in a boolean context.

Returns
Always true.

◆ overflow()

bool SoftwareSerial::overflow ( )
inline

Check whether a byte was dropped because the receive buffer was full.

Clears the flag.

Returns
true if an overflow occurred since the last call, false otherwise.

◆ peek()

int SoftwareSerial::peek ( )

Get the next received byte without removing it from the receive buffer.

Returns
The next byte, or -1 if the receive buffer is empty.

◆ read()

int SoftwareSerial::read ( )
virtual

Read the next byte from the receive buffer.

Returns
The byte read, or -1 if the receive buffer is empty.

◆ setInterruptPriority()

void SoftwareSerial::setInterruptPriority ( uint32_t  preemptPriority,
uint32_t  subPriority 
)
static

Set the priority of the timer interrupt shared by all software serial instances.

Parameters
preemptPriorityPreemption priority of the interrupt.
subPrioritySub-priority of the interrupt.

◆ stopListening()

bool SoftwareSerial::stopListening ( )

Stop listening on this instance.

Waits for any pending output to complete.

Returns
true if this instance was actually listening, false otherwise.

◆ write()

size_t SoftwareSerial::write ( uint8_t  byte)
virtual

Send one byte.

Waits for any previous transmission to complete.

Parameters
byteByte to send.
Returns
Always 1.

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