HardwareSerial

From chipKIT
Jump to: navigation, search
HardwareSerial
Quick Look
Hardware (External hardware)
Core HardwareSerial.h


The HardwareSerial class implements methods for communicating with Hardware UARTs (Universal Asynchronous Receiver / Transmitter )

Detailed Introduction

The HardwareSerial class is derived from class Stream. It's purpose is to provide methods for sending and receiving data over the available UARTs.

Full library usage

HardwareSerial

Constructors

HardwareSerial(p32_uart * uartP, int irq, int vec, int ipl, int spl, isrFunc isrHandler, int pinT, int pinR, ppsFunctionType ppsT, ppsFunctionType ppsR);

Create a new HardwareSerial object for PIC32MX1XX, PIC32MX2XX, PIC32MZXX, PIC32MX47X based boards


HardwareSerial(p32_uart * uartP, int irq, int vec, int ipl, int spl, isrFunc isrHandler);

Create a new HardwareSerial object for boards based on microcontrollers not listed above.


Constructor Parameters


Parameter Description
uartP Pointer to base register for UART
irq Base IRQ number for UART
vec Interrupt vector for the UART
ipl Interrupt priority level
spl Interrupt sub-priority level
isrHandler Interrupt Service Routine Handler
pinT Digital pin number of TX
pinR Digital pin number of RX
ppsT Peripheral Pin Select for UART TX
ppsR Peripheral Pin Select for UART RX


Public Functions


doSerialInt(void)

void	doSerialInt(void);

This function is called by the interrupt service routine for the UART being used by this object. It's purpose is to process receive interrupts and place the received characters into the receive buffer.

attachInterrupt(void (*callback)(int))

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

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

detachInterrupt()

void	detachInterrupt();

Detach the interrupt

enableAddressDetection (void)

        
void	enableAddressDetection (void);

Sets the bit in the UART status register that enables address detection

disableAddressDetection(void)

void	disableAddressDetection(void);

Clears the bit in the UART status register that enables address detection

begin(unsigned long baudRate)

		
void	begin(unsigned long baudRate);

Initialize the UART for use, setting the baud rate to the requested value, data size of 8-bits, and no parity.

begin(unsigned long baudRate, uint8_t address)

void	begin(unsigned long baudRate, uint8_t address);

Initialize the UART for use, setting the baud rate to the requested value, data size of 9-bits, and no parity and address detection mode

end()

void	end();

Disable the UART and UART interrupts.


Virtual Private Functions


available(void)

virtual in	available(void);

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

peek()

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.

read(void)

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.

flush(void)

virtual void	flush(void);

Empty the send buffer by waiting for the fifo to empty and the transmitter to become idle

purge(void)

virtual void	purge(void);

Empty the receive buffer by discarding any characters in the buffer.

write(uint8_t)

virtual	size_t	write(uint8_t);	

Wait until the transmitter is idle, and then transmit thespecified character.


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);

Conversion Operator


int()

		
operator  int();

Returns 1


External Links