Loading...
Searching...
No Matches
Interface

SPI interface for communicating with exeternal devices. More...

Data Structures

struct  SPI_Config
 SPI CR1 configuration struct. More...
 
struct  SPI_t
 Struct definition for SPI interface. Provides the interface for API consumers to interact with the SPI peripheral. More...
 

Enumerations

enum  SPI_Phase
 SPI clock phase enum. More...
 
enum  SPI_Polarity
 SPI clock polarity enum. More...
 
enum  SPI_MasterSelect
 SPI master selection enum. More...
 
enum  SPI_BaudRate
 SPI baud rate enum. More...
 
enum  SPI_DataFormat
 SPI data format enum. More...
 
enum  SPI_FrameFormat
 SPI frame format enum. More...
 

Functions

SPI_t SPI_init (SPI_TypeDef *, SPI_Config *)
 Initialiser for an SPI device interface.
 
uint16_t SPI_transmit (SPI_t *, uint16_t)
 Instance method to communicate a SPI transaction with slave device.
 
void SPI_updateConfig (SPI_t *, SPI_Config *)
 Update SPI peripheral configuration.
 

Detailed Description

SPI interface for communicating with exeternal devices.


Data Structure Documentation

◆ SPI_Config

struct SPI_Config

SPI CR1 configuration struct.

Describes the configuration of control register 1.

Definition at line 113 of file spi.h.

Data Fields
SPI_Phase CPHA: 1 SPI clock phase | (default SPI_CPHA_SECOND)
SPI_Polarity CPOL: 1 SPI clock polarity | (default SPI_CPOL1)
SPI_MasterSelect MSTR: 1 SPI master select | (default SPI_MASTER)
SPI_BaudRate BR: 3 SPI clock division | (default SPI_BR_PCLK8)
bool SPE: 1 SPI enable | (default false)
SPI_FrameFormat LSBFIRST: 1 SPI frame format | (default SPI_MSB_FIRST)
bool SSI: 1 SPI internal slave select | (default true)
bool SSM: 1 SPI software slave management | (default true )
bool RXONLY: 1 SPI receive only | (default false)
SPI_DataFormat DFF: 1 SPI data format | (default SPI_DFF8)
bool CRCNEXT: 1 SPI CRC transfer next | (default false)
bool CRCEN: 1 SPI CRC enable | (default false)
bool BIDIOE: 1 SPI bidirectional output | (default false)
bool BIDIMODE: 1 SPI bidirectional mode | (default true)

◆ SPI_t

struct SPI_t

Struct definition for SPI interface. Provides the interface for API consumers to interact with the SPI peripheral.

Definition at line 134 of file spi.h.

Data Fields
SPI_TypeDef * interface Pointer to SPI interface struct.
SPI_Config config Configuration parameters for the SPI peripheral.
void(*)(struct SPI *, uint16_t) send SPI send method.
See also
SPI_send
void(*)(struct SPI *, volatile uint16_t *) receive SPI receive method.
See also
SPI_receive
uint16_t(*)(struct SPI *, uint16_t) transmit SPI transmit method.
See also
SPI_transmit
void(*)(struct SPI *, SPI_Config *) updateConfig SPI configuration update method.
See also
SPI_updateConfig

Enumeration Type Documentation

◆ SPI_Phase

enum SPI_Phase

SPI clock phase enum.

Describes when to begin capturing data

Definition at line 53 of file spi.h.

◆ SPI_Polarity

SPI clock polarity enum.

Describes logic level of clock when idle

Definition at line 62 of file spi.h.

◆ SPI_MasterSelect

SPI master selection enum.

Describes operational mode of SPI

Definition at line 71 of file spi.h.

◆ SPI_BaudRate

SPI baud rate enum.

Describes clock division for SPI peripheral

Definition at line 80 of file spi.h.

◆ SPI_DataFormat

SPI data format enum.

Describes the format of data sent on the SPI data bus.

Definition at line 95 of file spi.h.

◆ SPI_FrameFormat

SPI frame format enum.

Describes the order in which to transmit bits per frame

Definition at line 104 of file spi.h.

Function Documentation

◆ SPI_init()

SPI_t SPI_init ( SPI_TypeDef * interface,
SPI_Config * config )

Initialiser for an SPI device interface.

Parameters
interfacePointer to the SPI_TypeDef struct representing the SPI interface.
configPointer to SPI_Config struct for initial configuration. This may be passed as NULL to initialise a default configuration.
Returns
spi Initialised SPI_t struct.

Definition at line 36 of file spi.c.

◆ SPI_transmit()

uint16_t SPI_transmit ( SPI_t * spi,
uint16_t data )

Instance method to communicate a SPI transaction with slave device.

Parameters
spiPointer to SPI_t struct.
dataData payload to be sent to slave device.
Return values
responseReturns the slave device response from the transaction.

Definition at line 96 of file spi.c.

◆ SPI_updateConfig()

void SPI_updateConfig ( SPI_t * spi,
SPI_Config * config )

Update SPI peripheral configuration.

Uses the provided configuration to update the SPI registers and resets the associated peripheral. As with initialisation, passing NULL will set the default config.

Parameters
spiPointer to SPI_t struct.
Returns
NULL.

Definition at line 166 of file spi.c.