From chipKIT
Jump to: navigation, search
Quick Look
Hardware USB Capable Boards (WF32, Fubarino)
Core HardwareSerial.h

The USBSerial class implements methods for communicating over USB using the Wiring Serial objects.

Detailed Introduction

The USBSerial class is derived from class Stream. It's purpose is to provide methods for sending and receiving data over the available USB ports when available. Boards must have USB capability such as the WF32 or Fubarino. Note that if USB is used for serial, the USB serial port gets instantiated as Serial and hardware serial port 0 gets instantiated as Serial0. If USBSSerial is not used then Hardware Serial (UART) gets instantiated as Serial.

Full library usage



USBSerial(ring_buffer *rx_buffer);

Create a new USBSerial object.



	#define	kMaxUSBxmitPkt	63

Public Functions


void	(*rxIntr)(int);

Interrupt callback routine.

attachInterrupt(void (*callback)(int))

void	attachInterrupt(void (*callback)(int));

Attach the interrupt. The callback parameter takes a funtion pointer.


void	detachInterrupt();

Detach the interrupt

begin(unsigned long baudRate)

void	begin(unsigned long baudRate);

Initialize the USB port for use. The baudRate parameted is required but the value is never used and therefore can be set to anything.


void	end();

Has no functionality implemented and therefore it does nothing.

Virtual Private Functions


virtual in	available(void);

Return the number of characters currently available in the receive buffer.


virtual int	peek();

This returns the next character in the receive buffer without removing it from the buffer, or -1 if no characters are in the buffer.


virtual int	read(void);

Return the next character from the receive buffer and remove it from the buffer, or -1 if no characters are available in the buffer.


virtual void	flush(void);

Empty the send buffer.


virtual	size_t	write(uint8_t);

Transmit the specified character.

write(const char *str)

virtual size_t	write(const char *str);

Transmits the characters from the specified pointer.

write(const uint8_t *buffer, size_t size)

virtual size_t	write(const uint8_t *buffer, size_t size);

Transmits the specified number of characters from the buffer pointer. The size parameter is used to specify the number of characters to transmit. If size is less than kMaxUSBxmitPkt a single packet will be transmitted. However if if (size < kMaxUSBxmitPkt is transmitted then multiple packets will be sent.

virtual unsigned long getBaudRate();

virtual unsigned long c;

Returns a baud rate.

Conversion Operator


operator  int();

Returns 1 if the com port is open and 0 if the com port is closed.

Print Class Functions

The following write functions are pulled in from the Print class.

write(const char *str)

size_t   write(const char *str);

write(const char *buffer, size_t size)

size_t   write(const char *buffer, size_t size);

External Links