AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Functions
USART0 Namespace Reference

This namespace bundles a high-level buffered interface to the USART0 hardware. It provides logical cohesion and prevents namespace collisions. More...

Functions

void start (unsigned long baudRate, UsartSerialConfiguration config=kSerial_8N1)
 Initialize USART0 for buffered, asynchronous serial communications using interrupts. More...
 
void stop ()
 Stops buffered serial communications using interrupts on USART0. More...
 
size_t write (char c)
 Write a single byte to the transmit buffer. More...
 
size_t write (const char *c)
 Write a null-terminated string to the transmit buffer. More...
 
size_t write (const char *c, size_t n)
 Write a character array of given size to the transmit buffer. More...
 
size_t write (const uint8_t *c, size_t n)
 Write a byte array of given size to the transmit buffer. More...
 
void flush ()
 Flush transmit buffer. More...
 
int peek ()
 Examine the next character in the receive buffer without removing it from the buffer. More...
 
int read ()
 Return the next character in the receive buffer, removing it from the buffer. More...
 
bool available ()
 Determine if there is data in the receive buffer.. More...
 

Detailed Description

This namespace bundles a high-level buffered interface to the USART0 hardware. It provides logical cohesion and prevents namespace collisions.

Function Documentation

§ available()

bool USART0::available ( )

Determine if there is data in the receive buffer..

Returns
if the receive buffer contains data, it returns TRUE; if the receive buffer is empty, it returns FALSE;

§ flush()

void USART0::flush ( )

Flush transmit buffer.

This function blocks until the transmit buffer is empty and the last byte has been transmitted by USART0. flush() doesn't actually do anything to make the transmit happen; it simply waits for the transmission to complete.

§ peek()

int USART0::peek ( )

Examine the next character in the receive buffer without removing it from the buffer.

Returns
if there is a value in the receive buffer, it returns the value (a number between 0 and 255); if the receive buffer is empty, it returns -1;

§ read()

int USART0::read ( )

Return the next character in the receive buffer, removing it from the buffer.

Returns
if there is a value in the receive buffer, it returns the value (a number between 0 and 255) and removes the value from the receive buffer; if the receive buffer is empty, it returns -1;

§ start()

void USART0::start ( unsigned long  baudRate,
UsartSerialConfiguration  config = kSerial_8N1 
)

Initialize USART0 for buffered, asynchronous serial communications using interrupts.

You must call this function before using any of the other USART0 functions.

  • baudRate the baud rate for the communications, usually one of the following values: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200 (although other values below can be specified).
  • config sets the configuration in term of data bits, parity, and stop bits. If omitted, the default is 8 data bits, no parity, and 1 stop bit.

§ stop()

void USART0::stop ( )

Stops buffered serial communications using interrupts on USART0.

After calling this function, Arduino pins 0 and 1 are released and available for use as ordinary digital pins.

If you want to use USART0 again for buffered, asynchronous serial communications, you must again call start().

§ write() [1/4]

size_t USART0::write ( char  c)

Write a single byte to the transmit buffer.

This function attempts to queue the data into the transmit buffer. If there is room in the transmit buffer, the function returns immediately. If not, the function blocks waiting for room to become available in the transmit buffer.

The data is transmitted asynchronously via USART0-related interrupts.

  • c the char (byte) to write into the transmit buffer
Returns
the number of bytes written into the output buffer.

§ write() [2/4]

size_t USART0::write ( const char *  c)

Write a null-terminated string to the transmit buffer.

This function attempts to queue the data into the transmit buffer. If there is room in the transmit buffer, the function returns immediately. If not, the function blocks waiting for room to become available in the transmit buffer.

The data is transmitted asynchronously via USART0-related interrupts.

  • c the null-terminated string to write into the transmit buffer.
Returns
the number of bytes written into the output buffer.

§ write() [3/4]

size_t USART0::write ( const char *  c,
size_t  n 
)

Write a character array of given size to the transmit buffer.

This function attempts to queue the data into the transmit buffer. If there is room in the transmit buffer, the function returns immediately. If not, the function blocks waiting for room to become available in the transmit buffer.

The data is transmitted asynchronously via USART0-related interrupts

  • c the character array to write into the transmit buffer.
  • n the number of elements from the array to write into the transmit buffer.
Returns
the number of characters written into the output buffer.

§ write() [4/4]

size_t USART0::write ( const uint8_t *  c,
size_t  n 
)

Write a byte array of given size to the transmit buffer.

This function attempts to queue the data into the transmit buffer. If there is room in the transmit buffer, the function returns immediately. If not, the function blocks waiting for room to become available in the transmit buffer.

The data is transmitted asynchronously via USART0-related interrupts

  • c the byte array to write into the transmit buffer.
  • n the number of elements from the array to write into the transmit buffer.
Returns
the number of bytes written into the output buffer.