|
Serial Peripheral Interface Reusable Driver v1.1
This project implements SPI reusable driver that can be adapted to various microcontrollers.
|
The implementation for the SPI Driver. More...
#include "spi.h"
Functions | |
| void | SPI_init (const SpiConfig_t *const Config, size_t configSize) |
| void | SPI_transfer (const SpiTransferConfig_t *const TransferConfig) |
| void | SPI_receive (const SpiTransferConfig_t *const TransferConfig) |
| void | SPI_registerWrite (uint32_t address, uint32_t value) |
| uint16_t | SPI_registerRead (uint32_t address) |
The implementation for the SPI Driver.
| void SPI_init | ( | const SpiConfig_t *const | Config, |
| size_t | configSize ) |
Description: This function is used to initialize the SPI based on the configuration
table defined in spi_cfg module.
PRE-CONDITION: The MCU clocks must be configured and enabled.
PRE-CONDITION: SPI pins should be configured using GPIO driver.
PRE-CONDITION: Configuration table needs to be populated (sizeof > 0)
PRE-CONDITION: The setting is within the maximum values (SPI_MAX).
POST-CONDITION: The peripheral is set up with the configuration settings.
| [in] | Config | is a pointer to the configuration table that contains the initialization for the peripheral. |
| [in] | configSize | is the size of the configuration table. |
Example:
Loop through all the elements of the configuration table.
Set the configuration of the SPI on the control register 1
Set the Clock phase and polarity modes
Set the hierarchy of the device
Set the baud rate of the device
Set the slave select pin management for the device
Set the frame format of the device
Set the data transfer type of the device
Set the data frame format (size) of the device
Enable the SPI module
| void SPI_receive | ( | const SpiTransferConfig_t *const | TransferConfig | ) |
Description: This function is used to initialize a data reception on the SPI bus. This function is used to receive data specified by the SpiTransferConfig_t structure, which contains the channel, size, and data.
PRE-CONDITION: The MCU clocks must be configured and enabled.
PRE-CONDITION: SPI_Init must be called with valid configuration data.
PRE-CONDITION: SpiTransferConfig_t needs to be populated.
PRE-CONDITION: The Channel is within the maximum SpiChannel_t.
PRE-CONDITION: The size is greater than 0.
PRE-CONDITION: The data is not NULL.
POST-CONDITION: Data transferred based on configuration.
| [in] | SpiTransferConfig | A pointer to a structure containing the channel, size, and data to be read. |
Example:
| uint16_t SPI_registerRead | ( | uint32_t | address | ) |
Description: This function is used to directly address a SPI register. The function should be used to access specialized functionality in the SPI peripheral that is not exposed by any other function of the interface.
PRE-CONDITION: Address is within the boundaries of the SPI register address space.
POST-CONDITION: The value stored in the register is returned to the caller.
| [in] | address | is the address of the SPI register to read. |
Example:
| void SPI_registerWrite | ( | uint32_t | address, |
| uint32_t | value ) |
Description: This function is used to directly address and modify a SPI register. The function should be used to access specialized functionality in the SPI peripheral that is not exposed by any other function of the interface.
PRE-CONDITION: Address is within the boundaries of the SPI register address space.
POST-CONDITION: The register located at address with be updated with value.
| [in] | address | is a register address within the SPI peripheral map. |
| [in] | value | is the value to set the SPI register. |
Example
| void SPI_transfer | ( | const SpiTransferConfig_t *const | TransferConfig | ) |
Description: This function is used to initialize a data transfer on the SPI bus. This function is used to send data to a slave device specified by the SpiTransferConfig_t structure, which contains the channel, size, and data.
PRE-CONDITION: The MCU clocks must be configured and enabled.
PRE-CONDITION: SPI_Init must be called with valid configuration data.
PRE-CONDITION: SpiTransferConfig_t needs to be populated.
PRE-CONDITION: The Channel is within the maximum SpiChannel_t.
PRE-CONDITION: The size is greater than 0.
PRE-CONDITION: The data is not NULL.
POST-CONDITION: Data transferred based on configuration.
| [in] | SpiTransferConfig | A pointer to a structure containing the channel, size, and data to be read. |
Example: