SPI_STM32F7x.c

SPI example for STM32F7xx MCUs

Author
Michael Fitzmayer
// SPDX-License-Identifier: Beerware
#include "STBrickLib.h"
#include "stm32f7xx_hal.h"
#include "stm32f7xx_hal_gpio.h"
#include "stm32f7xx_hal_spi.h"
SPI_HandleTypeDef hspi2;
StatusCode SPI_Transmit(uint8_t* pu8TxData, uint16_t u16Size)
{
if (HAL_OK != HAL_SPI_Transmit(&hspi2, pu8TxData, u16Size, 300))
{
return STATUS_ERROR;
}
return STATUS_OK;
}
StatusCode SPI_Receive(uint8_t* pu8RxData, uint16_t u16Size)
{
if (HAL_OK != HAL_SPI_Receive(&hspi2, pu8RxData, u16Size, 300))
{
return STATUS_ERROR;
}
return STATUS_OK;
}
StatusCode SPI_TransmitReceive(uint8_t* pu8TxData, uint8_t* pu8RxData, uint16_t u16Size)
{
if (HAL_OK != HAL_SPI_TransmitReceive(&hspi2, pu8TxData, pu8RxData, u16Size, 300))
{
return STATUS_ERROR;
}
return STATUS_OK;
}
void SPI_CS_PullLow(void)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);
}
void SPI_CS_RaiseHigh(void)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);
}
__weak StatusCode SPI_TransmitReceive(uint8_t *pu8TxData, uint8_t *pu8RxData, uint16_t u16Size)
Transmit and Receive an amount of data.
Definition: STBrickLib.c:102
A growing collection of hardware drivers designed for STM32 microcontrollers.
__weak StatusCode SPI_Transmit(uint8_t *pu8TxData, uint16_t u16Size)
Transmit an amount of data.
Definition: STBrickLib.c:78
__weak void SPI_CS_PullLow(void)
Pull CS pin low.
Definition: STBrickLib.c:115
__weak StatusCode SPI_Receive(uint8_t *pu8RxData, uint16_t u16Size)
Receive an amount of data.
Definition: STBrickLib.c:90
StatusCode
Status codes.
Definition: STBrickLib.h:20
__weak void SPI_CS_RaiseHigh(void)
Raise CS pin high.
Definition: STBrickLib.c:124