MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
This section describes the programming interface of the SPI DMA driver.
Files | |
file | fsl_spi.h |
Data Structures | |
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. | |
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, 4)) |
SPI driver version 2.0.4. 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... | |
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... | |
DMA Control | |
void | SPI_EnableTxDMA (SPI_Type *base, bool enable) |
Enables the DMA request from SPI txFIFO. More... | |
void | SPI_EnableRxDMA (SPI_Type *base, bool enable) |
Enables the DMA request from SPI rxFIFO. More... | |
Bus Operations | |
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... | |
static uint32_t | SPI_ReadData (SPI_Type *base) |
Gets a data from the SPI data register. More... | |
static 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... | |
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... | |
static 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... | |
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) |
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... | |
static void | SPI_SlaveTransferHandleIRQ (SPI_Type *base, spi_slave_handle_t *handle) |
Interrupts a handler for the SPI slave. More... | |
struct spi_delay_config_t |
Note: The DLY register controls several programmable delays related to SPI signalling, it stands for how many SPI clock time will be inserted. The maxinun value of these delay time is 15.
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... | |
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_txfifo_watermark_t | txWatermark |
txFIFO watermark | |
spi_rxfifo_watermark_t | rxWatermark |
rxFIFO watermark | |
spi_delay_config_t | delayConfig |
Delay configuration. More... | |
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_txfifo_watermark_t | txWatermark |
txFIFO watermark | |
spi_rxfifo_watermark_t | rxWatermark |
rxFIFO watermark | |
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. | |
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... | |
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]. | |
volatile size_t | toReceiveCount |
Receive data remaining 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]. | |
uint32_t | configFlags |
Additional option to control transfer. | |
spi_txfifo_watermark_t | txWatermark |
txFIFO watermark | |
spi_rxfifo_watermark_t | rxWatermark |
rxFIFO watermark | |
#define FSL_SPI_DRIVER_VERSION (MAKE_VERSION(2, 0, 4)) |
#define SPI_DUMMYDATA (0xFFU) |
enum spi_xfer_option_t |
enum spi_clock_polarity_t |
enum spi_clock_phase_t |
enum spi_data_width_t |
enum spi_ssel_t |
enum _spi_status |
enum _spi_statusflags |
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:
config | pointer 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
base | SPI base pointer |
config | pointer to master configuration structure |
srcClock_Hz | Source 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:
config | pointer 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
base | SPI base pointer |
config | pointer to slave configuration structure |
void SPI_Deinit | ( | SPI_Type * | base | ) |
Calling this API resets the SPI module, gates the SPI clock. The SPI module can't work unless calling the SPI_MasterInit/SPI_SlaveInit to initialize module.
base | SPI base pointer |
|
inlinestatic |
base | SPI base pointer |
enable | or disable ( true = enable, false = disable) |
|
inlinestatic |
base | SPI base pointer |
|
inlinestatic |
base | SPI base pointer |
irqs | SPI interrupt source. The parameter can be any combination of the following values:
|
|
inlinestatic |
base | SPI base pointer |
irqs | SPI interrupt source. The parameter can be any combination of the following values:
|
void SPI_EnableTxDMA | ( | SPI_Type * | base, |
bool | enable | ||
) |
base | SPI base pointer |
enable | True means enable DMA, false means disable DMA |
void SPI_EnableRxDMA | ( | SPI_Type * | base, |
bool | enable | ||
) |
base | SPI base pointer |
enable | True means enable DMA, false means disable DMA |
void* SPI_GetConfig | ( | SPI_Type * | base | ) |
base | SPI peripheral address. |
status_t SPI_MasterSetBaud | ( | SPI_Type * | base, |
uint32_t | baudrate_Bps, | ||
uint32_t | srcClock_Hz | ||
) |
This is only used in master.
base | SPI base pointer |
baudrate_Bps | baud rate needed in Hz. |
srcClock_Hz | SPI source clock frequency in Hz. |
void SPI_WriteData | ( | SPI_Type * | base, |
uint16_t | data, | ||
uint32_t | configFlags | ||
) |
base | SPI base pointer |
data | needs to be write. |
configFlags | transfer configuration options spi_xfer_option_t |
|
inlinestatic |
base | SPI base pointer |
|
inlinestatic |
the delay uint is SPI clock time, maximum value is 0xF.
base | SPI base pointer |
config | configuration for delay option spi_delay_config_t. |
void SPI_SetDummyData | ( | SPI_Type * | base, |
uint8_t | dummyData | ||
) |
base | SPI peripheral address. |
dummyData | Data to be transferred when tx buffer is NULL. |
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.
base | SPI peripheral base address. |
handle | SPI handle pointer. |
callback | Callback function. |
userData | User data. |
status_t SPI_MasterTransferBlocking | ( | SPI_Type * | base, |
spi_transfer_t * | xfer | ||
) |
base | SPI base pointer |
xfer | pointer to spi_xfer_config_t structure |
kStatus_Success | Successfully start a transfer. |
kStatus_InvalidArgument | Input argument is invalid. |
status_t SPI_MasterTransferNonBlocking | ( | SPI_Type * | base, |
spi_master_handle_t * | handle, | ||
spi_transfer_t * | xfer | ||
) |
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 |
kStatus_Success | Successfully start a transfer. |
kStatus_InvalidArgument | Input argument is invalid. |
kStatus_SPI_Busy | SPI 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 mechanism is half-duplex, users can set transmit first or receive first.
base | SPI base pointer |
xfer | pointer to spi_half_duplex_transfer_t structure |
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 second 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.
base | SPI peripheral base address. |
handle | pointer to spi_master_handle_t structure which stores the transfer state |
xfer | pointer to spi_half_duplex_transfer_t structure |
status_t SPI_MasterTransferGetCount | ( | SPI_Type * | base, |
spi_master_handle_t * | handle, | ||
size_t * | count | ||
) |
This function gets the master transfer count.
base | SPI peripheral base address. |
handle | Pointer to the spi_master_handle_t structure which stores the transfer state. |
count | The number of bytes transferred by using the non-blocking transaction. |
void SPI_MasterTransferAbort | ( | SPI_Type * | base, |
spi_master_handle_t * | handle | ||
) |
This function aborts a transfer using an interrupt.
base | SPI peripheral base address. |
handle | Pointer to the spi_master_handle_t structure which stores the transfer state. |
void SPI_MasterTransferHandleIRQ | ( | SPI_Type * | base, |
spi_master_handle_t * | handle | ||
) |
base | SPI peripheral base address. |
handle | pointer to spi_master_handle_t structure which stores the transfer state. |
|
inlinestatic |
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.
base | SPI peripheral base address. |
handle | SPI handle pointer. |
callback | Callback function. |
userData | User data. |
|
inlinestatic |
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 |
kStatus_Success | Successfully start a transfer. |
kStatus_InvalidArgument | Input argument is invalid. |
kStatus_SPI_Busy | SPI is not idle, is running another transfer. |
|
inlinestatic |
This function gets the slave transfer count.
base | SPI peripheral base address. |
handle | Pointer to the spi_master_handle_t structure which stores the transfer state. |
count | The number of bytes transferred by using the non-blocking transaction. |
|
inlinestatic |
This function aborts a transfer using an interrupt.
base | SPI peripheral base address. |
handle | Pointer to the spi_slave_handle_t structure which stores the transfer state. |
|
inlinestatic |
base | SPI peripheral base address. |
handle | pointer to spi_slave_handle_t structure which stores the transfer state |
volatile uint8_t s_dummyData[] |