Defines | Functions

Serial USART Driver - LUFA/Drivers/Peripheral/Serial.h
[On-chip Peripheral Drivers]

Defines

#define SERIAL_UBBRVAL(baud)   ((((F_CPU / 16) + (baud / 2)) / (baud)) - 1)
#define SERIAL_2X_UBBRVAL(baud)   ((((F_CPU / 8) + (baud / 2)) / (baud)) - 1)

Functions

void Serial_TxString_P (const char *FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1)
void Serial_TxString (const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1)
static void Serial_Init (const uint32_t BaudRate, const bool DoubleSpeed)
static void Serial_ShutDown (void)
static bool Serial_IsCharReceived (void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
static void Serial_TxByte (const char DataByte) ATTR_ALWAYS_INLINE
static char Serial_RxByte (void) ATTR_ALWAYS_INLINE

Detailed Description

Module Source Dependencies

The following files must be built with any user project that uses this module:

Description

Hardware serial USART driver. This module provides an easy to use driver for the setup of and transfer of data over the AVR's USART port.


Define Documentation

#define SERIAL_2X_UBBRVAL (   baud )    ((((F_CPU / 8) + (baud / 2)) / (baud)) - 1)

Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is set.

#define SERIAL_UBBRVAL (   baud )    ((((F_CPU / 16) + (baud / 2)) / (baud)) - 1)

Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is not set.


Function Documentation

static void Serial_Init ( const uint32_t  BaudRate,
const bool  DoubleSpeed 
) [inline, static]

Initializes the USART, ready for serial data transmission and reception. This initializes the interface to standard 8-bit, no parity, 1 stop bit settings suitable for most applications.

Parameters:
[in]BaudRateSerial baud rate, in bits per second.
[in]DoubleSpeedEnables double speed mode when set, halving the sample time to double the baud rate.
static bool Serial_IsCharReceived ( void   ) [inline, static]

Indicates whether a character has been received through the USART.

Returns:
Boolean true if a character has been received, false otherwise.
static char Serial_RxByte ( void   ) [inline, static]

Receives a byte from the USART. This function blocks until a byte has been received; if non-blocking behaviour is required, test for a received character beforehand with Serial_IsCharReceived().

Returns:
Byte received from the USART.
static void Serial_ShutDown ( void   ) [inline, static]

Turns off the USART driver, disabling and returning used hardware to their default configuration.

static void Serial_TxByte ( const char  DataByte ) [inline, static]

Transmits a given byte through the USART.

Parameters:
[in]DataByteByte to transmit through the USART.
void Serial_TxString ( const char *  StringPtr )

Transmits a given string located in SRAM memory through the USART.

Parameters:
[in]StringPtrPointer to a string located in SRAM space.
void Serial_TxString_P ( const char *  FlashStringPtr )

Transmits a given string located in program space (FLASH) through the USART.

Parameters:
[in]FlashStringPtrPointer to a string located in program space.