Mistake on this page?
Report an issue in GitHub or email us
SPI Configuration Functions


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

Function Documentation

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.

[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
void spi_free ( spi_t obj)

Release a SPI object.

TODO: spi_free is currently unimplemented This will require reference counting at the C++ level to be safe

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

[in]objThe SPI object to deinitialize
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

[in,out]objThe SPI object to configure
[in]hzThe baud rate in Hz
void spi_init ( spi_t obj,
PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  ssel 

Initialize the SPI peripheral.

Configures the pins used by SPI, sets a default format and frequency, and enables the peripheral

[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
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.