SPI
The SPI driver is contained within its header spi.h in Lib and its board-specific
source spi.c in Src. The driver allows for new code to easily read and write to an
SPI interface on the board.
Types
-
enum SpiPeriph
The SPI interface to use. A particular sensor will always interface with the same SPI peripheral.
-
enum SpiSpeed
The desired speed of the SPI interface in Hz. The possible options are:
-
SPI_SPEED_INVALID
-
SPI_SPEED_100kHz
-
SPI_SPEED_500kHz
-
SPI_SPEED_1MHz
-
SPI_SPEED_10MHz
-
SPI_SPEED_20MHz
-
SPI_SPEED_INVALID
-
struct SpiDevice
Configuration for communicating with a specific device on the bus.
-
bool cpol
Clock polarity configuration.
-
bool cpha
Clock phase configuration.
-
uint8_t mosi
Pin number for the MOSI wire (PIN_PXX). Note that every device on the same peripheral must use the same pin number.
-
uint8_t miso
Pin number for the MISO wire (PIN_PXX). Note that every device on the same peripheral must use the same pin number.
-
uint8_t sck
Pin number for the SCK wire (PIN_PXX). Note that every device on the same peripheral must use the same pin number.
-
uint8_t cs
Pin number for the CS wire (PIN_PXX). Note that every device on the same peripheral must use a different pin number.
-
bool cpol
Functions
-
Status spi_exchange(SpiDevice *dev, uint8_t *tx_buf, uint8_t *rx_buf, uint16_t len)
Exchanges data with an SPI device. If the peripheral is not yet initialized, it will be initialized.
- Parameters:
dev – The device to echange data with.
tx_buf – Pointer to the data to write.
rx_buf – Pointer to a buffer to store incoming data.
len – Number of bytes to exchange.
- Returns:
STATUS_OK if the write was successful, STATUS_PARAMETER_ERROR if a parameter is invalid, or STATUS_HARDWARE_ERROR if the write failed.
-
Status spi_exchange_nosetup(SpiDevice *dev, uint8_t *tx_buf, uint8_t *rx_buf, uint16_t len)
Exchanges data with an SPI device. The peripheral must be initialized before calling this function.
- Parameters:
dev – The device to echange data with.
tx_buf – Pointer to the data to write.
rx_buf – Pointer to a buffer to store incoming data.
len – Number of bytes to exchange.
- Returns:
STATUS_OK if the write was successful, STATUS_PARAMETER_ERROR if a parameter is invalid, or STATUS_HARDWARE_ERROR if the write failed.