Atmel Software Framework

XMEGA SPI master service.


This is the API for SPI master service on XMEGA.

Quick Start Guide

See Quick Start Guide for the SPI Master Driver

Data Structures

struct  spi_device
 Polled SPI device definition. More...

Defines

#define SPI_CPHA   (1 << 0)
 Clock phase.
#define SPI_CPOL   (1 << 1)
 Clock polarity.
#define SPI_MODE_0   0
 SPI mode 0.
#define SPI_MODE_1   (SPI_CPHA)
 SPI mode 1.
#define SPI_MODE_2   (SPI_CPOL)
 SPI mode 2.
#define SPI_MODE_3   (SPI_CPOL | SPI_CPHA)
 SPI mode 3.

Typedefs

typedef uint32_t board_spi_select_id_t
typedef uint8_t spi_flags_t

Functions

void spi_deselect_device (SPI_t *spi, struct spi_device *device)
 Deselect given device on the SPI bus.
void spi_disable (SPI_t *spi)
 Disables the SPI.
void spi_enable (SPI_t *spi)
 Enables the SPI.
bool spi_is_enabled (SPI_t *spi)
 Tests if the SPI is enabled.
static bool spi_is_rx_full (SPI_t *spi)
 Tests if the SPI contains a received character.
static bool spi_is_rx_ready (SPI_t *spi)
 Checks if all reception is ready.
static bool spi_is_tx_empty (SPI_t *spi)
 Checks if all transmissions are complete.
static bool spi_is_tx_ready (SPI_t *spi)
 Checks if all transmissions is ready.
void spi_master_init (SPI_t *spi)
 Initializes the SPI in master mode.
void spi_master_setup_device (SPI_t *spi, struct spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id)
 Setup a SPI device.
status_code_t spi_read_packet (SPI_t *spi, uint8_t *data, size_t len)
 Receive a sequence of bytes from a SPI device.
static void spi_read_single (SPI_t *spi, uint8_t *data)
 Receive one byte from a SPI device.
void spi_select_device (SPI_t *spi, struct spi_device *device)
 Select given device on the SPI bus.
status_code_t spi_write_packet (SPI_t *spi, const uint8_t *data, size_t len)
 Send a sequence of bytes to a SPI device.
static __always_inline void spi_write_single (SPI_t *spi, uint8_t data)
 Write one byte to a SPI device.

Spi Master Management Configuration



#define CONFIG_SPI_MASTER_DUMMY   0xFF
 Default Config Spi Master Dummy Field.

#define CONFIG_SPI_MASTER_DUMMY   0xFF

Default Config Spi Master Dummy Field.

Referenced by spi_read_packet().

#define SPI_CPHA   (1 << 0)

Clock phase.

#define SPI_CPOL   (1 << 1)

Clock polarity.

#define SPI_MODE_0   0

SPI mode 0.

#define SPI_MODE_1   (SPI_CPHA)

SPI mode 1.

#define SPI_MODE_2   (SPI_CPOL)

SPI mode 2.

#define SPI_MODE_3   (SPI_CPOL | SPI_CPHA)

SPI mode 3.


typedef uint32_t board_spi_select_id_t
typedef uint8_t spi_flags_t

void spi_deselect_device ( SPI_t *  spi,
struct spi_device device 
)

Deselect given device on the SPI bus.

Calls board chip deselect.

Parameters:
spi Base address of the SPI instance.
device SPI device
Precondition:
SPI device must be selected with spi_select_device() first

References spi_device::id, and ioport_set_pin_high().

Referenced by at25dfx_spi_deselect_device(), pal_trx_aes_wrrd(), pal_trx_frame_read(), pal_trx_frame_write(), pal_trx_reg_read(), pal_trx_reg_write(), pal_trx_sram_read(), pal_trx_sram_write(), ssd1306_write_command(), ssd1306_write_data(), st7565r_write_command(), and st7565r_write_data().

void spi_disable ( SPI_t *  spi  ) 

Disables the SPI.

Ensures that nothing is transferred while setting up buffers.

Parameters:
spi Base address of the SPI instance.
Warning:
This may cause data loss if used on a slave SPI.
void spi_enable ( SPI_t *  spi  ) 

Enables the SPI.

Parameters:
spi Base address of the SPI instance.

Referenced by at25dfx_spi_init(), at45dbx_spi_init(), ili9341_interface_init(), pal_spi_init(), run_baudrate_set_test(), and ssd1306_interface_init().

bool spi_is_enabled ( SPI_t *  spi  ) 

Tests if the SPI is enabled.

Parameters:
spi Base address of the SPI instance.
Returns:
1 if the SPI is enabled, otherwise 0.

Referenced by at45dbx_spi_init().

static bool spi_is_rx_full ( SPI_t *  spi  )  [inline, static]

Tests if the SPI contains a received character.

Parameters:
spi Base address of the SPI instance.
Returns:
1 if the SPI Receive Holding Register is full, otherwise 0.

References spi_is_tx_ok().

Referenced by hx8347a_read_byte(), ili9341_read_byte(), spi_read_packet(), and spi_write_packet().

static bool spi_is_rx_ready ( SPI_t *  spi  )  [inline, static]

Checks if all reception is ready.

Parameters:
spi Base address of the SPI instance.
Returns:
1 if the SPI Receiver is ready, otherwise 0.

References spi_is_tx_ok().

static bool spi_is_tx_empty ( SPI_t *  spi  )  [inline, static]

Checks if all transmissions are complete.

Parameters:
spi Base address of the SPI instance.
Returns:
Status.
Return values:
1 All transmissions complete.
0 Transmissions not complete.

References spi_is_tx_ok().

Referenced by ili9341_wait_for_send_done(), pal_trx_aes_wrrd(), pal_trx_sram_read(), and pal_trx_sram_write().

static bool spi_is_tx_ready ( SPI_t *  spi  )  [inline, static]

Checks if all transmissions is ready.

Parameters:
spi Base address of the SPI instance.
Returns:
Status.
Return values:
1 All transmissions complete.
0 Transmissions not complete.

References spi_is_tx_ok().

void spi_master_init ( SPI_t *  spi  ) 
void spi_master_setup_device ( SPI_t *  spi,
struct spi_device device,
spi_flags_t  flags,
unsigned long  baud_rate,
board_spi_select_id_t  sel_id 
)

Setup a SPI device.

The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.

Parameters:
spi Base address of the SPI instance.
device Pointer to SPI device struct that should be initialized.
flags SPI configuration flags. Common flags for all implementations are the SPI modes SPI_MODE_0 ... SPI_MODE_3.
baud_rate Baud rate for communication with slave device in Hz.
sel_id Board specific select id
status_code_t spi_read_packet ( SPI_t *  spi,
uint8_t *  data,
size_t  len 
)

Receive a sequence of bytes from a SPI device.

All bytes sent out on SPI bus are sent as value 0.

Parameters:
spi Base address of the SPI instance.
data data buffer to read
len Length of data
Precondition:
SPI device must be selected with spi_select_device() first

References CONFIG_SPI_MASTER_DUMMY, spi_is_rx_full(), spi_read_single(), and spi_write_single().

Referenced by at25dfx_spi_read_byte(), at25dfx_spi_read_packet(), pal_trx_aes_wrrd(), pal_trx_frame_read(), pal_trx_reg_read(), and pal_trx_sram_read().

static void spi_read_single ( SPI_t *  spi,
uint8_t *  data 
) [inline, static]

Receive one byte from a SPI device.

Parameters:
spi Base address of the SPI instance.
data Pointer to the data byte where to store the received data.

References spi_get().

Referenced by hx8347a_read_byte(), ili9341_read_byte(), pal_trx_aes_wrrd(), and spi_read_packet().

void spi_select_device ( SPI_t *  spi,
struct spi_device device 
)

Select given device on the SPI bus.

Set device specific setting and calls board chip select.

Parameters:
spi Base address of the SPI instance.
device SPI device

References spi_device::id, and ioport_set_pin_low().

Referenced by at25dfx_spi_select_device(), pal_trx_aes_wrrd(), pal_trx_frame_read(), pal_trx_frame_write(), pal_trx_reg_read(), pal_trx_reg_write(), pal_trx_sram_read(), pal_trx_sram_write(), ssd1306_write_command(), ssd1306_write_data(), st7565r_write_command(), and st7565r_write_data().

status_code_t spi_write_packet ( SPI_t *  spi,
const uint8_t *  data,
size_t  len 
)

Send a sequence of bytes to a SPI device.

Received bytes on the SPI bus are discarded.

Parameters:
spi Base address of the SPI instance.
data data buffer to write
len Length of data
Precondition:
SPI device must be selected with spi_select_device() first

References spi_is_rx_full(), and spi_write_single().

Referenced by at25dfx_spi_write_byte(), at25dfx_spi_write_packet(), hx8347a_write_packet(), pal_trx_aes_wrrd(), pal_trx_frame_read(), pal_trx_frame_write(), pal_trx_reg_read(), pal_trx_reg_write(), pal_trx_sram_read(), and pal_trx_sram_write().

static __always_inline void spi_write_single ( SPI_t *  spi,
uint8_t  data 
) [static]

Write one byte to a SPI device.

Parameters:
spi Base address of the SPI instance.
data The data byte to be loaded

References spi_put().

Referenced by hx8347a_read_byte(), hx8347a_send_byte(), ili9341_interface_init(), ili9341_read_byte(), ili9341_send_byte(), spi_read_packet(), spi_write_packet(), ssd1306_write_command(), ssd1306_write_data(), st7565r_write_command(), and st7565r_write_data().

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines