Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
Serial Class Reference
[Drivers]
A serial port (UART) for communication with other serial devices. More...
#include <Serial.h>
Inherits mbed::SerialBase, and mbed::Stream.
Public Member Functions | |
| Serial (PinName tx, PinName rx, const char *name=NULL, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) | |
| Create a Serial port, connected to the specified transmit and receive pins. | |
| Serial (PinName tx, PinName rx, int baud) | |
| Create a Serial port, connected to the specified transmit and receive pins, with the specified baud. | |
| void | baud (int baudrate) |
| Set the baud rate of the serial port. | |
| void | format (int bits=8, Parity parity=SerialBase::None, int stop_bits=1) |
| Set the transmission format used by the serial port. | |
| int | readable () |
| Determine if there is a character available to read. | |
| int | writeable () |
| Determine if there is space available to write a character. | |
| void | attach (Callback< void()> func, IrqType type=RxIrq) |
| Attach a function to call whenever a serial interrupt is generated. | |
| template<typename T > | |
| MBED_DEPRECATED_SINCE ("mbed-os-5.1","The attach function does not support cv-qualifiers. Replaced by ""attach(callback(obj, method), type).") void attach(T *obj | |
| Attach a member function to call whenever a serial interrupt is generated. | |
| void | set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC) |
| Set the flow control type on the serial port. | |
| int | write (const uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE) |
| Begin asynchronous write using 8bit buffer. | |
| int | write (const uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE) |
| Begin asynchronous write using 16bit buffer. | |
| void | abort_write () |
| Abort the on-going write transfer. | |
| int | read (uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH) |
| Begin asynchronous reading using 8bit buffer. | |
| int | read (uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_RX_COMPLETE, unsigned char char_match=SERIAL_RESERVED_CHAR_MATCH) |
| Begin asynchronous reading using 16bit buffer. | |
| void | abort_read () |
| Abort the on-going read transfer. | |
| int | set_dma_usage_tx (DMAUsage usage) |
| Configure DMA usage suggestion for non-blocking TX transfers. | |
| int | set_dma_usage_rx (DMAUsage usage) |
| Configure DMA usage suggestion for non-blocking RX transfers. | |
| MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileLike::seek") virtual off_t lseek(off_t offset | |
| Move the file position to a given offset from a given location. | |
Protected Member Functions | |
| virtual void | lock () |
| Acquire exclusive access to this serial port. | |
| virtual void | unlock () |
| Release exclusive access to this serial port. | |
Detailed Description
A serial port (UART) for communication with other serial devices.
Can be used for Full Duplex communication, or Simplex by specifying one pin as NC (Not Connected)
Synchronization level: Thread safe
Example:
// Print "Hello World" to the PC #include "mbed.h" Serial pc(USBTX, USBRX); int main() { pc.printf("Hello World\n"); }
Definition at line 52 of file Serial.h.
Member Function Documentation
| void baud | ( | int | baudrate ) | [inherited] |
Set the baud rate of the serial port.
- Parameters:
-
baudrate The baudrate of the serial port (default = 9600).
Definition at line 43 of file SerialBase.cpp.
| MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
| "Replaced by FileLike::seek" | |||
| ) | [inherited] |
Move the file position to a given offset from a given location.
- Parameters:
-
offset The offset from whence to move to whence SEEK_SET for the start of the file, SEEK_CUR for the current file position, or SEEK_END for the end of the file.
- Returns:
- new file position on success, -1 on failure or unsupported
Generated on Tue Jul 12 2022 11:02:42 by
1.7.2