api / mbed / trunk / Serial
Serial
class Serial : public Stream
A serial port (UART) for communication with other serial devices
Example
// Print "Hello World" to the PC
#include "mbed.h"
Serial pc(USBTX, USBRX);
int main() {
pc.printf("Hello World\n");
}| Serial | A serial port (UART) for communication with other serial devices |
| Functions | |
| Serial | Create a Serial port, connected to the specified transmit and receive pins |
| baud | Set the baud rate of the serial port |
| format | Set the transmission format used by the Serial port |
| putc | Write a character |
| getc | Read a character |
| printf | Write a formated string |
| scanf | Read a formated string |
| readable | Determine if there is a character available to read |
| writeable | Determine if there is space available to write a character |
| attach | Attach a function to call whenever a serial interrupt is generated |
| attach | Attach a member function to call whenever a serial interrupt is generated |
format
void format( int bits = 8, Parity parity = Serial::None, int stop_bits = 1 )
Set the transmission format used by the Serial port
Variables
| bits | The number of bits in a word (5-8; default = 8) |
| parity | The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) |
| stop | The number of stop bits (1 or 2; default = 1) |
attach
void attach( void (*fptr)(void), IrqType type = RxIrq )
Attach a function to call whenever a serial interrupt is generated
Variables
| fptr | A pointer to a void function, or 0 to set as none |
| type | Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
attach
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
Variables
| tptr | pointer to the object to call the member function on |
| mptr | pointer to the member function to be called |
| type | Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
A serial port (UART) for communication with other serial devices
class Serial : public Stream
Create a Serial port, connected to the specified transmit and receive pins
Serial( PinName tx, PinName rx, const char * name = NULL )
Set the baud rate of the serial port
void baud( int baudrate )
Set the transmission format used by the Serial port
void format( int bits = 8, Parity parity = Serial::None, int stop_bits = 1 )
Write a character
int putc( int c )
Read a character
int getc()
Write a formated string
int printf( const char * format, ... )
Read a formated string
int scanf( const char * format, ... )
Determine if there is a character available to read
int readable()
Determine if there is space available to write a character
int writeable()
Attach a function to call whenever a serial interrupt is generated
void attach( void (*fptr)(void), IrqType type = RxIrq )
