This section describes the programming interface of the SPI HAL driver.
|
enum | spi_status_t { ,
kStatus_SPI_SlaveTxUnderrun,
kStatus_SPI_SlaveRxOverrun,
kStatus_SPI_Timeout,
kStatus_SPI_Busy,
kStatus_SPI_NoTransferInProgress,
kStatus_SPI_OutOfRange,
kStatus_SPI_TxBufferNotEmpty,
kStatus_SPI_InvalidParameter,
kStatus_SPI_NonInit,
kStatus_SPI_AlreadyInitialized,
kStatus_SPI_DMAChannelInvalid,
kStatus_SPI_Error
} |
| Error codes for the SPI driver. More...
|
|
enum | spi_master_slave_mode_t {
kSpiMaster = 1,
kSpiSlave = 0
} |
| SPI master or slave configuration. More...
|
|
enum | spi_clock_polarity_t {
kSpiClockPolarity_ActiveHigh = 0,
kSpiClockPolarity_ActiveLow = 1
} |
| SPI clock polarity configuration. More...
|
|
enum | spi_clock_phase_t {
kSpiClockPhase_FirstEdge = 0,
kSpiClockPhase_SecondEdge = 1
} |
| SPI clock phase configuration. More...
|
|
enum | spi_shift_direction_t {
kSpiMsbFirst = 0,
kSpiLsbFirst = 1
} |
| SPI data shifter direction options. More...
|
|
enum | spi_ss_output_mode_t {
kSpiSlaveSelect_AsGpio = 0,
kSpiSlaveSelect_FaultInput = 2,
kSpiSlaveSelect_AutomaticOutput = 3
} |
| SPI slave select output mode options. More...
|
|
enum | spi_pin_mode_t {
kSpiPinMode_Normal = 0,
kSpiPinMode_Input = 1,
kSpiPinMode_Output = 3
} |
| SPI pin mode options. More...
|
|
enum | spi_data_bitcount_mode_t {
kSpi8BitMode = 0,
kSpi16BitMode = 1
} |
| SPI data length mode options. More...
|
|
enum | spi_interrupt_source_t {
kSpiRxFullAndModfInt = 1,
kSpiTxEmptyInt = 2,
kSpiMatchInt = 3
} |
| SPI interrupt sources. More...
|
|
enum | spi_int_status_flag_t {
kSpiRxBufferFullFlag = SPI_S_SPRF_SHIFT,
kSpiMatchFlag = SPI_S_SPMF_SHIFT,
kSpiTxBufferEmptyFlag = SPI_S_SPTEF_SHIFT,
kSpiModeFaultFlag = SPI_S_MODF_SHIFT
} |
| SPI interrupt status flags. More...
|
|
enum | spi_fifo_interrupt_source_t {
kSpiRxFifoNearFullInt = 1,
kSpiTxFifoNearEmptyInt = 2
} |
| SPI FIFO interrupt sources. More...
|
|
enum | spi_w1c_interrupt_t {
kSpiRxFifoFullClearInt = 0,
kSpiTxFifoEmptyClearInt = 1,
kSpiRxNearFullClearInt = 2,
kSpiTxNearEmptyClearInt = 3
} |
| SPI FIFO write-1-to-clear interrupt flags. More...
|
|
enum | spi_txfifo_watermark_t |
| SPI TX FIFO watermark settings. More...
|
|
enum | spi_rxfifo_watermark_t |
| SPI RX FIFO watermark settings. More...
|
|
enum | spi_fifo_status_flag_t |
| SPI status flags. More...
|
|
enum | spi_fifo_error_flag_t {
kSpiNoFifoError = 0,
kSpiRxfof = 1,
kSpiTxfof = 2,
kSpiRxfofTxfof = 3,
kSpiRxferr = 4,
kSpiRxfofRxferr = 5,
kSpiTxfofRxferr = 6,
kSpiRxfofTxfofRxferr = 7,
kSpiTxferr = 8,
kSpiRxfofTxferr = 9,
kSpiTxfofTxferr = 10,
kSpiRxfofTxfofTxferr = 11,
kSpiRxferrTxferr = 12,
kSpiRxfofRxferrTxferr = 13,
kSpiTxfofRxferrTxferr = 14,
kSpiRxfofTxfofRxferrTxferr =15
} |
| SPI error flags. More...
|
|
|
void | SPI_HAL_Init (SPI_Type *base) |
| Restores the SPI to the reset configuration. More...
|
|
static void | SPI_HAL_Enable (SPI_Type *base) |
| Enables the SPI peripheral. More...
|
|
static void | SPI_HAL_Disable (SPI_Type *base) |
| Disables the SPI peripheral. More...
|
|
uint32_t | SPI_HAL_SetBaud (SPI_Type *base, uint32_t bitsPerSec, uint32_t sourceClockInHz) |
| Sets the SPI baud rate in bits per second. More...
|
|
static void | SPI_HAL_SetBaudDivisors (SPI_Type *base, uint32_t prescaleDivisor, uint32_t rateDivisor) |
| Configures the baud rate divisors manually. More...
|
|
static void | SPI_HAL_SetMasterSlave (SPI_Type *base, spi_master_slave_mode_t mode) |
| Configures the SPI for master or slave. More...
|
|
static bool | SPI_HAL_IsMaster (SPI_Type *base) |
| Returns whether the SPI module is in master mode. More...
|
|
void | SPI_HAL_SetSlaveSelectOutputMode (SPI_Type *base, spi_ss_output_mode_t mode) |
| Sets how the slave select output operates. More...
|
|
void | SPI_HAL_SetDataFormat (SPI_Type *base, spi_clock_polarity_t polarity, spi_clock_phase_t phase, spi_shift_direction_t direction) |
| Sets the polarity, phase, and shift direction. More...
|
|
static uint32_t | SPI_HAL_GetDataRegAddr (SPI_Type *base) |
| Gets the SPI data register address for DMA operation. More...
|
|
void | SPI_HAL_SetPinMode (SPI_Type *base, spi_pin_mode_t mode) |
| Sets the SPI pin mode. More...
|
|
Enumerator |
---|
kStatus_SPI_SlaveTxUnderrun |
SPI Slave TX Underrun error.
|
kStatus_SPI_SlaveRxOverrun |
SPI Slave RX Overrun error.
|
kStatus_SPI_Timeout |
SPI transfer timed out.
|
kStatus_SPI_Busy |
SPI instance is already busy performing a transfer.
|
kStatus_SPI_NoTransferInProgress |
Attempt to abort a transfer when no transfer was in progress.
|
kStatus_SPI_OutOfRange |
SPI out-of-range error used in slave callback.
|
kStatus_SPI_TxBufferNotEmpty |
SPI TX buffer register is not empty.
|
kStatus_SPI_InvalidParameter |
Parameter is invalid.
|
kStatus_SPI_NonInit |
SPI driver is not initialized.
|
kStatus_SPI_AlreadyInitialized |
SPI driver already initialized.
|
kStatus_SPI_DMAChannelInvalid |
SPI driver cannot requests DMA channel.
|
kStatus_SPI_Error |
SPI driver error.
|
Enumerator |
---|
kSpiMaster |
SPI peripheral operates in master mode.
|
kSpiSlave |
SPI peripheral operates in slave mode.
|
Enumerator |
---|
kSpiClockPolarity_ActiveHigh |
Active-high SPI clock (idles low).
|
kSpiClockPolarity_ActiveLow |
Active-low SPI clock (idles high).
|
Enumerator |
---|
kSpiClockPhase_FirstEdge |
First edge on SPSCK occurs at the middle of the first cycle of a data transfer.
|
kSpiClockPhase_SecondEdge |
First edge on SPSCK occurs at the start of the first cycle of a data transfer.
|
Enumerator |
---|
kSpiMsbFirst |
Data transfers start with most significant bit.
|
kSpiLsbFirst |
Data transfers start with least significant bit.
|
Enumerator |
---|
kSpiSlaveSelect_AsGpio |
Slave select pin configured as GPIO.
|
kSpiSlaveSelect_FaultInput |
Slave select pin configured for fault detection.
|
kSpiSlaveSelect_AutomaticOutput |
Slave select pin configured for automatic SPI output.
|
Enumerator |
---|
kSpiPinMode_Normal |
Pins operate in normal, single-direction mode.
|
kSpiPinMode_Input |
Bidirectional mode.
Master: MOSI pin is input; Slave: MISO pin is input
|
kSpiPinMode_Output |
Bidirectional mode.
Master: MOSI pin is output; Slave: MISO pin is output
|
Enumerator |
---|
kSpi8BitMode |
8-bit data transmission mode
|
kSpi16BitMode |
16-bit data transmission mode
|
Enumerator |
---|
kSpiRxFullAndModfInt |
Receive buffer full (SPRF) and mode fault (MODF) interrupt.
|
kSpiTxEmptyInt |
Transmit buffer empty interrupt.
|
kSpiMatchInt |
Match interrupt.
|
Enumerator |
---|
kSpiRxBufferFullFlag |
Read buffer full flag.
|
kSpiMatchFlag |
Match flag.
|
kSpiTxBufferEmptyFlag |
Transmit buffer empty flag.
|
kSpiModeFaultFlag |
Mode fault flag.
|
Enumerator |
---|
kSpiRxFifoNearFullInt |
Receive FIFO nearly full interrupt.
|
kSpiTxFifoNearEmptyInt |
Transmit FIFO nearly empty interrupt.
|
Enumerator |
---|
kSpiRxFifoFullClearInt |
Receive FIFO full interrupt.
|
kSpiTxFifoEmptyClearInt |
Transmit FIFO empty interrupt.
|
kSpiRxNearFullClearInt |
Receive FIFO nearly full interrupt.
|
kSpiTxNearEmptyClearInt |
Transmit FIFO nearly empty interrupt.
|
Enumerator |
---|
kSpiNoFifoError |
No error is detected.
|
kSpiRxfof |
Receive FIFO Overflow.
|
kSpiTxfof |
Transmit FIFO Overflow.
|
kSpiRxfofTxfof |
Receive FIFO Overflow, Transmit FIFO Overflow.
|
kSpiRxferr |
Receive FIFO Error.
|
kSpiRxfofRxferr |
Receive FIFO Overflow, Receive FIFO Error.
|
kSpiTxfofRxferr |
Transmit FIFO Overflow, Receive FIFO Error.
|
kSpiRxfofTxfofRxferr |
Receive FIFO Overflow, Transmit FIFO Overflow, Receive FIFO Error.
|
kSpiTxferr |
Transmit FIFO Error.
|
kSpiRxfofTxferr |
Receive FIFO Overflow, Transmit FIFO Error.
|
kSpiTxfofTxferr |
Transmit FIFO Overflow, Transmit FIFO Error.
|
kSpiRxfofTxfofTxferr |
Receive FIFO Overflow, Transmit FIFO Overflow, Transmit FIFO Error.
|
kSpiRxferrTxferr |
Receive FIFO Error, Transmit FIFO Error.
|
kSpiRxfofRxferrTxferr |
Receive FIFO Overflow, Receive FIFO Error, Transmit FIFO Error.
|
kSpiTxfofRxferrTxferr |
Transmit FIFO Overflow, Receive FIFO Error, Transmit FIFO Error.
|
kSpiRxfofTxfofRxferrTxferr |
Receive FIFO Overflow, Transmit FIFO Overflow Receive FIFO Error, Transmit FIFO Error.
|
void SPI_HAL_Init |
( |
SPI_Type * |
base | ) |
|
This function basically resets all of the SPI registers to their default setting including disabling the module.
- Parameters
-
base | Module base pointer of type SPI_Type. |
static void SPI_HAL_Enable |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
static void SPI_HAL_Disable |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
uint32_t SPI_HAL_SetBaud |
( |
SPI_Type * |
base, |
|
|
uint32_t |
bitsPerSec, |
|
|
uint32_t |
sourceClockInHz |
|
) |
| |
This function takes in the desired bitsPerSec (baud rate) and calculates the nearest possible baud rate without exceeding the desired baud rate unless the baud rate requested is less than the absolute minimum in which case the minimum baud rate is returned. The returned baud rate is in bits-per-second. It requires that the caller also provide the frequency of the module source clock (in Hertz).
- Parameters
-
base | Module base pointer of type SPI_Type. |
bitsPerSec | The desired baud rate in bits per second. |
sourceClockInHz | Module source input clock in Hertz. |
- Returns
- The actual calculated baud rate in Hz.
static void SPI_HAL_SetBaudDivisors |
( |
SPI_Type * |
base, |
|
|
uint32_t |
prescaleDivisor, |
|
|
uint32_t |
rateDivisor |
|
) |
| |
|
inlinestatic |
This function allows the caller to manually set the baud rate divisors in the event that these dividers are known and the caller does not wish to call the SPI_HAL_SetBaudRate function.
- Parameters
-
base | Module base pointer of type SPI_Type. |
prescaleDivisor | baud rate prescale divisor setting. |
rateDivisor | baud rate divisor setting. |
- Parameters
-
base | Module base pointer of type SPI_Type. |
mode | Mode setting (master or slave) of type dspi_master_slave_mode_t. |
static bool SPI_HAL_IsMaster |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- true The module is in master mode. false The module is in slave mode.
This function allows the user to configure the slave select in one of the three operational modes: as GPIO, as a fault input, or as an automatic output for standard SPI modes.
- Parameters
-
base | Module base pointer of type SPI_Type. |
mode | Selection input of one of three modes of type spi_ss_output_mode_t. |
This function configures the clock polarity, clock phase, and data shift direction.
- Parameters
-
base | Module base pointer of type SPI_Type. |
polarity | Clock polarity setting of type spi_clock_polarity_t. |
phase | Clock phase setting of type spi_clock_phase_t. |
direction | Data shift direction (MSB or LSB) of type spi_shift_direction_t. |
static uint32_t SPI_HAL_GetDataRegAddr |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
This function gets the SPI data register address as this value is needed for DMA operation.
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- The SPI data register address.
This function configures the SPI data pins to one of three modes (of type spi_pin_mode_t): Single direction mode: MOSI and MISO pins operate in normal, single direction mode. Bidirectional mode: Master: MOSI configured as input, Slave: MISO configured as input. Bidirectional mode: Master: MOSI configured as output, Slave: MISO configured as output.
- Parameters
-
base | Module base pointer of type SPI_Type. |
mode | Operational of SPI pins of type spi_pin_mode_t. |
This function enables or disables the SPI receive buffer (or FIFO if the module supports a FIFO) full and mode fault interrupt, SPI transmit buffer (or FIFO if the module supports a FIFO) empty interrupt, and the SPI match interrupt.
Example, to set the receive and mode fault interrupt: SPI_HAL_SetIntMode(base, kSpiRxFullAndModfInt, true);
- Parameters
-
base | Module base pointer of type SPI_Type. |
interrupt | SPI interrupt source to configure of type spi_interrupt_source_t. |
enable | Enable (true) or disable (false) the receive buffer full and mode fault interrupt. |
static void SPI_HAL_SetReceiveAndFaultIntCmd |
( |
SPI_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the SPI receive buffer (or FIFO if the module supports a FIFO) full and mode fault interrupt.
- Parameters
-
base | Module base pointer of type SPI_Type. |
enable | Enable (true) or disable (false) the receive buffer full and mode fault interrupt. |
static void SPI_HAL_SetTransmitIntCmd |
( |
SPI_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the SPI transmit buffer (or FIFO if the module supports a FIFO) empty interrupt.
- Parameters
-
base | Module base pointer of type SPI_Type. |
enable | Enable (true) or disable (false) the transmit buffer empty interrupt. |
static void SPI_HAL_SetMatchIntCmd |
( |
SPI_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the SPI match interrupt.
- Parameters
-
base | Module base pointer of type SPI_Type. |
enable | Enable (true) or disable (false) the match interrupt. |
This function returns the state (set or cleared) of the SPI interrupt status flag.
- Parameters
-
base | Module base pointer of type SPI_Type. |
flag | The requested interrupt status flag of type spi_int_status_flag_t. |
- Returns
- Current setting of the requested interrupt status flag.
static bool SPI_HAL_IsReadBuffFullPending |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
The read buffer (or FIFO if the module supports a FIFO) full flag is only cleared by reading it when it is set, then reading the data register by calling the SPI_HAL_ReadData(). This example code demonstrates how to check the flag, read data, and clear the flag.
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- Current setting of the read buffer full flag.
static bool SPI_HAL_IsTxBuffEmptyPending |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
To clear the transmit buffer (or FIFO if the module supports a FIFO) empty flag, read the flag when it is set. Then, write a new data value into the transmit buffer with a call to the SPI_HAL_WriteData(). The example code shows how to do this.
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- Current setting of the transmit buffer empty flag.
static bool SPI_HAL_IsModeFaultPending |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- Current setting of the mode fault flag.
void SPI_HAL_ClearModeFaultFlag |
( |
SPI_Type * |
base | ) |
|
- Parameters
-
base | Module base pointer of type SPI_Type |
static bool SPI_HAL_IsMatchPending |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- Current setting of the match flag.
void SPI_HAL_ClearMatchFlag |
( |
SPI_Type * |
base | ) |
|
- Parameters
-
base | Module base pointer of type SPI_Type. |
static uint8_t SPI_HAL_ReadData |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
- Returns
- The data read from the data buffer.
static void SPI_HAL_WriteData |
( |
SPI_Type * |
base, |
|
|
uint8_t |
data |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
data | The data to send. |
void SPI_HAL_WriteDataBlocking |
( |
SPI_Type * |
base, |
|
|
uint8_t |
data |
|
) |
| |
This function writes data to the SPI data register and waits until the TX is empty to return.
- Parameters
-
base | Module base pointer of type SPI_Type. |
data | The data to send. |
static void SPI_HAL_SetMatchValue |
( |
SPI_Type * |
base, |
|
|
uint8_t |
matchByte |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Module base pointer of type SPI_Type. |
matchByte | The value which triggers the match interrupt. |