A serial port (UART) for communication with other serial devices This is a variation of the Serial class that doesn't use streams, thus making it safe to use in interrupt handlers with the RTOS. More...
#include <RawSerial.h>
Public Member Functions | |
RawSerial (PinName tx, PinName rx, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) | |
Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. More... | |
int | putc (int c) |
Write a char to the serial port. More... | |
int | getc () |
Read a char from the serial port. More... | |
int | puts (const char *str) |
Write a string to the serial port. More... | |
void | baud (int baudrate) |
Set the baud rate of the serial port. More... | |
void | format (int bits=8, Parity parity=SerialBase::None, int stop_bits=1) |
Set the transmission format used by the serial port. More... | |
int | readable () |
Determine if there is a character available to read. More... | |
int | writeable () |
Determine if there is space available to write a character. More... | |
void | attach (Callback< void()> func, IrqType type=RxIrq) |
Attach a function to call whenever a serial interrupt is generated. More... | |
template<typename T > | |
void | attach (T *obj, void(T::*method)(), IrqType type=RxIrq) |
Attach a member function to call whenever a serial interrupt is generated. More... | |
template<typename T > | |
void | attach (T *obj, void(*method)(T *), IrqType type=RxIrq) |
Attach a member function to call whenever a serial interrupt is generated. More... | |
void | set_break () |
Generate a break condition on the serial line NOTE: Clear break needs to run at least one frame after set_break is called. More... | |
void | clear_break () |
Clear a break condition on the serial line NOTE: Should be run at least one frame after set_break is called. More... | |
void | send_break () |
Generate a break condition on the serial line. More... | |
void | enable_input (bool enable=true) |
Enable serial input. More... | |
void | enable_output (bool enable=true) |
Enable serial output. More... | |
void | set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC) |
Set the flow control type on the serial port. More... | |
void | set_flow_control (Flow type, const serial_fc_pinmap_t &static_pinmap) |
Set the flow control type on the serial port. More... | |
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. More... | |
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. More... | |
void | abort_write () |
Abort the on-going write transfer. More... | |
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. More... | |
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. More... | |
void | abort_read () |
Abort the on-going read transfer. More... | |
int | set_dma_usage_tx (DMAUsage usage) |
Configure DMA usage suggestion for non-blocking TX transfers. More... | |
int | set_dma_usage_rx (DMAUsage usage) |
Configure DMA usage suggestion for non-blocking RX transfers. More... | |
A serial port (UART) for communication with other serial devices This is a variation of the Serial class that doesn't use streams, thus making it safe to use in interrupt handlers with the RTOS.
Can be used for Full Duplex communication, or Simplex by specifying one pin as NC (Not Connected)
Example:
Definition at line 62 of file RawSerial.h.
RawSerial | ( | PinName | tx, |
PinName | rx, | ||
int | baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE |
||
) |
Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
tx | Transmit pin |
rx | Receive pin |
baud | The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) |
|
inherited |
Abort the on-going read transfer.
It is safe to call abort_read() when there is no on-going transaction.
|
inherited |
Abort the on-going write transfer.
It is safe to call abort_write() when there is no on-going transaction.
|
inherited |
Attach a function to call whenever a serial interrupt is generated.
func | A pointer to a void function, or 0 to set as none |
type | Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) |
|
inherited |
Attach a member function to call whenever a serial interrupt is generated.
obj | pointer to the object to call the member function on |
method | pointer to the member function to be called |
type | Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) |
Definition at line 121 of file SerialBase.h.
|
inherited |
Attach a member function to call whenever a serial interrupt is generated.
obj | pointer to the object to call the member function on |
method | pointer to the member function to be called |
type | Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) |
Definition at line 139 of file SerialBase.h.
|
inherited |
Set the baud rate of the serial port.
baudrate | The baudrate of the serial port (default = 9600). |
|
inherited |
Clear a break condition on the serial line NOTE: Should be run at least one frame after set_break is called.
|
inherited |
Enable serial input.
If both serial input and serial output are disabled, the peripheral is freed. If either serial input or serial output is re-enabled, the peripheral is reinitialized.
On re-initialization rx interrupts will be enabled if a rx handler is attached. The rx handler is called once during re-initialization.
|
inherited |
Enable serial output.
If both serial input and serial output are disabled, the peripheral is freed. If either serial input or serial output is re-enabled, the peripheral is reinitialized.
On re-initialization tx interrupts will be enabled if a tx handler is attached. The tx handler is called once during re-initialization.
|
inherited |
Set the transmission format used by the serial port.
bits | The number of bits in a word (5-8; default = 8) |
parity | The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) |
stop_bits | The number of stop bits (1 or 2; default = 1) |
int getc | ( | ) |
Read a char from the serial port.
int putc | ( | int | c | ) |
Write a char to the serial port.
c | The char to write |
int puts | ( | const char * | str | ) |
Write a string to the serial port.
str | The string to write |
|
inherited |
Begin asynchronous reading using 8bit buffer.
The read operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_read() when no events are enabled. This function locks the deep sleep until any event has occurred.
buffer | The buffer where received data will be stored |
length | The buffer length in bytes |
callback | The event callback function |
event | The logical OR of RX events that should end operation |
char_match | The matching character |
|
inherited |
Begin asynchronous reading using 16bit buffer.
The read operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_read() when no events are enabled. This function locks the deep sleep until any event has occurred.
buffer | The buffer where received data will be stored |
length | The buffer length in bytes |
callback | The event callback function |
event | The logical OR of RX events that should end operation |
char_match | The matching character |
|
inherited |
Determine if there is a character available to read.
|
inherited |
Generate a break condition on the serial line.
|
inherited |
Generate a break condition on the serial line NOTE: Clear break needs to run at least one frame after set_break is called.
|
inherited |
Configure DMA usage suggestion for non-blocking RX transfers.
usage | The usage DMA hint for peripheral |
|
inherited |
Configure DMA usage suggestion for non-blocking TX transfers.
usage | The usage DMA hint for peripheral |
|
inherited |
Set the flow control type on the serial port.
type | the flow control type (Disabled, RTS, CTS, RTSCTS) |
flow1 | the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) |
flow2 | the second flow control pin (CTS for RTSCTS) |
|
inherited |
Set the flow control type on the serial port.
type | the flow control type (Disabled, RTS, CTS, RTSCTS) |
pinmap | reference to structure which holds static pinmap |
|
inherited |
Begin asynchronous write using 8bit buffer.
The write operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_write() when no events are enabled. This function locks the deep sleep until any event has occurred.
buffer | The buffer where received data will be stored |
length | The buffer length in bytes |
callback | The event callback function |
event | The logical OR of TX events that should end operation |
|
inherited |
Begin asynchronous write using 16bit buffer.
The write operation ends with any of the enabled events and invokes registered callback function (which can be NULL to not receive callback at all). Events that are not enabled by event argument are simply ignored. Operation has to be ended explicitly by calling abort_write() when no events are enabled. This function locks the deep sleep until any event has occurred.
buffer | The buffer where received data will be stored |
length | The buffer length in bytes |
callback | The event callback function |
event | The logical OR of TX events that should end operation |
|
inherited |
Determine if there is space available to write a character.