|
| enum | _spi_status {
kStatus_SPI_Busy = MAKE_STATUS(kStatusGroup_SPI, 0),
kStatus_SPI_Idle = MAKE_STATUS(kStatusGroup_SPI, 1),
kStatus_SPI_Error = MAKE_STATUS(kStatusGroup_SPI, 2)
} |
| | Return status for the SPI driver. More...
|
| |
| enum | spi_clock_polarity_t {
kSPI_ClockPolarityActiveHigh = 0x0U,
kSPI_ClockPolarityActiveLow
} |
| | SPI clock polarity configuration. More...
|
| |
| enum | spi_clock_phase_t {
kSPI_ClockPhaseFirstEdge = 0x0U,
kSPI_ClockPhaseSecondEdge
} |
| | SPI clock phase configuration. More...
|
| |
| enum | spi_shift_direction_t {
kSPI_MsbFirst = 0x0U,
kSPI_LsbFirst
} |
| | SPI data shifter direction options. More...
|
| |
| enum | spi_ss_output_mode_t {
kSPI_SlaveSelectAsGpio = 0x0U,
kSPI_SlaveSelectFaultInput = 0x2U,
kSPI_SlaveSelectAutomaticOutput = 0x3U
} |
| | SPI slave select output mode options. More...
|
| |
| enum | spi_pin_mode_t {
kSPI_PinModeNormal = 0x0U,
kSPI_PinModeInput = 0x1U,
kSPI_PinModeOutput = 0x3U
} |
| | SPI pin mode options. More...
|
| |
| enum | spi_data_bitcount_mode_t {
kSPI_8BitMode = 0x0U,
kSPI_16BitMode
} |
| | SPI data length mode options. More...
|
| |
| enum | _spi_interrupt_enable {
kSPI_RxFullAndModfInterruptEnable = 0x1U,
kSPI_TxEmptyInterruptEnable = 0x2U,
kSPI_MatchInterruptEnable = 0x4U,
kSPI_RxFifoNearFullInterruptEnable = 0x8U,
kSPI_TxFifoNearEmptyInterruptEnable = 0x10U
} |
| | SPI interrupt sources. More...
|
| |
| enum | _spi_flags {
kSPI_RxBufferFullFlag = SPI_S_SPRF_MASK,
kSPI_MatchFlag = SPI_S_SPMF_MASK,
kSPI_TxBufferEmptyFlag = SPI_S_SPTEF_MASK,
kSPI_ModeFaultFlag = SPI_S_MODF_MASK,
kSPI_RxFifoNearFullFlag = SPI_S_RNFULLF_MASK,
kSPI_TxFifoNearEmptyFlag = SPI_S_TNEAREF_MASK,
kSPI_RxFifoFullFlag = SPI_S_TXFULLF_MASK,
kSPI_TxFifoEmptyFlag = SPI_S_RFIFOEF_MASK,
kSPI_TxFifoError = SPI_CI_TXFERR_MASK << 8U,
kSPI_RxFifoError = SPI_CI_RXFERR_MASK << 8U,
kSPI_TxOverflow = SPI_CI_TXFOF_MASK << 8U,
kSPI_RxOverflow
} |
| | SPI status flags. More...
|
| |
| enum | spi_w1c_interrupt_t {
kSPI_RxFifoFullClearInterrupt = SPI_CI_SPRFCI_MASK,
kSPI_TxFifoEmptyClearInterrupt = SPI_CI_SPTEFCI_MASK,
kSPI_RxNearFullClearInterrupt = SPI_CI_RNFULLFCI_MASK,
kSPI_TxNearEmptyClearInterrupt = SPI_CI_TNEAREFCI_MASK
} |
| | SPI FIFO write-1-to-clear interrupt flags. More...
|
| |
| enum | spi_txfifo_watermark_t {
kSPI_TxFifoOneFourthEmpty = 0,
kSPI_TxFifoOneHalfEmpty = 1
} |
| | SPI TX FIFO watermark settings. More...
|
| |
| enum | spi_rxfifo_watermark_t {
kSPI_RxFifoThreeFourthsFull = 0,
kSPI_RxFifoOneHalfFull = 1
} |
| | SPI RX FIFO watermark settings. More...
|
| |
| enum | _spi_dma_enable_t {
kSPI_TxDmaEnable = SPI_C2_TXDMAE_MASK,
kSPI_RxDmaEnable = SPI_C2_RXDMAE_MASK,
kSPI_DmaAllEnable = (SPI_C2_TXDMAE_MASK | SPI_C2_RXDMAE_MASK)
} |
| | SPI dma source. More...
|
| |
|
| void | SPI_MasterTransferCreateHandle (SPI_Type *base, spi_master_handle_t *handle, spi_master_callback_t callback, void *userData) |
| | Initialize the SPI master handle. More...
|
| |
| status_t | SPI_MasterTransferBlocking (SPI_Type *base, spi_transfer_t *xfer) |
| | Transfer a block of data in polling way. More...
|
| |
| status_t | SPI_MasterTransferNonBlocking (SPI_Type *base, spi_master_handle_t *handle, spi_transfer_t *xfer) |
| | Performs a non-blocking SPI interrupt transfer. More...
|
| |
| status_t | SPI_MasterTransferGetCount (SPI_Type *base, spi_master_handle_t *handle, size_t *count) |
| | Get the bytes of SPI Interrupt transferred. More...
|
| |
| void | SPI_MasterTransferAbort (SPI_Type *base, spi_master_handle_t *handle) |
| | Abort a SPI transfer using interrupt. More...
|
| |
| void | SPI_MasterTransferHandleIRQ (SPI_Type *base, spi_master_handle_t *handle) |
| | Interrupt handler for SPI. More...
|
| |
| static void | SPI_SlaveTransferCreateHandle (SPI_Type *base, spi_slave_handle_t *handle, spi_slave_callback_t callback, void *userData) |
| | Initialize the SPI slave handle. More...
|
| |
| static status_t | SPI_SlaveTransferNonBlocking (SPI_Type *base, spi_slave_handle_t *handle, spi_transfer_t *xfer) |
| | Performs a non-blocking SPI slave interrupt transfer. More...
|
| |
| static status_t | SPI_SlaveTransferGetCount (SPI_Type *base, spi_slave_handle_t *handle, size_t *count) |
| | Get the bytes of SPI Interrupt transferred. More...
|
| |
| static void | SPI_SlaveTransferAbort (SPI_Type *base, spi_slave_handle_t *handle) |
| | Abort a SPI slave transfer using interrupt. More...
|
| |
| static void | SPI_SlaveTransferHandleIRQ (SPI_Type *base, spi_slave_handle_t *handle) |
| | Interrupt handler for SPI slave. More...
|
| |
The KSDK provides a periphera driver for the Serial Peripheral Interface (SPI) module of Kinetis devices.
Overview
SPI driver includes functional APIs and transactional APIs.
Functional APIs are feature/property target low level APIs. Functional APIs can be used for SPI initialization/configuration/operation for optimization/customization purpose. Using the functional API requires the knowledge of the SPI peripheral and how to organize functional APIs to meet the application requirements. All functional API use the peripheral base address as the first parameter. SPI functional operation groups provide the functional API set.
Transactional APIs are transaction target high level APIs. Transactional APIs can be used to enable the peripheral and in the application if the code size and performance of transactional APIs satisfy the requirements. If the code size and performance are a critical requirement, see the transactional API implementation and write a custom code. All transactional APIs use the spi_handle_t as the first parameter. Initialize the handle by calling the SPI_MasterTransferCreateHandle() or SPI_SlaveTransferCreateHandle() API.
Transactional APIs support asynchronous transfer. This means that the functions SPI_MasterTransferNonBlocking() and SPI_SlaveTransferNonBlocking() set up the interrupt for data transfer. When the transfer completes, the upper layer is notified through a callback function with the kStatus_SPI_Idle status.
Function groups
Initialization and deinitialization
The SPI_MasterInit() and SPI_SlaveInit() functions initialize SPI to be a master or slave with specific configurations. The SPI_MasterGetDefaultConfig() and SPI_SlaveGetDefaultConfig() functions get the default configurations.
Status
Provides functions to get and clear the SPI status.
Interrupt
Provides functions to enable/disable SPI interrupts.
DMA Control
Provides functions to enable/disable SPI to generate the DMA request if the chip support SPI DMA feature.
Bus Operations
Provides functions to set baud rate, enable/disable transfer, to write/read data.
Transactional
Provides functions to transfer data using an interrupt or a DMA method.
Typical use case
SPI master transfer using an interrupt method
#define BUFFER_LEN (64)
spi_master_handle_t spiHandle;
volatile bool isFinished = false;
const uint8_t sendData[BUFFER_LEN] = [......];
uint8_t receiveBuff[BUFFER_LEN];
void SPI_UserCallback(SPI_Type *base, spi_master_handle_t *handle,
status_t status,
void *userData)
{
isFinished = true;
}
{
while (!isFinished)
{
}
}
SPI Send/receive using a DMA method
#define BUFFER_LEN (64)
spi_dma_handle_t spiHandle;
dma_handle_t g_spiTxDmaHandle;
dma_handle_t g_spiRxDmaHandle;
spi_config_t masterConfig;
volatile bool isFinished;
uint8_t sendData[BUFFER_LEN] = ...;
uint8_t receiveBuff[BUFFER_LEN];
void SPI_UserCallback(SPI_Type *base, spi_dma_handle_t *handle,
status_t status,
void *userData)
{
isFinished = true;
}
{
DMAMUX_Init(DMAMUX0);
DMAMUX_SetSource(DMAMUX0, SPI_TX_DMA_CHANNEL, SPI_TX_DMA_REQUEST);
DMAMUX_EnableChannel(DMAMUX0, SPI_TX_DMA_CHANNEL);
DMAMUX_SetSource(DMAMUX0, SPI_RX_DMA_CHANNEL, SPI_RX_DMA_REQUEST);
DMAMUX_EnableChannel(DMAMUX0, SPI_RX_DMA_CHANNEL);
DMA_Init(DMA0);
DMA_CreateHandle(&g_spiTxDmaHandle, DMA0, SPI_TX_DMA_CHANNEL);
DMA_CreateHandle(&g_spiRxDmaHandle, DMA0, SPI_RX_DMA_CHANNEL);
SPI_MasterTransferCreateHandleDMA(SPI0, spiHandle, &g_spiTxDmaHandle, &g_spiRxDmaHandle, SPI_UserCallback, NULL);
SPI_MasterTransferDMA(SPI0, &spiHandle, &xfer);
while (!isFinished)
{
}
}
| struct spi_master_config_t |
SPI master user configure structure.
| struct spi_slave_config_t |
SPI slave user configure structure.
| Data Fields |
|
size_t |
dataSize |
Transfer bytes
|
|
uint32_t |
flags |
SPI control flag, useless to SPI.
|
|
uint8_t * |
rxData |
Receive buffer
|
|
uint8_t * |
txData |
Send buffer
|
| struct _spi_master_handle |
SPI transfer handle structure.
| Data Fields |
|
uint8_t |
bytePerFrame |
SPI mode, 2bytes or 1byte in a frame
|
|
spi_master_callback_t |
callback |
SPI callback
|
|
uint8_t *volatile |
rxData |
Receive buffer
|
|
volatile size_t |
rxRemainingBytes |
Receive data remaining in bytes
|
|
volatile uint32_t |
state |
SPI interanl state
|
|
size_t |
transferSize |
Bytes to be transferred
|
|
uint8_t *volatile |
txData |
Transfer buffer
|
|
volatile size_t |
txRemainingBytes |
Send data remaining in bytes
|
|
void * |
userData |
Cllback parameter
|
|
uint8_t |
watermark |
Watermark value for SPI transfer
|
SPI dma source.
| Enumerator |
|---|
| kSPI_TxDmaEnable |
Tx dma request source
|
| kSPI_RxDmaEnable |
Rx dma request source
|
| kSPI_DmaAllEnable |
All dma request source
|
SPI status flags.
| Enumerator |
|---|
| kSPI_RxBufferFullFlag |
Read buffer full flag
|
| kSPI_MatchFlag |
Match flag
|
| kSPI_TxBufferEmptyFlag |
Transmit buffer empty flag
|
| kSPI_ModeFaultFlag |
Mode fault flag
|
| kSPI_RxFifoNearFullFlag |
Rx FIFO near full
|
| kSPI_TxFifoNearEmptyFlag |
Tx FIFO near empty
|
| kSPI_RxFifoFullFlag |
Rx fifo full
|
| kSPI_TxFifoEmptyFlag |
Tx fifo empty
|
| kSPI_TxFifoError |
Tx FIFO error
|
| kSPI_RxFifoError |
Rx FIFO Overflow
|
| kSPI_TxOverflow |
Tx FIFO Overflow
|
| kSPI_RxOverflow |
Rx FIFO Overflow
|
SPI interrupt sources.
| Enumerator |
|---|
| kSPI_RxFullAndModfInterruptEnable |
Receive buffer full (SPRF) and mode fault (MODF) interrupt
|
| kSPI_TxEmptyInterruptEnable |
Transmit buffer empty interrupt
|
| kSPI_MatchInterruptEnable |
Match interrupt
|
| kSPI_RxFifoNearFullInterruptEnable |
Receive FIFO nearly full interrupt
|
| kSPI_TxFifoNearEmptyInterruptEnable |
Transmit FIFO nearly empty interrupt
|
Return status for the SPI driver.
| Enumerator |
|---|
| kStatus_SPI_Busy |
SPI bus is busy
|
| kStatus_SPI_Idle |
SPI is idle
|
| kStatus_SPI_Error |
SPI error
|
SPI clock phase configuration.
| Enumerator |
|---|
| kSPI_ClockPhaseFirstEdge |
First edge on SPSCK occurs at the middle of the first cycle of a data transfer.
|
| kSPI_ClockPhaseSecondEdge |
First edge on SPSCK occurs at the start of the first cycle of a data transfer.
|
SPI clock polarity configuration.
| Enumerator |
|---|
| kSPI_ClockPolarityActiveHigh |
Active-high SPI clock (idles low).
|
| kSPI_ClockPolarityActiveLow |
Active-low SPI clock (idles high).
|
SPI data length mode options.
| Enumerator |
|---|
| kSPI_8BitMode |
8-bit data transmission mode
|
| kSPI_16BitMode |
16-bit data transmission mode
|
SPI pin mode options.
| Enumerator |
|---|
| kSPI_PinModeNormal |
Pins operate in normal, single-direction mode.
|
| kSPI_PinModeInput |
Bidirectional mode. Master: MOSI pin is input; Slave: MISO pin is input.
|
| kSPI_PinModeOutput |
Bidirectional mode. Master: MOSI pin is output; Slave: MISO pin is output.
|
SPI RX FIFO watermark settings.
| Enumerator |
|---|
| kSPI_RxFifoThreeFourthsFull |
SPI rx watermark at 3/4 FIFO size
|
| kSPI_RxFifoOneHalfFull |
SPI rx watermark at 1/2 FIFO size
|
SPI data shifter direction options.
| Enumerator |
|---|
| kSPI_MsbFirst |
Data transfers start with most significant bit.
|
| kSPI_LsbFirst |
Data transfers start with least significant bit.
|
SPI slave select output mode options.
| Enumerator |
|---|
| kSPI_SlaveSelectAsGpio |
Slave select pin configured as GPIO.
|
| kSPI_SlaveSelectFaultInput |
Slave select pin configured for fault detection.
|
| kSPI_SlaveSelectAutomaticOutput |
Slave select pin configured for automatic SPI output.
|
SPI TX FIFO watermark settings.
| Enumerator |
|---|
| kSPI_TxFifoOneFourthEmpty |
SPI tx watermark at 1/4 FIFO size
|
| kSPI_TxFifoOneHalfEmpty |
SPI tx watermark at 1/2 FIFO size
|
SPI FIFO write-1-to-clear interrupt flags.
| Enumerator |
|---|
| kSPI_RxFifoFullClearInterrupt |
Receive FIFO full interrupt
|
| kSPI_TxFifoEmptyClearInterrupt |
Transmit FIFO empty interrupt
|
| kSPI_RxNearFullClearInterrupt |
Receive FIFO nearly full interrupt
|
| kSPI_TxNearEmptyClearInterrupt |
Transmit FIFO nearly empty interrupt
|
| static void SPI_ClearInterrupt |
( |
SPI_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
Clear the interrupt if enable INCTLR.
- Parameters
-
| base | SPI base pointer |
| interrupt | Interrupt need to be cleared The parameter could be any combination of the following values:
- kSPIRxFifoFullClearInt
- kSPITxFifoEmptyClearInt
- kSPIRxNearFullClearInt
- kSPITxNearEmptyClearInt
|
| void SPI_Deinit |
( |
SPI_Type * |
base | ) |
|
De-initialize SPI.
Call this API will reset the SPI module, gate the spi clock , so the SPI module can not work unless call SPI_MasterInit/SPI_SlaveInit to initialize module.
- Parameters
-
| void SPI_DisableInterrupts |
( |
SPI_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
Disable interrupt for SPI.
- Parameters
-
| base | SPI base pointer |
| mask | SPI interrupt source. The parameter could be any combination of the following values:
- kSPI_RxFullAndModfInterruptEnable
- kSPI_TxEmptyInterruptEnable
- kSPI_MatchInterruptEnable
- kSPI_RxFifoNearFullInterruptEnable
- kSPI_TxFifoNearEmptyInterruptEnable
|
| static void SPI_Enable |
( |
I2C_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
Enable or disables the SPI.
- Parameters
-
| base | SPI base pointer |
| enable | pass true to enable module, false to disable module |
| static void SPI_EnableDMA |
( |
SPI_Type * |
base, |
|
|
uint32_t |
mask, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
Enable dma source for SPI.
- Parameters
-
| base | SPI base pointer |
| source | SPI dma source. |
| enable | True means enable DMA, false means disable DMA |
| void SPI_EnableFIFO |
( |
SPI_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
Enable or Disable FIFO if there is FIFO.
- Parameters
-
| base | SPI base pointer |
| enable | True means enable FIFO, false means disable FIFO. |
| void SPI_EnableInterrupts |
( |
SPI_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
Enable interrupt for SPI.
- Parameters
-
| base | SPI base pointer |
| mask | SPI interrupt source. The parameter could be any combination of the following values:
- kSPI_RxFullAndModfInterruptEnable
- kSPI_TxEmptyInterruptEnable
- kSPI_MatchInterruptEnable
- kSPI_RxFifoNearFullInterruptEnable
- kSPI_TxFifoNearEmptyInterruptEnable
|
| static uint32_t SPI_GetDataRegisterAddress |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
Get SPI tx/rx data register address.
This API is used to provide transfer address for SPI DMA transfer configuration.
- Parameters
-
- Returns
- data register address
| uint32_t SPI_GetStatusFlags |
( |
SPI_Type * |
base | ) |
|
Get the status flag.
- Parameters
-
- Returns
- SPI Status, use status flag to AND _spi_flags could get the related status.
Set the SPI master configuration structure to default values.
The purpose of this API is to get the config structure initialized for use in SPI_MasterInit(). User may use the initialized structure unchanged in SPI_MasterInit(), or modify some fields of the structure before calling SPI_MasterInit(). After calling this API, The master is ready to transfer. Example:
1 spi_master_config_t config;
2 SPI_MasterGetDefaultConfig(&config);
- Parameters
-
| config | pointer to master config structure |
| void SPI_MasterInit |
( |
SPI_Type * |
base, |
|
|
const spi_master_config_t * |
config, |
|
|
uint32_t |
srcClock_Hz |
|
) |
| |
Initialize SPI with master configuration.
The configuration structure can be filled by user from scratch, or be set with default values by SPI_MasterGetDefaultConfig(). After calling this API, the slave is ready to transfer. Example
1 spi_master_config_t config = {
2 .baudRate_Bps = 400000,
5 SPI_MasterInit(SPI0, &config);
- Parameters
-
| base | SPI base pointer |
| config | pointer to master config structure |
| srcClock_Hz | Source clock frequency. |
| void SPI_MasterSetBaudRate |
( |
SPI_Type * |
base, |
|
|
uint32_t |
baudRate_Bps, |
|
|
uint32_t |
srcClock_Hz |
|
) |
| |
Set Baud rate for SPI transfer, this only used in master.
- Parameters
-
| base | SPI base pointer |
| baudRate_Bps | Buad Rate needed in Hz. |
| srcClock_Hz | SPI source clock frequency in Hz. |
| void SPI_MasterTransferAbort |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle |
|
) |
| |
Abort a SPI transfer using interrupt.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to SPI transfer handle, this should be a static variable. |
Transfer a block of data in polling way.
- Parameters
-
| base | SPI base pointer |
| xfer | pointer to spi_xfer_config_t structure |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| void SPI_MasterTransferCreateHandle |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle, |
|
|
spi_master_callback_t |
callback, |
|
|
void * |
userData |
|
) |
| |
Initialize the SPI master handle.
This function initializes the SPI master handle which can be used for other SPI master transactional APIs. Usually, for a specified SPI instance, user need only call this API once to get the initialized handle.
- Parameters
-
| base | SPI peripheral base address. |
| handle | SPI handle pointer. |
| callback | Callback function. |
| userData | User data. |
| status_t SPI_MasterTransferGetCount |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle, |
|
|
size_t * |
count |
|
) |
| |
Get the bytes of SPI Interrupt transferred.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to SPI transfer handle, this should be a static variable. |
| count | Transferred bytes of SPI master. |
- Return values
-
| kStatus_SPI_Success | Succeed get the transfer count. |
| kStatus_NoTransferInProgress | There is not a non-blocking transaction currently in progress. |
| void SPI_MasterTransferHandleIRQ |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle |
|
) |
| |
Interrupt handler for SPI.
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_master_handle_t structure which stores the transfer state. |
| status_t SPI_MasterTransferNonBlocking |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle, |
|
|
spi_transfer_t * |
xfer |
|
) |
| |
Performs a non-blocking SPI interrupt transfer.
- Note
- Calling the API will immediately return after transfer intialize finished. Users need to call SPI_GetStatusIRQ() to get the transfer status
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_master_handle_t structure which stores the transfer state |
| xfer | pointer to spi_xfer_config_t structure |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| kStatus_SPI_Busy | SPI is not idle, is running another transfer. |
| uint16_t SPI_ReadData |
( |
SPI_Type * |
base | ) |
|
Get a data from SPI data register.
- Parameters
-
- Returns
- Data in the register.
| static void SPI_SetMatchData |
( |
SPI_Type * |
base, |
|
|
uint32_t |
matchData |
|
) |
| |
|
inlinestatic |
Set match data for SPI.
Match Data is a hardware compare value, when the value received in the SPI receive data buffer equals this hardware compare value, the SPI Match Flag in the S register (S[SPMF]) sets, this can also generate a interrupt if the enable bit sets.
- Parameters
-
| base | SPI base pointer |
| matchData | Match data. |
Set the SPI slave configuration structure to default values.
The purpose of this API is to get the config structure initialized for use in SPI_SlaveInit(). User need to modify some fields of the structure before calling SPI_SlaveInit(). Example:
1 spi_slave_config_t config;
2 SPI_SlaveGetDefaultConfig(&config);
- Parameters
-
| config | pointer to slave config structure |
Initialize SPI with slave configuration.
The configuration structure can be filled by user from scratch, or be set with default values by SPI_SlaveGetDefaultConfig(). After calling this API, the slave is ready to transfer. Example
1 spi_slave_config_t config = {
2 .polarity = kSPIClockPolarity_ActiveHigh;
3 .phase = kSPIClockPhase_FirstEdge;
4 .direction = kSPIMsbFirst;
7 SPI_MasterInit(SPI0, &config);
- Parameters
-
| base | SPI base pointer |
| config | pointer to master config structure |
Abort a SPI slave transfer using interrupt.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to SPI transfer handle, this should be a static variable. |
Initialize the SPI slave handle.
This function initializes the SPI slave handle which can be used for other SPI slave transactional APIs. Usually, for a specified SPI instance, user need only call this API once to get the initialized handle.
- Parameters
-
| base | SPI peripheral base address. |
| handle | SPI handle pointer. |
| callback | Callback function. |
| userData | User data. |
Get the bytes of SPI Interrupt transferred.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to SPI transfer handle, this should be a static variable. |
| count | Transferred bytes of SPI slave. |
- Return values
-
| kStatus_SPI_Success | Succeed get the transfer count. |
| kStatus_NoTransferInProgress | There is not a non-blocking transaction currently in progress. |
Interrupt handler for SPI slave.
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_slave_handle_t structure which stores the transfer state |
Performs a non-blocking SPI slave interrupt transfer.
- Note
- Calling the API will immediately return after transfer intialize finished. Users need to call SPI_GetStatusIRQ() to get the transfer status.
-
If use SPI with FIFO to do interrupt transfer, the transfer size shall be the integer times of watermark. Or the last data may lost as it cannot generate interrupt request. Users can also call functional API to get the last several receive data.
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_master_handle_t structure which stores the transfer state |
| xfer | pointer to spi_xfer_config_t structure |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| kStatus_SPI_Busy | SPI is not idle, is running another transfer. |
| void SPI_WriteBlocking |
( |
SPI_Type * |
base, |
|
|
uint8_t * |
buffer, |
|
|
size_t |
size |
|
) |
| |
Sends a buffer of data bytes in blocking way.
- Note
- This function blocks via polling until all bytes have been sent.
- Parameters
-
| base | SPI base pointer |
| buffer | The data bytes to send |
| size | The number of data bytes to send |
| void SPI_WriteData |
( |
SPI_Type * |
base, |
|
|
uint16_t |
data |
|
) |
| |
Write a data into SPI data register.
- Parameters
-
| base | SPI base pointer |
| data | needs to be write. |