MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the spi Cortex Microcontroller Software Interface Standard (CMSIS) driver. And this driver defines generic peripheral driver interfaces for middleware making it reusable across a wide range of supported microcontroller devices. The API connects microcontroller peripherals with middleware that implements for example communication stacks, file systems, or graphic user interfaces. More information and usage methord please refer to http://www.keil.com/pack/doc/cmsis/Driver/html/index.html.

Function groups

SPI CMSIS GetVersion Operation

This function group will return the DSPI CMSIS Driver version to user.

SPI CMSIS GetCapabilities Operation

This function group will return the capabilities of this driver.

SPI CMSIS Initialize and Uninitialize Operation

This function will initialize and uninitialize the instance in master mode or slave mode. And this API must be called before you configure an instance or after you Deinit an instance.The right steps to start an instance is that you must initialize the instance which been slected firstly,then you can power on the instance.After these all have been done,you can configure the instance by using control operation.If you want to Uninitialize the instance, you must power off the instance first.

SPI CMSIS Transfer Operation

This function group controls the transfer, master send/receive data, and slave send/receive data.

SPI CMSIS Status Operation

This function group gets the spi transfer status.

SPI CMSIS Control Operation

This function can select instance as master mode or slave mode, set baudrate for master mode transfer, get current baudrate of master mode transfer,set transfer data bits and set other control command.

Typical use case

Master Operation

/* Variables */
uint8_t masterRxData[TRANSFER_SIZE] = {0U};
uint8_t masterTxData[TRANSFER_SIZE] = {0U};
/*DSPI master init*/
Driver_SPI0.Initialize(DSPI_MasterSignalEvent_t);
Driver_SPI0.PowerControl(ARM_POWER_FULL);
Driver_SPI0.Control(ARM_SPI_MODE_MASTER, TRANSFER_BAUDRATE);
/* Start master transfer */
Driver_SPI0.Transfer(masterTxData, masterRxData, TRANSFER_SIZE);
/* Master power off */
Driver_SPI0.PowerControl(ARM_POWER_OFF);
/* Master uninitialize */
Driver_SPI0.Uninitialize();

Slave Operation

/* Variables */
uint8_t slaveRxData[TRANSFER_SIZE] = {0U};
uint8_t slaveTxData[TRANSFER_SIZE] = {0U};
/*DSPI slave init*/
Driver_SPI2.Initialize(DSPI_SlaveSignalEvent_t);
Driver_SPI2.PowerControl(ARM_POWER_FULL);
Driver_SPI2.Control(ARM_SPI_MODE_SLAVE, false);
/* Start slave transfer */
Driver_SPI2.Transfer(slaveTxData, slaveRxData, TRANSFER_SIZE);
/* slave power off */
Driver_SPI2.PowerControl(ARM_POWER_OFF);
/* slave uninitialize */
Driver_SPI2.Uninitialize();

This section describes the programming interface of the SPI DMA driver.

Files

file  fsl_spi.h
 

Data Structures

struct  spi_fifo_config_t
 SPI fifo user configure structure. More...
 
struct  spi_delay_config_t
 SPI delay time configure structure. More...
 
struct  spi_master_config_t
 SPI master user configure structure. More...
 
struct  spi_slave_config_t
 SPI slave user configure structure. More...
 
struct  spi_transfer_t
 SPI transfer structure. More...
 
struct  spi_half_duplex_transfer_t
 SPI half-duplex(master only) transfer structure. More...
 
struct  spi_config_t
 Internal configuration structure used in 'spi' and 'spi_dma' driver. More...
 
struct  spi_master_handle_t
 SPI transfer handle structure. More...
 

Macros

#define SPI_DUMMYDATA   (0xFFU)
 SPI dummy transfer data, the data is sent while txBuff is NULL. More...
 

Typedefs

typedef spi_master_handle_t spi_slave_handle_t
 Slave handle type.
 
typedef void(* spi_master_callback_t )(SPI_Type *base, spi_master_handle_t *handle, status_t status, void *userData)
 SPI master callback for finished transmit.
 
typedef void(* spi_slave_callback_t )(SPI_Type *base, spi_slave_handle_t *handle, status_t status, void *userData)
 SPI slave callback for finished transmit.
 

Enumerations

enum  spi_xfer_option_t {
  kSPI_FrameDelay = (SPI_TXDATCTL_EOF_MASK),
  kSPI_FrameAssert = (SPI_TXDATCTL_EOT_MASK),
  kSPI_ReceiveIgnore = (SPI_TXDATCTL_RXIGNORE_MASK)
}
 SPI transfer option. More...
 
enum  spi_shift_direction_t {
  kSPI_MsbFirst = 0U,
  kSPI_LsbFirst = 1U
}
 SPI data shifter direction options. More...
 
enum  spi_clock_polarity_t {
  kSPI_ClockPolarityActiveHigh = 0x0U,
  kSPI_ClockPolarityActiveLow = 0x1U
}
 SPI clock polarity configuration. More...
 
enum  spi_clock_phase_t {
  kSPI_ClockPhaseFirstEdge = 0x0U,
  kSPI_ClockPhaseSecondEdge = 0x1U
}
 SPI clock phase configuration. More...
 
enum  spi_fifo_direction_t {
  kSPI_FifoTx = 1U,
  kSPI_FifoRx = 2U
}
 SPI FIFO driection. More...
 
enum  spi_data_width_t {
  kSPI_Data1Bits = 0,
  kSPI_Data2Bits = 1,
  kSPI_Data3Bits = 2,
  kSPI_Data4Bits = 3,
  kSPI_Data5Bits = 4,
  kSPI_Data6Bits = 5,
  kSPI_Data7Bits = 6,
  kSPI_Data8Bits = 7,
  kSPI_Data9Bits = 8,
  kSPI_Data10Bits = 9,
  kSPI_Data11Bits = 10,
  kSPI_Data12Bits = 11,
  kSPI_Data13Bits = 12,
  kSPI_Data14Bits = 13,
  kSPI_Data15Bits = 14,
  kSPI_Data16Bits = 15
}
 Transfer data width. More...
 
enum  spi_ssel_t {
  kSPI_Ssel0 = 0,
  kSPI_Ssel1 = 1,
  kSPI_Ssel2 = 2,
  kSPI_Ssel3 = 3
}
 Slave select. More...
 
enum  spi_spol_t
 ssel polarity
 
enum  _spi_status {
  kStatus_SPI_Busy = MAKE_STATUS(kStatusGroup_LPC_SPI, 0),
  kStatus_SPI_Idle = MAKE_STATUS(kStatusGroup_LPC_SPI, 1),
  kStatus_SPI_Error = MAKE_STATUS(kStatusGroup_LPC_SPI, 2),
  kStatus_SPI_BaudrateNotSupport
}
 SPI transfer status. More...
 
enum  _spi_interrupt_enable {
  kSPI_RxReadyInterruptEnable = SPI_INTENSET_RXRDYEN_MASK,
  kSPI_TxReadyInterruptEnable = SPI_INTENSET_TXRDYEN_MASK,
  kSPI_RxOverrunInterruptEnable = SPI_INTENSET_RXOVEN_MASK,
  kSPI_TxUnderrunInterruptEnable = SPI_INTENSET_TXUREN_MASK,
  kSPI_SlaveSelectAssertInterruptEnable = SPI_INTENSET_SSAEN_MASK,
  kSPI_SlaveSelectDeassertInterruptEnable = SPI_INTENSET_SSDEN_MASK,
  kSPI_MasterIdleInterruptEnable = SPI_INTENSET_MSTIDLEEN_MASK
}
 SPI interrupt sources. More...
 
enum  _spi_fifo_interrupt_enable {
  kSPI_RxFifoThresholdInterruptEnable,
  kSPI_TxFifoThresholdInterruptEnable,
  kSPI_RxFifoTimeoutInterruptEnable = VFIFO_SPI_CTLSETSPI_RXTIMEOUTINTEN_MASK
}
 SPI FIFO interrupt sources. More...
 
enum  _spi_status_flags {
  kSPI_RxReadyFlag = SPI_STAT_RXRDY_MASK,
  kSPI_TxReadyFlag = SPI_STAT_TXRDY_MASK,
  kSPI_RxOverrunFlag = SPI_STAT_RXOV_MASK,
  kSPI_TxUnderrunFlag = SPI_STAT_TXUR_MASK,
  kSPI_SlaveSelectAssertFlag = SPI_STAT_SSA_MASK,
  kSPI_SlaveSelectDeassertFlag = SPI_STAT_SSD_MASK,
  kSPI_StallFlag = SPI_STAT_STALLED_MASK,
  kSPI_EndTransferFlag = SPI_STAT_ENDTRANSFER_MASK,
  kSPI_MasterIdleFlag = SPI_STAT_MSTIDLE_MASK
}
 SPI status flags. More...
 
enum  _spi_fifo_status_flags {
  kSPI_RxFifoThresholdFlag = (VFIFO_SPI_STATSPI_RXTH_MASK),
  kSPI_TxFifoThresholdFlag = (VFIFO_SPI_STATSPI_TXTH_MASK),
  kSPI_RxFifoTimeOutFlag = (VFIFO_SPI_STATSPI_RXTIMEOUT_MASK),
  kSPI_FifoBusErrorFlag = (VFIFO_SPI_STATSPI_BUSERR_MASK),
  kSPI_RxFifoEmptyFlag = (VFIFO_SPI_STATSPI_RXEMPTY_MASK),
  kSPI_TxFifoEmptyFlag = (VFIFO_SPI_STATSPI_TXEMPTY_MASK)
}
 SPI FIFO status flags. More...
 

Functions

uint32_t SPI_GetInstance (SPI_Type *base)
 Returns instance number for SPI peripheral base address. More...
 

Variables

volatile uint8_t s_dummyData []
 Global variable for dummy data value setting. More...
 

Driver version

#define FSL_SPI_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
 SPI driver version 2.0.2. More...
 

Initialization and deinitialization

void SPI_MasterGetDefaultConfig (spi_master_config_t *config)
 Sets the SPI master configuration structure to default values. More...
 
status_t SPI_MasterInit (SPI_Type *base, const spi_master_config_t *config, uint32_t srcClock_Hz)
 Initializes the SPI with master configuration. More...
 
void SPI_SlaveGetDefaultConfig (spi_slave_config_t *config)
 Sets the SPI slave configuration structure to default values. More...
 
status_t SPI_SlaveInit (SPI_Type *base, const spi_slave_config_t *config)
 Initializes the SPI with slave configuration. More...
 
void SPI_Deinit (SPI_Type *base)
 De-initializes the SPI. More...
 
static void SPI_Enable (SPI_Type *base, bool enable)
 Enable or disable the SPI Master or Slave. More...
 

Status

static uint32_t SPI_GetStatusFlags (SPI_Type *base)
 Gets the status flag. More...
 
uint32_t SPI_GetFifoStatusFlags (SPI_Type *base)
 Gets the FIFO status flag for SPI transfer. More...
 
void SPI_ClearFifoStatusFlags (SPI_Type *base, uint32_t mask)
 Clear the FIFO status flag for SPI transfer. More...
 

Interrupts

static void SPI_EnableInterrupts (SPI_Type *base, uint32_t irqs)
 Enables the interrupt for the SPI. More...
 
static void SPI_DisableInterrupts (SPI_Type *base, uint32_t irqs)
 Disables the interrupt for the SPI. More...
 
void SPI_EnableFifoInterrupts (SPI_Type *base, uint32_t irqs)
 Enables the FIFO interrupt for the SPI. More...
 
void SPI_DisableFifoInterrupts (SPI_Type *base, uint32_t irqs)
 Disables the FIFO interrupt for the SPI. More...
 

Bus Operations

static bool SPI_IsMaster (SPI_Type *base)
 Returns whether the SPI module is in master mode. More...
 
void * SPI_GetConfig (SPI_Type *base)
 Returns the configurations. More...
 
status_t SPI_MasterSetBaud (SPI_Type *base, uint32_t baudrate_Bps, uint32_t srcClock_Hz)
 Sets the baud rate for SPI transfer. More...
 
void SPI_WriteData (SPI_Type *base, uint16_t data, uint32_t configFlags)
 Writes a data into the SPI data register. More...
 
uint32_t SPI_ReadData (SPI_Type *base)
 Gets a data from the SPI data register. More...
 
void SPI_SetTransferDelay (SPI_Type *base, const spi_delay_config_t *config)
 Set delay time for transfer. More...
 
void SPI_SetDummyData (SPI_Type *base, uint8_t dummyData)
 Set up the dummy data. More...
 

FIFO Operations

void SPI_EnableFifo (SPI_Type *base, const spi_fifo_config_t *config)
 Enable FIFO for SPI. More...
 
void SPI_DisableFifo (SPI_Type *base)
 Disable FIFO for SPI. More...
 
bool SPI_IsTxFifoEnabled (SPI_Type *base)
 Is TX FIFO enabled. More...
 
bool SPI_IsRxFifoEnabled (SPI_Type *base)
 Is RX FIFO enabled. More...
 
void SPI_FifoFlush (SPI_Type *base, uint32_t direction)
 Flush the FIFO buffer. More...
 

Transactional

status_t SPI_MasterTransferCreateHandle (SPI_Type *base, spi_master_handle_t *handle, spi_master_callback_t callback, void *userData)
 Initializes the SPI master handle. More...
 
status_t SPI_MasterTransferBlocking (SPI_Type *base, spi_transfer_t *xfer)
 Transfers a block of data using a polling method. 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_MasterHalfDuplexTransferBlocking (SPI_Type *base, spi_half_duplex_transfer_t *xfer)
 Transfers a block of data using a polling method. More...
 
status_t SPI_MasterHalfDuplexTransferNonBlocking (SPI_Type *base, spi_master_handle_t *handle, spi_half_duplex_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)
 Gets the master transfer count. More...
 
void SPI_MasterTransferAbort (SPI_Type *base, spi_master_handle_t *handle)
 SPI master aborts a transfer using an interrupt. More...
 
void SPI_MasterTransferHandleIRQ (SPI_Type *base, spi_master_handle_t *handle)
 Interrupts the handler for the SPI. More...
 
status_t SPI_SlaveTransferCreateHandle (SPI_Type *base, spi_slave_handle_t *handle, spi_slave_callback_t callback, void *userData)
 Initializes the SPI slave handle. More...
 
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)
 Gets the slave transfer count. More...
 
static void SPI_SlaveTransferAbort (SPI_Type *base, spi_slave_handle_t *handle)
 SPI slave aborts a transfer using an interrupt. More...
 
void SPI_SlaveTransferHandleIRQ (SPI_Type *base, spi_slave_handle_t *handle)
 Interrupts a handler for the SPI slave. More...
 

Data Structure Documentation

struct spi_fifo_config_t

Data Fields

bool enableTxFifo
 Enable transmit FIFO.
 
bool enableRxFifo
 Enable receive FIFO.
 
uint8_t txFifoSize
 Configure txFIFO size.
 
uint8_t rxFifoSize
 Configure rxFIFO size.
 
uint8_t txFifoThreshold
 txFIFO threshold
 
uint8_t rxFifoThreshold
 rxFIFO threshold
 
struct spi_delay_config_t

Data Fields

uint8_t preDelay
 Delay between SSEL assertion and the beginning of transfer. More...
 
uint8_t postDelay
 Delay between the end of transfer and SSEL deassertion. More...
 
uint8_t frameDelay
 Delay between frame to frame. More...
 
uint8_t transferDelay
 Delay between transfer to transfer. More...
 

Field Documentation

uint8_t spi_delay_config_t::preDelay
uint8_t spi_delay_config_t::postDelay
uint8_t spi_delay_config_t::frameDelay
uint8_t spi_delay_config_t::transferDelay
struct spi_master_config_t

Data Fields

bool enableLoopback
 Enable loopback for test purpose.
 
bool enableMaster
 Enable SPI at initialization time.
 
spi_clock_polarity_t polarity
 Clock polarity.
 
spi_clock_phase_t phase
 Clock phase.
 
spi_shift_direction_t direction
 MSB or LSB.
 
uint32_t baudRate_Bps
 Baud Rate for SPI in Hz.
 
spi_data_width_t dataWidth
 Width of the data.
 
spi_ssel_t sselNum
 Slave select number.
 
spi_spol_t sselPol
 Configure active CS polarity.
 
spi_fifo_config_t fifoConfig
 Configure for fifo. More...
 
spi_delay_config_t delayConfig
 Configure for delay time. More...
 

Field Documentation

spi_fifo_config_t spi_master_config_t::fifoConfig
spi_delay_config_t spi_master_config_t::delayConfig
struct spi_slave_config_t

Data Fields

bool enableSlave
 Enable SPI at initialization time.
 
spi_clock_polarity_t polarity
 Clock polarity.
 
spi_clock_phase_t phase
 Clock phase.
 
spi_shift_direction_t direction
 MSB or LSB.
 
spi_data_width_t dataWidth
 Width of the data.
 
spi_spol_t sselPol
 Configure active CS polarity.
 
spi_fifo_config_t fifoConfig
 Configure for fifo. More...
 

Field Documentation

spi_fifo_config_t spi_slave_config_t::fifoConfig
struct spi_transfer_t

Data Fields

uint8_t * txData
 Send buffer.
 
uint8_t * rxData
 Receive buffer.
 
uint32_t configFlags
 Additional option to control transfer, spi_xfer_option_t. More...
 
size_t dataSize
 Transfer bytes.
 

Field Documentation

uint32_t spi_transfer_t::configFlags
struct spi_half_duplex_transfer_t

Data Fields

uint8_t * txData
 Send buffer.
 
uint8_t * rxData
 Receive buffer.
 
size_t txDataSize
 Transfer bytes for transmit.
 
size_t rxDataSize
 Transfer bytes.
 
uint32_t configFlags
 Transfer configuration flags, spi_xfer_option_t. More...
 
bool isPcsAssertInTransfer
 If PCS pin keep assert between transmit and receive. More...
 
bool isTransmitFirst
 True for transmit first and false for receive first. More...
 

Field Documentation

uint32_t spi_half_duplex_transfer_t::configFlags
bool spi_half_duplex_transfer_t::isPcsAssertInTransfer

true for assert and false for deassert.

bool spi_half_duplex_transfer_t::isTransmitFirst
struct spi_config_t
struct _spi_master_handle

Master handle type.

Data Fields

uint8_t *volatile txData
 Transfer buffer.
 
uint8_t *volatile rxData
 Receive buffer.
 
volatile size_t txRemainingBytes
 Number of data to be transmitted [in bytes].
 
volatile size_t rxRemainingBytes
 Number of data to be received [in bytes].
 
size_t totalByteCount
 A number of transfer bytes.
 
volatile uint32_t state
 SPI internal state.
 
spi_master_callback_t callback
 SPI callback.
 
void * userData
 Callback parameter.
 
uint8_t dataWidth
 Width of the data [Valid values: 1 to 16].
 
uint8_t sselNum
 Slave select number to be asserted when transferring data [Valid values: 0 to 3].
 
bool isTxFifoEnabled
 Is transmit FIFO enabled. More...
 
bool isRxFifoEnabled
 Is receive FIFO enabled. More...
 
uint8_t txFifoThreshold
 txFIFO threshold
 
uint8_t rxFifoThreshold
 rxFIFO threshold
 
uint8_t rxFIFOSize
 rxFIFO size used for protecting received data. More...
 
uint32_t commonCommand
 Command for common transfer bytes. More...
 
uint32_t lastCommand
 Command for last transfer byte. More...
 

Field Documentation

bool spi_master_handle_t::isTxFifoEnabled
bool spi_master_handle_t::isRxFifoEnabled
uint8_t spi_master_handle_t::rxFIFOSize
uint32_t spi_master_handle_t::commonCommand
uint32_t spi_master_handle_t::lastCommand

Macro Definition Documentation

#define FSL_SPI_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
#define SPI_DUMMYDATA   (0xFFU)

Enumeration Type Documentation

Enumerator
kSPI_FrameDelay 

A delay may be inserted, defined in the DLY register.

kSPI_FrameAssert 

SSEL will be deasserted at the end of a transfer.

kSPI_ReceiveIgnore 

Ignore the receive data.

Enumerator
kSPI_MsbFirst 

Data transfers start with most significant bit.

kSPI_LsbFirst 

Data transfers start with least significant bit.

Enumerator
kSPI_ClockPolarityActiveHigh 

Active-high SPI clock (idles low).

kSPI_ClockPolarityActiveLow 

Active-low SPI clock (idles high).

Enumerator
kSPI_ClockPhaseFirstEdge 

First edge on SCK occurs at the middle of the first cycle of a data transfer.

kSPI_ClockPhaseSecondEdge 

First edge on SCK occurs at the start of the first cycle of a data transfer.

Enumerator
kSPI_FifoTx 

FIFO direction for transmit.

kSPI_FifoRx 

FIFO direction for receive.

Enumerator
kSPI_Data1Bits 

1 bits data width,when LEN = 0, the underrun status is not meaningful.

kSPI_Data2Bits 

2 bits data width

kSPI_Data3Bits 

3 bits data width

kSPI_Data4Bits 

4 bits data width

kSPI_Data5Bits 

5 bits data width

kSPI_Data6Bits 

6 bits data width

kSPI_Data7Bits 

7 bits data width

kSPI_Data8Bits 

8 bits data width

kSPI_Data9Bits 

9 bits data width

kSPI_Data10Bits 

10 bits data width

kSPI_Data11Bits 

11 bits data width

kSPI_Data12Bits 

12 bits data width

kSPI_Data13Bits 

13 bits data width

kSPI_Data14Bits 

14 bits data width

kSPI_Data15Bits 

15 bits data width

kSPI_Data16Bits 

16 bits data width

enum spi_ssel_t
Enumerator
kSPI_Ssel0 

Slave select 0.

kSPI_Ssel1 

Slave select 1.

kSPI_Ssel2 

Slave select 2.

kSPI_Ssel3 

Slave select 3.

Enumerator
kStatus_SPI_Busy 

SPI bus is busy.

kStatus_SPI_Idle 

SPI is idle.

kStatus_SPI_Error 

SPI error.

kStatus_SPI_BaudrateNotSupport 

Baudrate is not support in current clock source.

Enumerator
kSPI_RxReadyInterruptEnable 

Rx ready interrupt.

kSPI_TxReadyInterruptEnable 

Tx ready interrupt.

kSPI_RxOverrunInterruptEnable 

Rx overrun interrupt.

kSPI_TxUnderrunInterruptEnable 

Tx underrun interrupt.

kSPI_SlaveSelectAssertInterruptEnable 

Slave select assert interrupt.

kSPI_SlaveSelectDeassertInterruptEnable 

Slave select deassert interrupt.

kSPI_MasterIdleInterruptEnable 

Master idle interrupt.

Enumerator
kSPI_RxFifoThresholdInterruptEnable 

Rx FIFO reach the threshold interrupt.

kSPI_TxFifoThresholdInterruptEnable 

Tx FIFO reach the threshold interrupt.

kSPI_RxFifoTimeoutInterruptEnable 

Rx FIfo timeout interrupt.

Enumerator
kSPI_RxReadyFlag 

Receive ready flag.

kSPI_TxReadyFlag 

Transmit ready flag.

kSPI_RxOverrunFlag 

Receive overrun flag.

kSPI_TxUnderrunFlag 

Transmit underrun flag.

kSPI_SlaveSelectAssertFlag 

Slave select assert flag.

kSPI_SlaveSelectDeassertFlag 

slave select deassert flag.

kSPI_StallFlag 

Stall flag.

kSPI_EndTransferFlag 

End transfer bit.

kSPI_MasterIdleFlag 

Master in idle status flag.

Enumerator
kSPI_RxFifoThresholdFlag 

Receive FIFO threshold reached flag.

kSPI_TxFifoThresholdFlag 

Transmit FIFO threshold reached flag.

kSPI_RxFifoTimeOutFlag 

Receive time out flag.

kSPI_FifoBusErrorFlag 

FIFO bus error flag.

kSPI_RxFifoEmptyFlag 

Receive fifo buffer empty flag.

kSPI_TxFifoEmptyFlag 

transmit fifo buffer empty flag.

Function Documentation

uint32_t SPI_GetInstance ( SPI_Type *  base)
void SPI_MasterGetDefaultConfig ( spi_master_config_t config)

The purpose of this API is to get the configuration 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:

Parameters
configpointer to master config structure
status_t SPI_MasterInit ( SPI_Type *  base,
const spi_master_config_t config,
uint32_t  srcClock_Hz 
)

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

.baudRate_Bps = 500000,
...
};
SPI_MasterInit(SPI0, &config);
Parameters
baseSPI base pointer
configpointer to master configuration structure
srcClock_HzSource clock frequency.
void SPI_SlaveGetDefaultConfig ( spi_slave_config_t config)

The purpose of this API is to get the configuration structure initialized for use in SPI_SlaveInit(). Modify some fields of the structure before calling SPI_SlaveInit(). Example:

Parameters
configpointer to slave configuration structure
status_t SPI_SlaveInit ( SPI_Type *  base,
const spi_slave_config_t config 
)

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

Parameters
baseSPI base pointer
configpointer to slave configuration structure
void SPI_Deinit ( SPI_Type *  base)

Calling this API resets the SPI module, gates the SPI clock. Disable the fifo if enabled. The SPI module can't work unless calling the SPI_MasterInit/SPI_SlaveInit to initialize module.

Parameters
baseSPI base pointer
static void SPI_Enable ( SPI_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSPI base pointer
enableor disable ( true = enable, false = disable)
static uint32_t SPI_GetStatusFlags ( SPI_Type *  base)
inlinestatic
Parameters
baseSPI base pointer
Returns
SPI Status, use status flag to AND _spi_status_flags could get the related status.
uint32_t SPI_GetFifoStatusFlags ( SPI_Type *  base)
Parameters
baseSPI base pointer
Returns
SPI Status, use status flag to AND _spi_fifo_status_flags could get the related status.
void SPI_ClearFifoStatusFlags ( SPI_Type *  base,
uint32_t  mask 
)

Only kSPI_RxFifoTimeOutFlag and kSPI_FifoBusErrorFlag can be cleared.

Parameters
baseSPI base pointer
maskuse status flag to AND _spi_status_flags could get the related status.
static void SPI_EnableInterrupts ( SPI_Type *  base,
uint32_t  irqs 
)
inlinestatic
Parameters
baseSPI base pointer
irqsSPI interrupt source. The parameter can be any combination of the following values:
  • kSPI_RxReadyInterruptEnable
  • kSPI_TxReadyInterruptEnable
static void SPI_DisableInterrupts ( SPI_Type *  base,
uint32_t  irqs 
)
inlinestatic
Parameters
baseSPI base pointer
irqsSPI interrupt source. The parameter can be any combination of the following values:
  • kSPI_RxReadyInterruptEnable
  • kSPI_TxReadyInterruptEnable
void SPI_EnableFifoInterrupts ( SPI_Type *  base,
uint32_t  irqs 
)
Parameters
baseSPI base pointer
irqsSPI interrupt source. The parameter can be any combination of the following values:
  • kSPI_RxFifoThresholdInterruptEnable
  • kSPI_TxFifoThresholdInterruptEnable
void SPI_DisableFifoInterrupts ( SPI_Type *  base,
uint32_t  irqs 
)
Parameters
baseSPI base pointer
irqsSPI interrupt source. The parameter can be any combination of the following values:
  • kSPI_RxFifoThresholdInterruptEnable
  • kSPI_TxFifoThresholdInterruptEnable
static bool SPI_IsMaster ( SPI_Type *  base)
inlinestatic
Parameters
baseSPI peripheral address.
Returns
Returns true if the module is in master mode or false if the module is in slave mode.
void* SPI_GetConfig ( SPI_Type *  base)
Parameters
baseSPI peripheral address.
Returns
return configurations which contain datawidth and SSEL numbers. return data type is a pointer of spi_config_t.
status_t SPI_MasterSetBaud ( SPI_Type *  base,
uint32_t  baudrate_Bps,
uint32_t  srcClock_Hz 
)

This is only used in master.

Parameters
baseSPI base pointer
baudrate_Bpsbaud rate needed in Hz.
srcClock_HzSPI source clock frequency in Hz.
void SPI_WriteData ( SPI_Type *  base,
uint16_t  data,
uint32_t  configFlags 
)
Parameters
baseSPI base pointer
dataneeds to be write.
configFlagstransfer configuration options spi_xfer_option_t
uint32_t SPI_ReadData ( SPI_Type *  base)
Parameters
baseSPI base pointer
Returns
Data in the register.
void SPI_SetTransferDelay ( SPI_Type *  base,
const spi_delay_config_t config 
)
   the delay uint is SPI clock time, maximum value is 0xF.
Parameters
baseSPI base pointer
configconfiguration for delay option spi_delay_config_t.
void SPI_SetDummyData ( SPI_Type *  base,
uint8_t  dummyData 
)
Parameters
baseSPI peripheral address.
dummyDataData to be transferred when tx buffer is NULL.
void SPI_EnableFifo ( SPI_Type *  base,
const spi_fifo_config_t config 
)

This function will enable the FIFO for SPI according to pointer of the configure struct. Note: If this API is called, please reset the baudrate to adapt your demand after this API was called.

Parameters
baseSPI peripheral base address.
configpointer to FIFO configuration structure.
void SPI_DisableFifo ( SPI_Type *  base)

This function will Disable the FIFO for SPI transfer. disable interrupts, clear status flags, disable the TX/RX FIFO, set fifo size to zero. But will not disable the system FIFO, because other instance like USART may using the FIFO.

Parameters
baseSPI peripheral base address.
configpointer to FIFO configuration structure.
bool SPI_IsTxFifoEnabled ( SPI_Type *  base)

This function will return status if the transmit fifo is enabled. true for enabled and false for not enabled.

Parameters
baseSPI peripheral base address.
Returns
true for enabled and false for not enabled.
bool SPI_IsRxFifoEnabled ( SPI_Type *  base)

This function will return status if the receive fifo is enabled. true for enabled and false for not enabled.

Parameters
baseSPI peripheral base address.
Returns
true for enabled and false for not enabled.
void SPI_FifoFlush ( SPI_Type *  base,
uint32_t  direction 
)

This function will Flush tHE fifo buffer.

Parameters
baseSPI peripheral base address.
directionthe fifo direction need to flushed, Tx FIFO or Rx FIFO.
status_t SPI_MasterTransferCreateHandle ( SPI_Type *  base,
spi_master_handle_t *  handle,
spi_master_callback_t  callback,
void *  userData 
)

This function initializes the SPI master handle which can be used for other SPI master transactional APIs. Usually, for a specified SPI instance, call this API once to get the initialized handle.

Parameters
baseSPI peripheral base address.
handleSPI handle pointer.
callbackCallback function.
userDataUser data.
status_t SPI_MasterTransferBlocking ( SPI_Type *  base,
spi_transfer_t xfer 
)
Parameters
baseSPI base pointer
xferpointer to spi_xfer_config_t structure
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
status_t SPI_MasterTransferNonBlocking ( SPI_Type *  base,
spi_master_handle_t *  handle,
spi_transfer_t xfer 
)
Parameters
baseSPI peripheral base address.
handlepointer to spi_master_handle_t structure which stores the transfer state
xferpointer to spi_xfer_config_t structure
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
kStatus_SPI_BusySPI is not idle, is running another transfer.
status_t SPI_MasterHalfDuplexTransferBlocking ( SPI_Type *  base,
spi_half_duplex_transfer_t xfer 
)

This function will do a half-duplex transfer for SPI master, This is a blocking function, which does not retuen until all transfer have been completed. And data transfer will be half-duplex, users can set transmit first or receive first.

Parameters
baseSPI base pointer
xferpointer to spi_half_duplex_transfer_t structure
Returns
status of status_t.
status_t SPI_MasterHalfDuplexTransferNonBlocking ( SPI_Type *  base,
spi_master_handle_t *  handle,
spi_half_duplex_transfer_t xfer 
)

This function using polling way to do the first half transimission and using interrupts to do the srcond half transimission, the transfer mechanism is half-duplex. When do the second half transimission, code will return right away. When all data is transferred, the callback function is called.

Parameters
baseSPI peripheral base address.
handlepointer to spi_master_handle_t structure which stores the transfer state
xferpointer to spi_half_duplex_transfer_t structure
Returns
status of status_t.
status_t SPI_MasterTransferGetCount ( SPI_Type *  base,
spi_master_handle_t *  handle,
size_t *  count 
)

This function gets the master transfer count.

Parameters
baseSPI peripheral base address.
handlePointer to the spi_master_handle_t structure which stores the transfer state.
countThe number of bytes transferred by using the non-blocking transaction.
Returns
status of status_t.
void SPI_MasterTransferAbort ( SPI_Type *  base,
spi_master_handle_t *  handle 
)

This function aborts a transfer using an interrupt.

Parameters
baseSPI peripheral base address.
handlePointer to the spi_master_handle_t structure which stores the transfer state.
void SPI_MasterTransferHandleIRQ ( SPI_Type *  base,
spi_master_handle_t *  handle 
)
Parameters
baseSPI peripheral base address.
handlepointer to spi_master_handle_t structure which stores the transfer state.
status_t SPI_SlaveTransferCreateHandle ( SPI_Type *  base,
spi_slave_handle_t handle,
spi_slave_callback_t  callback,
void *  userData 
)

This function initializes the SPI slave handle which can be used for other SPI slave transactional APIs. Usually, for a specified SPI instance, call this API once to get the initialized handle.

Parameters
baseSPI peripheral base address.
handleSPI handle pointer.
callbackCallback function.
userDataUser data.
status_t SPI_SlaveTransferNonBlocking ( SPI_Type *  base,
spi_slave_handle_t handle,
spi_transfer_t xfer 
)
Note
The API returns immediately after the transfer initialization is finished.
Parameters
baseSPI peripheral base address.
handlepointer to spi_master_handle_t structure which stores the transfer state
xferpointer to spi_xfer_config_t structure
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
kStatus_SPI_BusySPI is not idle, is running another transfer.
static status_t SPI_SlaveTransferGetCount ( SPI_Type *  base,
spi_slave_handle_t handle,
size_t *  count 
)
inlinestatic

This function gets the slave transfer count.

Parameters
baseSPI peripheral base address.
handlePointer to the spi_master_handle_t structure which stores the transfer state.
countThe number of bytes transferred by using the non-blocking transaction.
Returns
status of status_t.
static void SPI_SlaveTransferAbort ( SPI_Type *  base,
spi_slave_handle_t handle 
)
inlinestatic

This function aborts a transfer using an interrupt.

Parameters
baseSPI peripheral base address.
handlePointer to the spi_slave_handle_t structure which stores the transfer state.
void SPI_SlaveTransferHandleIRQ ( SPI_Type *  base,
spi_slave_handle_t handle 
)
Parameters
baseSPI peripheral base address.
handlepointer to spi_slave_handle_t structure which stores the transfer state

Variable Documentation

volatile uint8_t s_dummyData[]