microHAL
An abstraction layer for your future F4xx projects
Loading...
Searching...
No Matches
spi.c File Reference

Function defines for the SPI driver. More...

#include "spi.h"
#include "defines.h"

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.
 

Detailed Description

Function defines for the SPI driver.

This file contains all of the function definitions declared in spi.h.

Author
Vasileios Ch. (BillisC)
Bug
None, yet.

Function Documentation

◆ spi_configure_clk()

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.

Parameters
spiThe selected SPI
divThe prescale divider
polarityThe default state of the clock
phaseCapture data on first or second pulse
Returns
None

◆ spi_configure_communication()

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.

Parameters
spiThe selected SPI
dirThe communication mode
nssThe NSS pin mode
Returns
None

◆ spi_configure_options()

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.

Parameters
spiThe selected SPI
configThe SPI configuration
Returns
None

◆ spi_rx_data()

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.

Parameters
spiThe selected SPI
Returns
The received data

◆ spi_set_dma()

void spi_set_dma ( const spi_peripheral_t spi,
const _Bool forTX,
const _Bool forRX )

Enables DMA for SPI RX and/or TX.

Parameters
spiThe selected SPI
forTXEnable / disable DMA for TX
forRXEnable / disable DMA for RX
Returns
None

◆ spi_set_interrupts()

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.

Parameters
spiThe selected SPI
configThe interrupt config
Returns
None

◆ spi_set_ssi_state()

void spi_set_ssi_state ( const spi_peripheral_t spi,
const _Bool state )

Sets the internal SS to the desired state.

Parameters
spiThe selected SPI
stateThe SSI state
Returns
None

◆ spi_start()

void spi_start ( const spi_peripheral_t spi,
const _Bool master )

Initiates the SPI peripheral with specified options.

Parameters
spiThe selected SPI
masterUse master configuration
Returns
None

◆ spi_stop()

void spi_stop ( const spi_peripheral_t spi)

Stops the SPI peripheral communication.

Parameters
spiThe selected SPI
Returns
None

◆ spi_trx_data()

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.

Parameters
spiThe selected SPI
dataThe data to transmit
Returns
The received data

◆ spi_tx_data()

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.

Parameters
spiThe selected SPI
dataThe data to transmit
Returns
None