AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Functions
USART2Minimal.h File Reference

This file provides functions that provide a minimalist interface to USART2 available on the Arduino Mega (ATmega2560). More...

Go to the source code of this file.

Functions

void initUSART2 (unsigned long baudRate)
 Initialize USART2 for serial receive and transmit. More...
 
void transmitUSART2 (unsigned char data)
 Transmit a single byte on USART2. More...
 
void transmitUSART2 (const char *data)
 Transmit a null-terminated string on USART2. More...
 
unsigned char receiveUSART2 ()
 Receive a byte on USART2. More...
 
void releaseUSART2 ()
 Release USART2, making pins 0 and 1 again available for non-USART use. More...
 

Detailed Description

This file provides functions that provide a minimalist interface to USART2 available on the Arduino Mega (ATmega2560).

These functions are minimalist in the following sense:

To use these functions, include USART2Minimal.h in your source code and link against USART2Minimal.cpp.

For a more advanced USART2 interface, consider using either the USART2 or Serial2 interfaces. Both of these are available by including USART2.h instead of USART2Minimal.h.

Function Documentation

§ initUSART2()

void initUSART2 ( unsigned long  baudRate)

Initialize USART2 for serial receive and transmit.

USART2 is tied to pins 16 (TX) and 17 (RX) on Arduino Mega (ATmega2560 pins PH1, PH0).

Communications are configured for 8 data bits, no parity, and 1 stop bit.

  • 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).
Note
This function is only available on Arduino Mega (ATmega2560).

§ receiveUSART2()

unsigned char receiveUSART2 ( )

Receive a byte on USART2.

You must first initialize USART2 by calling initUSART2().

This function blocks until the USART receives a byte.

Returns
the byte received.
Note
This function is only available on Arduino Mega (ATmega2560).

§ releaseUSART2()

void releaseUSART2 ( )

Release USART2, making pins 0 and 1 again available for non-USART use.

After calling this function, you cannot read or write to the USART unless you first call initUSART2().

Note
This function is only available on Arduino Mega (ATmega2560).

§ transmitUSART2() [1/2]

void transmitUSART2 ( unsigned char  data)

Transmit a single byte on USART2.

You must first initialize USART2 by calling initUSART2().

This function blocks until the USART becomes available and the byte can be transmitted.

  • data the byte to be transmitted.
Note
This function is only available on Arduino Mega (ATmega2560).

§ transmitUSART2() [2/2]

void transmitUSART2 ( const char *  data)

Transmit a null-terminated string on USART2.

You must first initialize USART2 by calling initUSART2().

This function blocks until the USART becomes available and all the bytes can be transmitted.

  • data the null-terminated string to be transmitted.
Note
This function is only available on Arduino Mega (ATmega2560).