Mbed OS Reference
Loading...
Searching...
No Matches
SPI Configuration Functions

Modules

 SPI hal tests
 The SPI HAL tests ensure driver conformance to defined behaviour.
 

Functions

void spi_get_capabilities (PinName ssel, bool slave, spi_capabilities_t *cap)
 Fills the given spi_capabilities_t structure with the capabilities of the given peripheral. More...
 
void spi_init_direct (spi_t *obj, const spi_pinmap_t *pinmap)
 Initialize the SPI peripheral. More...
 
void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
 Initialize the SPI peripheral. More...
 
void spi_free (spi_t *obj)
 Release a SPI object. More...
 
void spi_format (spi_t *obj, int bits, int mode, int slave)
 Configure the SPI format. More...
 
void spi_frequency (spi_t *obj, int hz)
 Set the SPI baud rate. More...
 

Detailed Description

Defined behavior

Undefined behavior

Function Documentation

◆ spi_get_capabilities()

void spi_get_capabilities ( PinName  ssel,
bool  slave,
spi_capabilities_t cap 
)

Fills the given spi_capabilities_t structure with the capabilities of the given peripheral.

◆ spi_init_direct()

void spi_init_direct ( spi_t obj,
const spi_pinmap_t pinmap 
)

Initialize the SPI peripheral.

Configures the pins used by SPI and enables the peripheral.

After this function is called by the driver layer, spi_format() and spi_frequency() will be called before the SPI bus is used.

Parameters
[out]objThe SPI object to initialize
[in]pinmappointer to structure which holds static pinmap

◆ spi_init()

void spi_init ( spi_t obj,
PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  ssel 
)

Initialize the SPI peripheral.

Configures the pins used by SPI and enables the peripheral

After this function is called by the driver layer, spi_format() and spi_frequency() will be called before the SPI bus is used.

Parameters
[out]objThe SPI object to initialize
[in]mosiThe pin to use for MOSI
[in]misoThe pin to use for MISO
[in]sclkThe pin to use for SCLK
[in]sselThe pin to use for SSEL

◆ spi_free()

void spi_free ( spi_t obj)

Release a SPI object.

Return the pins owned by the SPI object to their reset state Disable the SPI peripheral Disable the SPI clock

Parameters
[in]objThe SPI object to deinitialize

◆ spi_format()

void spi_format ( spi_t obj,
int  bits,
int  mode,
int  slave 
)

Configure the SPI format.

Set the number of bits per frame, configure clock polarity and phase, shift order and master/slave mode. The default bit order is MSB.

Parameters
[in,out]objThe SPI object to configure
[in]bitsThe number of bits per frame
[in]modeThe SPI mode (clock polarity, phase, and shift direction)
[in]slaveZero for master mode or non-zero for slave mode

◆ spi_frequency()

void spi_frequency ( spi_t obj,
int  hz 
)

Set the SPI baud rate.

Actual frequency may differ from the desired frequency due to available dividers and bus clock Configures the SPI peripheral's baud rate

Parameters
[in,out]objThe SPI object to configure
[in]hzThe baud rate in Hz