LUFA Library  151115

Functions

static void SerialSPI_Disable (USART_t *const USART) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1)
 
static void SerialSPI_Init (USART_t *const USART, const uint8_t SPIOptions, const uint32_t BaudRate) ATTR_NON_NULL_PTR_ARG(1)
 
static uint8_t SerialSPI_ReceiveByte (USART_t *const USART) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1)
 
static void SerialSPI_SendByte (USART_t *const USART, const uint8_t DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1)
 
static uint8_t SerialSPI_TransferByte (USART_t *const USART, const uint8_t DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1)
 

SPI SCK Polarity Configuration Masks

#define USART_SPI_SCK_LEAD_RISING   0
 

SPI Sample Edge Configuration Masks

#define USART_SPI_SAMPLE_LEADING   0
 
#define USART_SPI_SAMPLE_TRAILING   (1 << 1)
 

SPI Data Ordering Configuration Masks

#define USART_SPI_ORDER_MSB_FIRST   0
 
#define USART_SPI_ORDER_LSB_FIRST   (1 << 2)
 

Detailed Description

Module Description

On-chip serial USART driver for the XMEGA AVR microcontrollers.

Note
This file should not be included directly. It is automatically included as needed by the ADC driver dispatch header located in LUFA/Drivers/Peripheral/SerialSPI.h.

Example Usage

The following snippet is an example of how this module may be used within a typical application.

// Initialize the Master SPI mode USART driver before first use, with 1Mbit baud
// Send several bytes, ignoring the returned data
SerialSPI_SendByte(&USARTD0, 0x01);
SerialSPI_SendByte(&USARTD0, 0x02);
SerialSPI_SendByte(&USARTD0, 0x03);
// Receive several bytes, sending a dummy 0x00 byte each time
uint8_t Byte1 = SerialSPI_ReceiveByte(&USARTD);
uint8_t Byte2 = SerialSPI_ReceiveByte(&USARTD);
uint8_t Byte3 = SerialSPI_ReceiveByte(&USARTD);
// Send a byte, and store the received byte from the same transaction
uint8_t ResponseByte = SerialSPI_TransferByte(&USARTD0, 0xDC);

Macro Definition Documentation

#define USART_SPI_ORDER_LSB_FIRST   (1 << 2)

SPI data order mask for SerialSPI_Init(). Indicates that data should be shifted out LSB first.

#define USART_SPI_ORDER_MSB_FIRST   0

SPI data order mask for SerialSPI_Init(). Indicates that data should be shifted out MSB first.

#define USART_SPI_SAMPLE_LEADING   0

SPI data sample mode mask for SerialSPI_Init(). Indicates that the data should sampled on the leading edge.

#define USART_SPI_SAMPLE_TRAILING   (1 << 1)

SPI data sample mode mask for SerialSPI_Init(). Indicates that the data should be sampled on the trailing edge.

#define USART_SPI_SCK_LEAD_RISING   0

SPI clock polarity mask for SerialSPI_Init(). Indicates that the SCK should lead on the rising edge.

Function Documentation

static void SerialSPI_Disable ( USART_t *const  USART)
inlinestatic

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

Parameters
[in,out]USARTPointer to the base of the USART peripheral within the device.
static void SerialSPI_Init ( USART_t *const  USART,
const uint8_t  SPIOptions,
const uint32_t  BaudRate 
)
inlinestatic

Initialize the USART module in Master SPI mode.

Parameters
[in,out]USARTPointer to the base of the USART peripheral within the device.
[in]SPIOptionsUSART SPI Options, a mask consisting of one of each of the USART_SPI_SCK_*, USART_SPI_SAMPLE_* and USART_SPI_ORDER_* masks.
[in]BaudRateSPI baud rate, in bits per second.
static uint8_t SerialSPI_ReceiveByte ( USART_t *const  USART)
inlinestatic

Sends a dummy byte through the USART SPI interface, blocking until the transfer is complete. The response byte from the attached SPI device is returned.

Parameters
[in,out]USARTPointer to the base of the USART peripheral within the device.
Returns
The response byte from the attached SPI device.
static void SerialSPI_SendByte ( USART_t *const  USART,
const uint8_t  DataByte 
)
inlinestatic

Sends a byte through the USART SPI interface, blocking until the transfer is complete. The response byte sent to from the attached SPI device is ignored.

Parameters
[in,out]USARTPointer to the base of the USART peripheral within the device.
[in]DataByteByte to send through the USART SPI interface.
static uint8_t SerialSPI_TransferByte ( USART_t *const  USART,
const uint8_t  DataByte 
)
inlinestatic

Sends and receives a byte through the USART SPI interface, blocking until the transfer is complete.

Parameters
[in,out]USARTPointer to the base of the USART peripheral within the device.
[in]DataByteByte to send through the USART SPI interface.
Returns
Response byte from the attached SPI device.