ACDC Senior Project v1.0.0
Senior Project for Textron Aviation
|
Header file for SPI driver. More...
Go to the source code of this file.
Enumerations | |
enum | SPI_BaudDivider { SPI_BAUD_DIV_2 = 0b000 , SPI_BAUD_DIV_4 = 0b001 , SPI_BAUD_DIV_8 = 0b010 , SPI_BAUD_DIV_16 = 0b011 , SPI_BAUD_DIV_32 = 0b100 , SPI_BAUD_DIV_64 = 0b101 , SPI_BAUD_DIV_128 = 0b110 , SPI_BAUD_DIV_256 = 0b111 } |
enum | SPI_BitMode { SPI_MODE_8Bit = 0 , SPI_MODE_16Bit = 1 } |
Functions | |
void | SPI_InitCS (SPI_TypeDef *SPIx, bool isMaster, GPIO_TypeDef *GPIOx, uint16_t GPIO_PIN) |
Initializes the SPIx peripheral to master or slave, using the chip select pin of your choosing. (Default Values: SPI_MODE_16Bit, SPI_BAUD_DIV_2, MSB First) | |
void | SPI_EnableSoftwareCS (SPI_TypeDef *SPIx, GPIO_TypeDef *GPIOx, uint16_t GPIO_PIN) |
Enables the software CS for SPIx. (Disables Hardware CS) | |
void | SPI_EnableRemap (const SPI_TypeDef *SPIx, bool enable) |
Enables pin remapping on SPIx depending on the value of enable (Only SPI1 can be remapped) | |
void | SPI_Transmit (SPI_TypeDef *SPIx, uint16_t data) |
Transmits data over the given SPI. | |
void | SPI_TransmitCS (SPI_TypeDef *SPIx, uint16_t data, GPIO_TypeDef *GPIOx, uint16_t GPIO_PIN) |
Transmits data over the given SPI, and toggles the CS pins accordingly. | |
uint16_t | SPI_Receive (const SPI_TypeDef *SPIx) |
Recieves data from a SPI. | |
uint16_t | SPI_TransmitReceive (SPI_TypeDef *SPIx, uint16_t data) |
Transmits and recieves data over the SPI. | |
uint16_t | SPI_TransmitReceiveCS (SPI_TypeDef *SPIx, uint16_t data, GPIO_TypeDef *GPIOx, uint16_t GPIO_PIN) |
Transmits and recieves data over the SPI, also takes care of the software chip select. | |
void | SPI_SetBaudDivider (SPI_TypeDef *SPIx, SPI_BaudDivider SPI_BAUD_DIV_x) |
Changes the Baud rate divider of the SPIx peripheral. | |
void | SPI_CalculateAndSetBaudDivider (SPI_TypeDef *SPIx, uint32_t maxPeripheralClockSpeed) |
Calculates and sets the SPI baud divider to accompany the current peripherals maximum clock speed. | |
void | SPI_SetBitMode (SPI_TypeDef *SPIx, SPI_BitMode SPI_MODE_x) |
Changes the SPIx peripheral between 8-bit and 16-bit mode. | |
void | SPI_SetLsbFirst (SPI_TypeDef *SPIx, bool LsbFirst) |
Sets SPIx into either MsbFirst or LsbFirst mode. | |
void | SPI_SetClockPhaseAndPolarity (SPI_TypeDef *SPIx, bool ClkPhase, bool ClkPolarity) |
Sets the clock phase and polarity for SPIx. | |
void | SPI_SetToMaster (SPI_TypeDef *SPIx, bool isMaster) |
Configures SPIx peripheral as master or slave mode. | |
bool | SPI_HasDataToRecieve (SPI_TypeDef *SPIx) |
Checks if there is data available in the SPIx recieve buffer. | |
Header file for SPI driver.
enum SPI_BaudDivider |
enum SPI_BitMode |
void SPI_CalculateAndSetBaudDivider | ( | SPI_TypeDef * | SPIx, |
uint32_t | maxPeripheralClockSpeed ) |
Calculates and sets the SPI baud divider to accompany the current peripherals maximum clock speed.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
maxPeripheralClockSpeed | Maximum clock speed the SPI peripheral can run at |
void SPI_EnableRemap | ( | const SPI_TypeDef * | SPIx, |
bool | enable ) |
Enables pin remapping on SPIx depending on the value of enable (Only SPI1 can be remapped)
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
enable | True if the system should enable remapping for SPIx, false if it should not remap SPIx |
void SPI_EnableSoftwareCS | ( | SPI_TypeDef * | SPIx, |
GPIO_TypeDef * | GPIOx, | ||
uint16_t | GPIO_PIN ) |
Enables the software CS for SPIx. (Disables Hardware CS)
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
GPIOx | Port of the GPIO (Ex. GPIOA, GPIOB, ...) |
GPIO_PIN | Desired pin on port GPIOx (Ex. GPIO_PIN_0, GPIO_PIN_1, ...) |
bool SPI_HasDataToRecieve | ( | SPI_TypeDef * | SPIx | ) |
Checks if there is data available in the SPIx recieve buffer.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
Initializes the SPIx peripheral to master or slave, using the chip select pin of your choosing. (Default Values: SPI_MODE_16Bit, SPI_BAUD_DIV_2, MSB First)
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
isMaster | True if SPIx should act as the master, false if it should act as the slave |
GPIOx | GPIO Port for the chip select pin (Ex. GPIOA, GPIOB, ...) |
GPIO_PIN | Desired chip select pin on port GPIOx (Ex. GPIO_PIN_0, GPIO_PIN_1, ...) |
uint16_t SPI_Receive | ( | const SPI_TypeDef * | SPIx | ) |
Recieves data from a SPI.
SPIx | SPI to recieve from |
void SPI_SetBaudDivider | ( | SPI_TypeDef * | SPIx, |
SPI_BaudDivider | SPI_BAUD_DIV_x ) |
Changes the Baud rate divider of the SPIx peripheral.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
SPI_BAUD_DIV_x | SPI Tx Baud rate divider (Ex. SPI_BAUD_DIV_2, SPI_BAUD_DIV_4, ...) |
void SPI_SetBitMode | ( | SPI_TypeDef * | SPIx, |
SPI_BitMode | SPI_MODE_x ) |
Changes the SPIx peripheral between 8-bit and 16-bit mode.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
SPI_MODE_x | Bit mode selection for SPIx (Ex. SPI_MODE_8bit or SPI_MODE_16bit) |
Sets the clock phase and polarity for SPIx.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
ClkPhase | True for second clock transition as first data capture edge, False for first clock transition. {See RM-744} |
ClkPolarity | True to set clock to 1 when idle, else false to set low while idle. |
void SPI_SetLsbFirst | ( | SPI_TypeDef * | SPIx, |
bool | LsbFirst ) |
Sets SPIx into either MsbFirst or LsbFirst mode.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
LsbFirst | True if the data format should be LsbFirst, else false for MsbFirst. |
void SPI_SetToMaster | ( | SPI_TypeDef * | SPIx, |
bool | isMaster ) |
Configures SPIx peripheral as master or slave mode.
SPIx | SPI Peripheral (Ex. SPI1 or SPI2) |
isMaster | True to configure SPI as master, False to configure it as slave. |
void SPI_Transmit | ( | SPI_TypeDef * | SPIx, |
uint16_t | data ) |
Transmits data over the given SPI.
SPIx | SPI to transmit over |
data | Data to transmit |
Transmits data over the given SPI, and toggles the CS pins accordingly.
SPIx | SPI to transmit over |
data | Data to transmit |
GPIOx | GPIO Port for the chip select pin (Ex. GPIOA, GPIOB, ...) |
GPIO_PIN | Desired chip select pin on port GPIOx (Ex. GPIO_PIN_0, GPIO_PIN_1, ...) |
Transmits and recieves data over the SPI.
SPIx | SPI to transmit over |
data | Data to transmit |
uint16_t SPI_TransmitReceiveCS | ( | SPI_TypeDef * | SPIx, |
uint16_t | data, | ||
GPIO_TypeDef * | GPIOx, | ||
uint16_t | GPIO_PIN ) |
Transmits and recieves data over the SPI, also takes care of the software chip select.
SPIx | SPI to transmit over |
data | Data to transmit |
GPIOx | GPIO Port for the chip select pin (Ex. GPIOA, GPIOB, ...) |
GPIO_PIN | Desired chip select pin on port GPIOx (Ex. GPIO_PIN_0, GPIO_PIN_1, ...) |