microHAL
An abstraction layer for your future F4xx projects
|
Function prototypes for the SPI interface. More...
Go to the source code of this file.
Data Structures | |
struct | SPIRegs |
Contains SPI/I2S registers. More... | |
struct | SPIISR |
Contains SPI interrupt configuration. More... | |
struct | SPIConfig |
Contains additional SPI configuration. More... | |
Macros | |
#define | SPI(ADDR) |
Typedefs | |
typedef enum spi_peripheral | spi_peripheral_t |
Available SPI peripherals. | |
typedef enum spi_communication | spi_communication_t |
Available SPI communication modes. | |
typedef enum spi_nss_mode | spi_nss_mode_t |
Available SPI NSS pin modes. | |
typedef enum spi_prescaler | spi_prescaler_t |
Available SPI clock dividers. | |
Enumerations | |
enum | spi_peripheral { SPI_PERIPH_LEN } |
Available SPI peripherals. | |
enum | spi_communication { SPI_COMM_FULLDUPLEX = 0x0 , SPI_COMM_HALFDUPLEX_RX , SPI_COMM_HALFDUPLEX_TX , SPI_COMM_SIMPLEX_RX , SPI_COMM_SIMPLEX_TX } |
Available SPI communication modes. | |
enum | spi_nss_mode { SPI_NSS_SOFT = 0x0 , SPI_NSS_HARD_OE , SPI_NSS_HARD_OD } |
Available SPI NSS pin modes. | |
enum | spi_prescaler { SPI_PRESC_DIV2 = 0x0 , SPI_PRESC_DIV4 , SPI_PRESC_DIV8 , SPI_PRESC_DIV16 , SPI_PRESC_DIV32 , SPI_PRESC_DIV64 , SPI_PRESC_DIV128 , SPI_PRESC_DIV256 } |
Available SPI clock dividers. | |
Functions | |
void | spi_set_interrupts (const spi_peripheral_t spi, const struct SPIISR config) |
Enables specified SPI interrupts. | |
void | spi_configure_communication (const spi_peripheral_t spi, const spi_communication_t com, const spi_nss_mode_t nss) |
Configures the SPI communication / wiring. | |
void | spi_configure_clk (const spi_peripheral_t spi, const spi_prescaler_t div, _Bool polarity, _Bool phase) |
Configures the SPI prescale divider. | |
void | spi_set_ssi_state (const spi_peripheral_t spi, const _Bool state) |
Sets the internal SS to the desired state. | |
void | spi_set_dma (const spi_peripheral_t spi, const _Bool forTX, const _Bool forRX) |
Enables DMA for SPI RX and/or TX. | |
void | spi_configure_options (const spi_peripheral_t spi, const struct SPIConfig config) |
Set SPI options from specified config. | |
void | spi_tx_data (const spi_peripheral_t spi, const uint16_t data) |
Transmits specified SPI data. | |
uint16_t | spi_rx_data (const spi_peripheral_t spi) |
Reads the received SPI data. | |
uint16_t | spi_trx_data (const spi_peripheral_t spi, const uint16_t data) |
Transmit data, receive answer. | |
void | spi_start (const spi_peripheral_t spi, const _Bool master) |
Initiates the SPI peripheral with specified options. | |
void | spi_stop (const spi_peripheral_t spi) |
Stops the SPI peripheral communication. | |
Function prototypes for the SPI interface.
This file contains all of the enums, macros, and function prototypes required for a functional SPI interface.
Multi-slave switching is not available, so please handle GPIOs manually.
#define SPI | ( | ADDR | ) |
void spi_configure_clk | ( | const spi_peripheral_t | spi, |
const spi_prescaler_t | div, | ||
_Bool | polarity, | ||
_Bool | phase ) |
Configures the SPI prescale divider.
The available division values can be found in the spi_prescaler_t enum. Any other value will be ignored. Note that the prescaler will divide the clock speed of the bus of the peripheral and not the system clock. The resulting clock will be the baudrate of the SPI.
spi | The selected SPI |
div | The prescale divider |
polarity | The default state of the clock |
phase | Capture data on first or second pulse |
void spi_configure_communication | ( | const spi_peripheral_t | spi, |
const spi_communication_t | com, | ||
const spi_nss_mode_t | nss ) |
Configures the SPI communication / wiring.
The available communication and nss modes can be located under the spi_communication_t and spi_nss_mode_t enums. Any other value will be ignored.
spi | The selected SPI |
dir | The communication mode |
nss | The NSS pin mode |
void spi_configure_options | ( | const spi_peripheral_t | spi, |
const struct SPIConfig | config ) |
Set SPI options from specified config.
The SPI configuration is located under the SPIConfig struct. Refer to the datasheet for the correct usage of these options.
spi | The selected SPI |
config | The SPI configuration |
uint16_t spi_rx_data | ( | const spi_peripheral_t | spi | ) |
Reads the received SPI data.
The data can be read as soon as they are stored in the RX buffer from the shift register. You may pair this with an interrupt for better performance.
spi | The selected SPI |
void spi_set_dma | ( | const spi_peripheral_t | spi, |
const _Bool | forTX, | ||
const _Bool | forRX ) |
Enables DMA for SPI RX and/or TX.
spi | The selected SPI |
forTX | Enable / disable DMA for TX |
forRX | Enable / disable DMA for RX |
void spi_set_interrupts | ( | const spi_peripheral_t | spi, |
const struct SPIISR | config ) |
Enables specified SPI interrupts.
The list of available SPI interrupts is located under the SPIISR struct.
spi | The selected SPI |
config | The interrupt config |
void spi_set_ssi_state | ( | const spi_peripheral_t | spi, |
const _Bool | state ) |
Sets the internal SS to the desired state.
spi | The selected SPI |
state | The SSI state |
void spi_start | ( | const spi_peripheral_t | spi, |
const _Bool | master ) |
Initiates the SPI peripheral with specified options.
spi | The selected SPI |
master | Use master configuration |
void spi_stop | ( | const spi_peripheral_t | spi | ) |
Stops the SPI peripheral communication.
spi | The selected SPI |
uint16_t spi_trx_data | ( | const spi_peripheral_t | spi, |
const uint16_t | data ) |
Transmit data, receive answer.
A combination of TX and RX functions.
spi | The selected SPI |
data | The data to transmit |
void spi_tx_data | ( | const spi_peripheral_t | spi, |
const uint16_t | data ) |
Transmits specified SPI data.
The data parameter is 16-bit but you may set the LSB for 8-bit transfers. The SPI loads the data in the shift register and transmits using the configured byte order.
spi | The selected SPI |
data | The data to transmit |