Atmel Software Framework

spi.h File Reference
#include "compiler.h"

Data Structures

struct  spi_options_t
 Option structure for SPI channels. More...
 

Macros

#define SPI_MODE_0   0
 SPI Mode 0. More...
 
#define SPI_MODE_1   1
 SPI Mode 1. More...
 
#define SPI_MODE_2   2
 SPI Mode 2. More...
 
#define SPI_MODE_3   3
 SPI Mode 3. More...
 
#define SPI_TIMEOUT   15000
 Time-out value (number of attempts). More...
 

Enumerations

enum  spi_status_t {
  SPI_ERROR = -1,
  SPI_OK = 0,
  SPI_ERROR_TIMEOUT = 1,
  SPI_ERROR_ARGUMENT,
  SPI_ERROR_OVERRUN,
  SPI_ERROR_MODE_FAULT,
  SPI_ERROR_OVERRUN_AND_MODE_FAULT
}
 Status codes used by the SPI driver. More...
 

Functions

int16_t getBaudDiv (const uint32_t baudrate, uint32_t pb_hz)
 Calculates the baudrate divider. More...
 
void spi_disable (volatile avr32_spi_t *spi)
 Disables the SPI. More...
 
static void spi_disable_chipselect_decoding (volatile avr32_spi_t *spi)
 Disable Chip Select Decoding of the SPI. More...
 
static void spi_disable_loopback (volatile avr32_spi_t *spi)
 Disable Loopback of the SPI. More...
 
static void spi_disable_modfault (volatile avr32_spi_t *spi)
 Disable Modfault of the SPI. More...
 
static void spi_disable_variable_chipselect (volatile avr32_spi_t *spi)
 Disable Variable Chip Select of the SPI. More...
 
void spi_enable (volatile avr32_spi_t *spi)
 Enables the SPI. More...
 
static void spi_enable_active_mode (volatile avr32_spi_t *spi, uint8_t chip_select)
 Enable Active mode of a Chip Selects of the SPI. More...
 
static void spi_enable_chipselect_decoding (volatile avr32_spi_t *spi)
 Enable Chip Select Decoding of the SPI. More...
 
static void spi_enable_loopback (volatile avr32_spi_t *spi)
 Enable Loopback of the SPI. More...
 
static void spi_enable_modfault (volatile avr32_spi_t *spi)
 Enable Modfault of the SPI. More...
 
static void spi_enable_variable_chipselect (volatile avr32_spi_t *spi)
 Enable Variable Chip Select of the SPI. More...
 
static uint16_t spi_get (volatile avr32_spi_t *spi)
 Get one data to a SPI peripheral. More...
 
uint8_t spi_getStatus (volatile avr32_spi_t *spi)
 Gets status information from the SPI. More...
 
spi_status_t spi_initMaster (volatile avr32_spi_t *spi, const spi_options_t *options)
 Initializes the SPI in master mode. More...
 
spi_status_t spi_initSlave (volatile avr32_spi_t *spi, uint8_t bits, uint8_t spi_mode)
 Initializes the SPI in slave mode. More...
 
spi_status_t spi_initTest (volatile avr32_spi_t *spi)
 Sets up the SPI in a test mode where the transmitter is connected to the receiver (local loopback). More...
 
bool spi_is_enabled (volatile avr32_spi_t *spi)
 Tests if the SPI is enabled. More...
 
static bool spi_is_rx_full (volatile avr32_spi_t *spi)
 Check if the SPI contains a received character. More...
 
static bool spi_is_rx_ready (volatile avr32_spi_t *spi)
 Checks if all reception is ready. More...
 
static bool spi_is_tx_empty (volatile avr32_spi_t *spi)
 Checks if all transmissions are complete. More...
 
static bool spi_is_tx_ready (volatile avr32_spi_t *spi)
 Checks if all transmissions is ready. More...
 
static void spi_put (volatile avr32_spi_t *spi, uint16_t data)
 Put one data to a SPI peripheral. More...
 
spi_status_t spi_read (volatile avr32_spi_t *spi, uint16_t *data)
 Reads one data word in master mode or in slave mode. More...
 
uint8_t spi_readRegisterFullCheck (volatile avr32_spi_t *spi)
 Checks if there is data in the receive register. More...
 
static void spi_reset (volatile avr32_spi_t *spi)
 Reset the SPI. More...
 
spi_status_t spi_selectChip (volatile avr32_spi_t *spi, uint8_t chip)
 Selects slave chip. More...
 
spi_status_t spi_selectionMode (volatile avr32_spi_t *spi, uint8_t variable_ps, uint8_t pcs_decode, uint8_t delay)
 Sets up how and when the slave chips are selected (master mode only). More...
 
static void spi_set_baudrate_register (volatile avr32_spi_t *spi, uint8_t chip_select, uint8_t scbr)
 Set baudrate for a Chip Selects of the SPI. More...
 
static void spi_set_bits_per_transfer (volatile avr32_spi_t *spi, uint8_t chip_select, uint8_t len)
 Set Delay Before SPCK on a Chip Selects of the SPI. More...
 
static void spi_set_chipselect (volatile avr32_spi_t *spi, uint8_t chip_select)
 Set Chip Select of the SPI. More...
 
static void spi_set_chipselect_delay_bct (volatile avr32_spi_t *spi, uint8_t chip_select, uint8_t delay)
 Set Delay Between Consecutive Transfer on a Chip Selects of the SPI. More...
 
static void spi_set_chipselect_delay_bs (volatile avr32_spi_t *spi, uint8_t chip_select, uint8_t delay)
 Set Delay Before SPCK on a Chip Selects of the SPI. More...
 
static void spi_set_delay (volatile avr32_spi_t *spi, uint8_t delay)
 Set Delay Between Chip Selects of the SPI. More...
 
static void spi_set_master_mode (volatile avr32_spi_t *spi)
 Set Master Mode of the SPI. More...
 
static void spi_set_mode (volatile avr32_spi_t *spi, uint8_t chip_select, uint8_t flags)
 Set Mode of the SPI. More...
 
static void spi_set_slave_mode (volatile avr32_spi_t *spi)
 Set Slave Mode of the SPI. More...
 
spi_status_t spi_setupChipReg (volatile avr32_spi_t *spi, const spi_options_t *options, uint32_t pb_hz)
 Sets options for a specific slave chip. More...
 
spi_status_t spi_unselectChip (volatile avr32_spi_t *spi, uint8_t chip)
 Unselects slave chip. More...
 
spi_status_t spi_variableSlaveWrite (volatile avr32_spi_t *spi, uint16_t data, uint8_t pcs, uint8_t lastxfer)
 Selects a slave in master variable peripheral select mode and writes one data word to it. More...
 
spi_status_t spi_write (volatile avr32_spi_t *spi, uint16_t data)
 Writes one data word in master fixed peripheral select mode or in slave mode. More...
 
uint8_t spi_writeEndCheck (volatile avr32_spi_t *spi)
 Checks if all transmissions are complete. More...
 
uint8_t spi_writeRegisterEmptyCheck (volatile avr32_spi_t *spi)
 Checks if there is no data in the transmit register. More...