api / mbed / trunk / SerialHalfDuplex

SerialHalfDuplex

class SerialHalfDuplex : public Serial

A serial port (UART) for communication with other devices, with a single shared transmit and receive line.

If the device both transmits and receives, then both (separate) pins need to be defined, and tied together externally.

Example

// Send a byte as a master, and receive a byte as a slave

#include "mbed.h"

SerialHalfDuplex master(p9, p10);

int main() {
    int outbyte = master.putc(0x55);
    int retbyte = master.getc();
    printf("Wrote: %02X  Read: %02X\n", outbyte, retbyte);
}
SerialHalfDuplexA serial port (UART) for communication with other devices, with a single shared transmit and receive line.
Functions
SerialHalfDuplexCreate a half-duplex serial port, connected to the specified transmit and receive pins.
baudSet the baud rate of the serial port
format
putcWrite a character
getcRead a character
printfWrite a formated string
scanfRead a formated string
readableDetermine if there is a character available to read
writeableDetermine if there is space available to write a character
attachAttach a function to call whenever a serial interrupt is generated
attachAttach a member function to call whenever a serial interrupt is generated

Functions

SerialHalfDuplex

SerialHalfDuplex(PinName tx,  
PinName rx,  
const char *name =  NULL)

Create a half-duplex serial port, connected to the specified transmit and receive pins.

Variables

txTransmit pin
rxReceive pin

Note: Either tx or rx may be specified as NC if unused

baud

void baud(int baudrate)

Set the baud rate of the serial port

Variables

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

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)

putc

int putc(int c)

Write a character

Variables

cThe character to write to the serial port

getc

int getc()

Read a character

Variables

returnsThe character read from the serial port

printf

int printf(const char *format,
 ...)

Write a formated string

Variables

formatA printf-style format string, followed by the variables to use in formating the string.

scanf

int scanf(const char *format,
 ...)

Read a formated string

Variables

formatA scanf-style format string, followed by the pointers to variables to store the results.

readable

int readable()

Determine if there is a character available to read

Variables

returns1 if there is a character available to read, else 0

writeable

int writeable()

Determine if there is space available to write a character

Variables

returns1 if there is space to write a character, else 0

attach

void attach(void (*fptr)(void))

Attach a function to call whenever a serial interrupt is generated

Variables

fptrA pointer to a void function, or 0 to set as none

attach

template<typename T> void attach(*tptr,
void (T::*mptr)(void))

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

Variables

tptrpointer to the object to call the member function on
mptrpointer to the member function to be called
class SerialHalfDuplex : public Serial
A serial port (UART) for communication with other devices, with a single shared transmit and receive line.
SerialHalfDuplex(PinName tx,  
PinName rx,  
const char *name =  NULL)
Create a half-duplex serial port, connected to the specified transmit and receive pins.
void baud(int baudrate)
Set the baud rate of the serial port
void format(int bits =  8,
Parity parity =  Serial::None,
int stop_bits =  1)
int putc(int c)
Write a character
int getc()
Read a character
int printf(const char *format,
 ...)
Write a formated string
int scanf(const char *format,
 ...)
Read a formated string
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))
Attach a function to call whenever a serial interrupt is generated