Core
Loading...
Searching...
No Matches
spi.c File Reference

Core SPI library. More...

#include "spi.h"
#include "core_config.h"
#include <stdint.h>
#include <stdbool.h>
#include <stm32g4xx_hal.h>
#include <stm32g4xx_hal_spi.h>
#include "clock.h"

Functions

bool core_SPI_init (SPI_TypeDef *spi, GPIO_TypeDef *cs_port, uint16_t cs_pin)
 Initialize an SPI module and set up a CS pin for it.
 
bool core_SPI_read_write (SPI_TypeDef *spi, uint8_t *txbuf, uint32_t txbuflen, uint8_t *rxbuf, uint32_t rxbuflen)
 Transmit data from a buffer on the given SPI bus and store the incoming data in a separate buffer.
 
bool core_SPI_start (SPI_TypeDef *spi)
 Set the CS pin for an SPI bus low.
 
bool core_SPI_stop (SPI_TypeDef *spi)
 Set the CS pin for an SPI bus high.
 

Variables

uint16_t core_SPI1_CS_pin
 
GPIO_TypeDef * core_SPI1_CS_port
 
uint16_t core_SPI2_CS_pin
 
GPIO_TypeDef * core_SPI2_CS_port
 
uint16_t core_SPI3_CS_pin
 
GPIO_TypeDef * core_SPI3_CS_port
 
uint16_t core_SPI4_CS_pin
 
GPIO_TypeDef * core_SPI4_CS_port
 

Detailed Description

Core SPI library.

This core library component is used to interact with SPI devices.

Function Documentation

◆ core_SPI_init()

bool core_SPI_init ( SPI_TypeDef * spi,
GPIO_TypeDef * cs_port,
uint16_t cs_pin )

Initialize an SPI module and set up a CS pin for it.

Parameters
spiThe SPI module to be initialized
cs_portPort the CS pin is located on (GPIOx)
cs_pinCS pin (GPIO_PIN_x)

◆ core_SPI_read_write()

bool core_SPI_read_write ( SPI_TypeDef * spi,
uint8_t * txbuf,
uint32_t txbuflen,
uint8_t * rxbuf,
uint32_t rxbuflen )

Transmit data from a buffer on the given SPI bus and store the incoming data in a separate buffer.

Note
The number of bytes transmitted or received on the SPI bus is the greater of txbuflen and rxbuflen. Only the number of bytes given by each parameter will be read/stored respectively.
Parameters
spiThe SPI module
txbufBuffer from which data to be transmitted is read
txbuflenNumber of bytes to read from the TX buffer
rxbufBuffer to which received data is to be stored
rxbuflenNumber of bytes to write to the RX buffer

◆ core_SPI_start()

bool core_SPI_start ( SPI_TypeDef * spi)

Set the CS pin for an SPI bus low.

Parameters
spiThe SPI module

◆ core_SPI_stop()

bool core_SPI_stop ( SPI_TypeDef * spi)

Set the CS pin for an SPI bus high.

Parameters
spiThe SPI module