Mbed SDK for XRange SX1272 LoRa module

Dependents:   XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver

Embed: (wiki syntax)

« Back to documentation index

RawSerial Class Reference

RawSerial Class Reference

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>

Inherits mbed::SerialBase.

Public Member Functions

 RawSerial (PinName tx, PinName rx)
 Create a RawSerial port, connected to the specified transmit and receive pins.
int putc (int c)
 Write a char to the serial port.
int getc ()
 Read a char from the serial port.
int puts (const char *str)
 Write a string to the serial port.
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 (void(*fptr)(void), IrqType type=RxIrq)
 Attach a function to call whenever a serial interrupt is generated.
template<typename T >
void attach (T *tptr, void(T::*mptr)(void), IrqType type=RxIrq)
 Attach a member function to call whenever a serial interrupt is generated.
void send_break ()
 Generate a break condition on the serial line.
void set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC)
 Set the flow control type on the serial port.

Detailed Description

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:

 // Send a char to the PC

 #include "mbed.h"

 RawSerial pc(USBTX, USBRX);

 int main() {
     pc.putc('A');
 }

Definition at line 48 of file RawSerial.h.


Constructor & Destructor Documentation

RawSerial ( PinName  tx,
PinName  rx 
)

Create a RawSerial port, connected to the specified transmit and receive pins.

Parameters:
txTransmit pin
rxReceive pin
Note:
Either tx or rx may be specified as NC if unused

Definition at line 26 of file RawSerial.cpp.


Member Function Documentation

void attach ( T *  tptr,
void(T::*)(void)  mptr,
IrqType  type = RxIrq 
) [inherited]

Attach a member function to call whenever a serial interrupt is generated.

Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called
typeWhich serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)

Definition at line 99 of file SerialBase.h.

void attach ( void(*)(void)  fptr,
IrqType  type = RxIrq 
) [inherited]

Attach a function to call whenever a serial interrupt is generated.

Parameters:
fptrA pointer to a void function, or 0 to set as none
typeWhich serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)

Definition at line 46 of file SerialBase.cpp.

void baud ( int  baudrate ) [inherited]

Set the baud rate of the serial port.

Parameters:
baudrateThe baudrate of the serial port (default = 9600).

Definition at line 28 of file SerialBase.cpp.

void format ( int  bits = 8,
Parity  parity = SerialBase::None,
int  stop_bits = 1 
) [inherited]

Set the transmission format used by the serial port.

Parameters:
bitsThe number of bits in a word (5-8; default = 8)
parityThe parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
stopThe number of stop bits (1 or 2; default = 1)

Definition at line 33 of file SerialBase.cpp.

int getc (  )

Read a char from the serial port.

Returns:
The char read from the serial port

Definition at line 29 of file RawSerial.cpp.

int putc ( int  c )

Write a char to the serial port.

Parameters:
cThe char to write
Returns:
The written char or -1 if an error occured

Definition at line 33 of file RawSerial.cpp.

int puts ( const char *  str )

Write a string to the serial port.

Parameters:
strThe string to write
Returns:
0 if the write succeeds, EOF for error

Definition at line 37 of file RawSerial.cpp.

int readable (  ) [inherited]

Determine if there is a character available to read.

Returns:
1 if there is a character available to read, 0 otherwise

Definition at line 37 of file SerialBase.cpp.

void send_break (  ) [inherited]

Generate a break condition on the serial line.

Definition at line 69 of file SerialBase.cpp.

void set_flow_control ( Flow  type,
PinName  flow1 = NC,
PinName  flow2 = NC 
) [inherited]

Set the flow control type on the serial port.

Parameters:
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
flow1the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
flow2the second flow control pin (CTS for RTSCTS)

Definition at line 84 of file SerialBase.cpp.

int writeable (  ) [inherited]

Determine if there is space available to write a character.

Returns:
1 if there is space to write a character, 0 otherwise

Definition at line 42 of file SerialBase.cpp.