Koduino
Public Member Functions | List of all members
USARTClass Class Reference

Serial / USART library (use on global objects Serial<x> where <x> can be 1, 2, 3) More...

#include <USARTClass.h>

Detailed Description

Serial / USART library (use on global objects Serial<x> where <x> can be 1, 2, 3)

Usage

  1. Call begin() with a baud rate (and optionally the mode)
  2. Use any of the Stream output methods to read or write

Example: Hello

void setup() {
Serial1.begin(115200);
}
void loop() {
Serial1 << "Hello\n";
delay(1000);
}

Public Member Functions

void begin (uint32_t baud, uint8_t mode)
 Opens a serial connection and configures the RX and TX pins. More...
 
void end ()
 Close the serial port.
 
void setPins (uint8_t tx, uint8_t rx)
 Change the default RX and TX pins. More...
 
virtual int available (void)
 Return the number of bytes in the receive buffer. More...
 
virtual int peek (void)
 Reads a single byte from the receive buffer. More...
 
virtual int read (void)
 Reads a single byte from the receive buffer. More...
 
virtual void flush (void)
 Waits till the previous write operation is finished.
 
virtual bool writeComplete ()
 Check if the previous write operation is finished. More...
 
virtual size_t write (uint8_t c)
 Write a single character. More...
 
- Public Member Functions inherited from Stream
void setTimeout (uint32_t timeout)
 Sets maximum milliseconds to wait for stream data. More...
 
bool find (char *target)
 Reads data from the stream until the target string is found. More...
 
bool find (char *target, size_t length)
 Reads data from the stream until the target string of given length is found. More...
 
bool findUntil (char *target, char *terminator)
 Same as find() but search ends if the terminator string is found. More...
 
int parseInt ()
 Returns the first valid (long) integer value from the current position. More...
 
float parseFloat ()
 Float version of parseInt() More...
 
size_t readBytes (char *buffer, size_t length)
 Read chars from stream into buffer. More...
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 Same as readBytes() with terminator character. More...
 

Inherits Stream.

Member Function Documentation

int USARTClass::available ( void  )
virtual

Return the number of bytes in the receive buffer.

Returns

Implements Stream.

void USARTClass::begin ( uint32_t  baud,
uint8_t  mode 
)

Opens a serial connection and configures the RX and TX pins.

Use setPins() to change the default RX and TX pins

Parameters
baudBaud rate as an integer
modeOne of SERIAL_<x> where <x> can be 8N1, 8N2, 7E1, 8E1, 7E2, 8E2, 7O1, 8O2 (default if omitted is 8N1)
int USARTClass::peek ( void  )
virtual

Reads a single byte from the receive buffer.

Does not increment the buffer pointer

Returns

Implements Stream.

int USARTClass::read ( void  )
virtual

Reads a single byte from the receive buffer.

Increments the buffer pointer

Returns

Implements Stream.

void USARTClass::setPins ( uint8_t  tx,
uint8_t  rx 
)

Change the default RX and TX pins.

Should be called before begin(). Defaults are

  • PA9, PA10 for Serial1
  • PB3, PB4 for Serial2
  • PB8, PB9 for Serial3
Parameters
txNew TX pin
rxNew RX pin
size_t USARTClass::write ( uint8_t  c)
virtual

Write a single character.

Does not block. Uses a ring buffer to queue outgoing transfers and interrupt handlers to transmit the queue.

Note: No output is allowed for the first 1 second on the bootloading port, Serial1 in order to not interfere with auto-reset and bootloading

Parameters
cCharacter to write
Returns
1 on success, 0 on failure
bool USARTClass::writeComplete ( )
virtual

Check if the previous write operation is finished.

Returns
true if complete

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