Driver for the Serial Peripheral Interface (SPI).
Provides functions for configuring and using the SPI.
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the SPI - Serial Peripheral Interface. | |
Macros | |
#define | BAUD_RATE_MASK 0x03 |
#define | DOUBLE_SPEED_MASK 0x04 |
#define | SPI_CLK2X_bm 0x01 /* Enable Double Speed bit mask. */ |
#define | SPI_CLK2X_bp 0 /* Enable Double Speed bit position. */ |
#define | SPI_CPHA_bm 0x04 /* SPI Clock phase bit 1 mask. */ |
#define | SPI_CPHA_bp 2 /* SPI Clock phase bit 1 position. */ |
#define | SPI_CPOL_bm 0x08 /* SPI Clock polarity bit 1 mask. */ |
#define | SPI_CPOL_bp 3 /* SPI Clock polarity bit 1 position. */ |
#define | SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */ |
#define | SPI_DORD_bp 5 /* Data Order Setting bit position. */ |
#define | SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */ |
#define | SPI_ENABLE_bp 6 /* Enable Module bit position. */ |
#define | SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */ |
#define | SPI_IF_bp 7 /* Interrupt Flag bit position. */ |
#define | SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */ |
#define | SPI_MASTER_bp 4 /* Master Operation Enable bit position. */ |
#define | SPI_MODE0 0 |
#define | SPI_MODE1 (SPI_CPHA) |
#define | SPI_MODE2 (SPI_CPOL) |
#define | SPI_MODE3 (SPI_CPOL | SPI_CPHA) |
#define | SPI_MODE_gm 0x0C /* SPI Mode group mask. */ |
#define | SPI_MODE_gp 2 /* SPI Mode group position. */ |
#define | SPI_PRESCALER0_bm (1 << 0) /* Prescaler bit 0 mask. */ |
#define | SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */ |
#define | SPI_PRESCALER1_bm (1 << 1) /* Prescaler bit 1 mask. */ |
#define | SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */ |
#define | SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */ |
#define | SPI_PRESCALER_gp 0 /* Prescaler group position. */ |
#define | SPI_SPIE_bm 0x80 /* Interrupt Enable bit mask. */ |
#define | SPI_SPIE_bp 7 /* Interrupt Enable bit position. */ |
#define | SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */ |
#define | SPI_WRCOL_bp 6 /* Write Collision bit position. */ |
Typedefs | |
typedef void(* | spi_int_callback_t )(void) |
Interrupt event callback function type. More... | |
typedef enum SPI_PRESCALER_enum | SPI_PRESCALER_t |
Enumerations | |
enum | SPI_PRESCALER_enum { SPI_PRESCALER_DIV4_gc = (0x00 << 0), SPI_PRESCALER_DIV16_gc = (0x01 << 0), SPI_PRESCALER_DIV64_gc = (0x02 << 0), SPI_PRESCALER_DIV128_gc = (0x03 << 0) } |
Functions | |
static void | spi_disable (volatile void *spi) |
Disables the SPI. More... | |
static void | spi_disable_interrupt (volatile void *spi) |
Disables the SPI's interrupt. More... | |
static void | spi_double_speed_disable (volatile void *spi) |
Disable SPI Double Speed. More... | |
static void | spi_double_speed_enable (volatile void *spi) |
Enable SPI Double Speed. More... | |
static void | spi_enable (volatile void *spi) |
Enables the SPI. More... | |
static void | spi_enable_interrupt (volatile void *spi) |
Enables the SPI in interrupt mode. More... | |
static void | spi_enable_master_mode (volatile void *spi) |
Activate SPI master mode of a SPI peripheral. More... | |
static void | spi_enable_slave_mode (volatile void *spi) |
Activate SPI slave mode of a SPI peripheral. More... | |
static uint8_t | spi_get (volatile void *spi) |
Get one data byte from SPI peripheral. More... | |
static bool | spi_is_enabled (volatile void *spi) |
Tests if the SPI is enabled. More... | |
static bool | spi_is_tx_ok (volatile void *spi) |
Tests if the SPI transfer is complete. More... | |
static bool | spi_is_wc_flag_set (volatile void *spi) |
Tests if the Write collision occurs during SPI transfer. More... | |
static void | spi_put (volatile void *spi, uint8_t data) |
Put one data byte to SPI peripheral. More... | |
int8_t | spi_set_baud_div (volatile void *spi, uint32_t baudrate, uint32_t clkper_hz) |
Calculates the SPI baudrate divider. More... | |
static void | spi_set_clock_mode (volatile void *spi, uint8_t mode) |
Set SPI clock mode. More... | |
static void | spi_set_clock_phase (volatile void *spi, bool polarity) |
Set Data Capture Phase. More... | |
static void | spi_set_clock_polarity (volatile void *spi, bool polarity) |
Set clock default state. More... | |
static void | spi_set_dord_lsb (volatile void *spi) |
Set SPI data order to LSB first. More... | |
static void | spi_set_dord_msb (volatile void *spi) |
Set SPI data order to MSB first. More... | |
void | spi_set_interrupt_callback (spi_int_callback_t callback) |
Set SPI interrupt callback function. More... | |
#define BAUD_RATE_MASK 0x03 |
#define DOUBLE_SPEED_MASK 0x04 |
#define SPI_CLK2X_bm 0x01 /* Enable Double Speed bit mask. */ |
Referenced by get_spi_divisor(), spi_double_speed_disable(), and spi_double_speed_enable().
#define SPI_CLK2X_bp 0 /* Enable Double Speed bit position. */ |
#define SPI_CPHA_bm 0x04 /* SPI Clock phase bit 1 mask. */ |
Referenced by spi_set_clock_phase().
#define SPI_CPHA_bp 2 /* SPI Clock phase bit 1 position. */ |
#define SPI_CPOL_bm 0x08 /* SPI Clock polarity bit 1 mask. */ |
Referenced by spi_set_clock_polarity().
#define SPI_CPOL_bp 3 /* SPI Clock polarity bit 1 position. */ |
#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */ |
Referenced by spi_set_dord_lsb(), and spi_set_dord_msb().
#define SPI_DORD_bp 5 /* Data Order Setting bit position. */ |
#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */ |
Referenced by spi_disable(), spi_enable(), and spi_is_enabled().
#define SPI_ENABLE_bp 6 /* Enable Module bit position. */ |
#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */ |
Referenced by spi_is_tx_ok().
#define SPI_IF_bp 7 /* Interrupt Flag bit position. */ |
#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */ |
Referenced by spi_enable_master_mode(), and spi_enable_slave_mode().
#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */ |
#define SPI_MODE0 0 |
#define SPI_MODE1 (SPI_CPHA) |
#define SPI_MODE2 (SPI_CPOL) |
#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */ |
Referenced by spi_master_setup_device(), and spi_set_clock_mode().
#define SPI_MODE_gp 2 /* SPI Mode group position. */ |
Referenced by spi_master_setup_device(), and spi_set_clock_mode().
#define SPI_PRESCALER0_bm (1 << 0) /* Prescaler bit 0 mask. */ |
#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */ |
#define SPI_PRESCALER1_bm (1 << 1) /* Prescaler bit 1 mask. */ |
#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */ |
#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */ |
Referenced by get_spi_divisor(), and spi_set_baud_div().
#define SPI_PRESCALER_gp 0 /* Prescaler group position. */ |
#define SPI_SPIE_bm 0x80 /* Interrupt Enable bit mask. */ |
Referenced by spi_disable_interrupt(), and spi_enable_interrupt().
#define SPI_SPIE_bp 7 /* Interrupt Enable bit position. */ |
#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */ |
Referenced by spi_is_wc_flag_set().
#define SPI_WRCOL_bp 6 /* Write Collision bit position. */ |
typedef void(* spi_int_callback_t)(void) |
Interrupt event callback function type.
The interrupt handler can be configured to do a function callback, the callback function must match the api_int_callback_t type.
typedef enum SPI_PRESCALER_enum SPI_PRESCALER_t |
enum SPI_PRESCALER_enum |
|
inlinestatic |
Disables the SPI.
Ensures that nothing is transferred while setting up buffers.
spi | Base address of the SPI instance. |
References SPI_ENABLE_bm.
Referenced by epd_spi_detach().
|
inlinestatic |
Disables the SPI's interrupt.
spi | Base address of the SPI instance. |
References SPI_SPIE_bm.
|
inlinestatic |
Disable SPI Double Speed.
spi | Base address of the SPI instance. |
References SPI_CLK2X_bm.
Referenced by spi_set_baud_div().
|
inlinestatic |
Enable SPI Double Speed.
spi | Base address of the SPI instance. |
References SPI_CLK2X_bm.
Referenced by spi_set_baud_div().
|
inlinestatic |
Enables the SPI.
spi | Base address of the SPI instance. |
References SPI_ENABLE_bm.
Referenced by at45dbx_spi_init(), epd_spi_init(), main(), run_baudrate_set_test(), and run_spi_transfer_test().
|
inlinestatic |
Enables the SPI in interrupt mode.
spi | Base address of the SPI instance. |
References SPI_SPIE_bm.
Referenced by spi_slave_init().
|
inlinestatic |
Activate SPI master mode of a SPI peripheral.
spi | Base address of the SPI instance. |
References SPI_MASTER_bm.
Referenced by run_spi_transfer_test(), and spi_master_init().
|
inlinestatic |
Activate SPI slave mode of a SPI peripheral.
spi | Base address of the SPI instance. |
References SPI_MASTER_bm.
Referenced by spi_slave_init().
|
inlinestatic |
Get one data byte from SPI peripheral.
spi | Base address of the SPI instance. |
Referenced by spi_interrupt_callback(), spi_read(), and spi_read_single().
|
inlinestatic |
Tests if the SPI is enabled.
spi | Base address of the SPI instance. |
1
if the SPI is enabled, otherwise 0
. References SPI_ENABLE_bm.
Referenced by at45dbx_spi_init().
|
inlinestatic |
Tests if the SPI transfer is complete.
spi | Base address of the SPI instance. |
1
if the SPI transfer is complete, otherwise 0
. References SPI_IF_bm.
Referenced by spi_is_rx_full(), spi_is_rx_ready(), spi_is_tx_empty(), spi_is_tx_ready(), spi_read(), and spi_write().
|
inlinestatic |
Tests if the Write collision occurs during SPI transfer.
spi | Base address of the SPI instance. |
1
if the SPI Write collision occurred, otherwise 0
. References SPI_WRCOL_bm.
|
inlinestatic |
Put one data byte to SPI peripheral.
spi | Base address of the SPI instance. |
data | The data byte to be loaded |
References data.
Referenced by spi_interrupt_callback(), spi_read(), spi_write(), and spi_write_single().
int8_t spi_set_baud_div | ( | volatile void * | spi, |
uint32_t | baudrate, | ||
uint32_t | clkper_hz | ||
) |
Calculates the SPI baudrate divider.
baudrate | The expected baudrate on the SPI. |
clkper_hz | SPI module input clock frequency (Peripheral clock, Hz). |
spi | The SPI module address |
>=0 | Success. |
<0 | Error. |
References Assert, spi_double_speed_disable(), spi_double_speed_enable(), SPI_PRESCALER_DIV128_gc, SPI_PRESCALER_DIV16_gc, SPI_PRESCALER_DIV4_gc, SPI_PRESCALER_DIV64_gc, and SPI_PRESCALER_gm.
Referenced by run_baudrate_set_test(), run_spi_transfer_test(), and spi_master_setup_device().
|
inlinestatic |
Set SPI clock mode.
spi | Base address of the SPI instance. |
mode | Value of the mode to be set. |
References SPI_MODE_gm, and SPI_MODE_gp.
Referenced by run_spi_transfer_test(), and spi_slave_init().
|
inlinestatic |
Set Data Capture Phase.
spi | Base address of the SPI instance. |
polarity | Set clock phase as logical one(high)/zero(low). |
References SPI_CPHA_bm.
|
inlinestatic |
Set clock default state.
spi | Base address of the SPI instance. |
polarity | Set clock polarity as logical one(high)/zero(low). |
References SPI_CPOL_bm.
|
inlinestatic |
Set SPI data order to LSB first.
spi | Base address of the SPI instance. |
References SPI_DORD_bm.
|
inlinestatic |
Set SPI data order to MSB first.
spi | Base address of the SPI instance. |
References SPI_DORD_bm.
void spi_set_interrupt_callback | ( | spi_int_callback_t | callback | ) |
Set SPI interrupt callback function.
This function allows the caller to set and change the interrupt callback function. Without setting a callback function the interrupt handler in the driver will only clear the interrupt flags.
callback | Reference to a callback function |
References spi_int_callback.
Referenced by spi_slave_init().