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 LPSPI Peripheral driver. The LPSPI driver configures LPSPI module, provides the functional and transactional interfaces to build the LPSPI application.

Function groups

LPSPI Initialization and De-initialization

This function group initializes the default configuration structure for master and slave, initializes the LPSPI master with a master configuration, initializes the LPSPI slave with a slave configuration, and de-initializes the LPSPI module.

LPSPI Basic Operation

This function group enables/disables the LPSPI module both interrupt and DMA, gets the data register address for the DMA transfer, sets master and slave, starts and stops the transfer, and so on.

LPSPI Transfer Operation

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

LPSPI Status Operation

This function group gets/clears the LPSPI status.

LPSPI Block Transfer Operation

This function group transfers a block of data, gets the transfer status, and aborts the transfer.

Typical use case

Master Operation

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpspi

Slave Operation

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpspi

Data Structures

struct  lpspi_master_config_t
 LPSPI master configuration structure. More...
 
struct  lpspi_slave_config_t
 LPSPI slave configuration structure. More...
 
struct  lpspi_transfer_t
 LPSPI master/slave transfer structure. More...
 
struct  lpspi_master_handle_t
 LPSPI master transfer handle structure used for transactional API. More...
 
struct  lpspi_slave_handle_t
 LPSPI slave transfer handle structure used for transactional API. More...
 

Macros

#define LPSPI_DUMMY_DATA   (0x00U)
 LPSPI dummy data if no Tx data. More...
 
#define SPI_RETRY_TIMES   0U /* Define to zero means keep waiting until the flag is assert/deassert. */
 Retry times for waiting flag. More...
 
#define LPSPI_MASTER_PCS_SHIFT   (4U)
 LPSPI master PCS shift macro , internal used. More...
 
#define LPSPI_MASTER_PCS_MASK   (0xF0U)
 LPSPI master PCS shift macro , internal used. More...
 
#define LPSPI_SLAVE_PCS_SHIFT   (4U)
 LPSPI slave PCS shift macro , internal used. More...
 
#define LPSPI_SLAVE_PCS_MASK   (0xF0U)
 LPSPI slave PCS shift macro , internal used. More...
 

Typedefs

typedef void(* lpspi_master_transfer_callback_t )(LPSPI_Type *base, lpspi_master_handle_t *handle, status_t status, void *userData)
 Master completion callback function pointer type. More...
 
typedef void(* lpspi_slave_transfer_callback_t )(LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData)
 Slave completion callback function pointer type. More...
 

Enumerations

enum  {
  kStatus_LPSPI_Busy = MAKE_STATUS(kStatusGroup_LPSPI, 0),
  kStatus_LPSPI_Error = MAKE_STATUS(kStatusGroup_LPSPI, 1),
  kStatus_LPSPI_Idle = MAKE_STATUS(kStatusGroup_LPSPI, 2),
  kStatus_LPSPI_OutOfRange = MAKE_STATUS(kStatusGroup_LPSPI, 3),
  kStatus_LPSPI_Timeout = MAKE_STATUS(kStatusGroup_LPSPI, 4)
}
 Status for the LPSPI driver. More...
 
enum  _lpspi_flags {
  kLPSPI_TxDataRequestFlag = LPSPI_SR_TDF_MASK,
  kLPSPI_RxDataReadyFlag = LPSPI_SR_RDF_MASK,
  kLPSPI_WordCompleteFlag = LPSPI_SR_WCF_MASK,
  kLPSPI_FrameCompleteFlag = LPSPI_SR_FCF_MASK,
  kLPSPI_TransferCompleteFlag = LPSPI_SR_TCF_MASK,
  kLPSPI_TransmitErrorFlag = LPSPI_SR_TEF_MASK,
  kLPSPI_ReceiveErrorFlag = LPSPI_SR_REF_MASK,
  kLPSPI_DataMatchFlag = LPSPI_SR_DMF_MASK,
  kLPSPI_ModuleBusyFlag = LPSPI_SR_MBF_MASK,
  kLPSPI_AllStatusFlag
}
 LPSPI status flags in SPIx_SR register. More...
 
enum  _lpspi_interrupt_enable {
  kLPSPI_TxInterruptEnable = LPSPI_IER_TDIE_MASK,
  kLPSPI_RxInterruptEnable = LPSPI_IER_RDIE_MASK,
  kLPSPI_WordCompleteInterruptEnable = LPSPI_IER_WCIE_MASK,
  kLPSPI_FrameCompleteInterruptEnable = LPSPI_IER_FCIE_MASK,
  kLPSPI_TransferCompleteInterruptEnable = LPSPI_IER_TCIE_MASK,
  kLPSPI_TransmitErrorInterruptEnable = LPSPI_IER_TEIE_MASK,
  kLPSPI_ReceiveErrorInterruptEnable = LPSPI_IER_REIE_MASK,
  kLPSPI_DataMatchInterruptEnable = LPSPI_IER_DMIE_MASK,
  kLPSPI_AllInterruptEnable
}
 LPSPI interrupt source. More...
 
enum  _lpspi_dma_enable {
  kLPSPI_TxDmaEnable = LPSPI_DER_TDDE_MASK,
  kLPSPI_RxDmaEnable = LPSPI_DER_RDDE_MASK
}
 LPSPI DMA source. More...
 
enum  lpspi_master_slave_mode_t {
  kLPSPI_Master = 1U,
  kLPSPI_Slave = 0U
}
 LPSPI master or slave mode configuration. More...
 
enum  lpspi_which_pcs_t {
  kLPSPI_Pcs0 = 0U,
  kLPSPI_Pcs1 = 1U,
  kLPSPI_Pcs2 = 2U,
  kLPSPI_Pcs3 = 3U
}
 LPSPI Peripheral Chip Select (PCS) configuration (which PCS to configure). More...
 
enum  lpspi_pcs_polarity_config_t {
  kLPSPI_PcsActiveHigh = 1U,
  kLPSPI_PcsActiveLow = 0U
}
 LPSPI Peripheral Chip Select (PCS) Polarity configuration. More...
 
enum  _lpspi_pcs_polarity {
  kLPSPI_Pcs0ActiveLow = 1U << 0,
  kLPSPI_Pcs1ActiveLow = 1U << 1,
  kLPSPI_Pcs2ActiveLow = 1U << 2,
  kLPSPI_Pcs3ActiveLow = 1U << 3,
  kLPSPI_PcsAllActiveLow = 0xFU
}
 LPSPI Peripheral Chip Select (PCS) Polarity. More...
 
enum  lpspi_clock_polarity_t {
  kLPSPI_ClockPolarityActiveHigh = 0U,
  kLPSPI_ClockPolarityActiveLow = 1U
}
 LPSPI clock polarity configuration. More...
 
enum  lpspi_clock_phase_t {
  kLPSPI_ClockPhaseFirstEdge = 0U,
  kLPSPI_ClockPhaseSecondEdge = 1U
}
 LPSPI clock phase configuration. More...
 
enum  lpspi_shift_direction_t {
  kLPSPI_MsbFirst = 0U,
  kLPSPI_LsbFirst = 1U
}
 LPSPI data shifter direction options. More...
 
enum  lpspi_host_request_select_t {
  kLPSPI_HostReqExtPin = 0U,
  kLPSPI_HostReqInternalTrigger = 1U
}
 LPSPI Host Request select configuration. More...
 
enum  lpspi_match_config_t {
  kLPSI_MatchDisabled = 0x0U,
  kLPSI_1stWordEqualsM0orM1 = 0x2U,
  kLPSI_AnyWordEqualsM0orM1 = 0x3U,
  kLPSI_1stWordEqualsM0and2ndWordEqualsM1 = 0x4U,
  kLPSI_AnyWordEqualsM0andNxtWordEqualsM1 = 0x5U,
  kLPSI_1stWordAndM1EqualsM0andM1 = 0x6U,
  kLPSI_AnyWordAndM1EqualsM0andM1 = 0x7U
}
 LPSPI Match configuration options. More...
 
enum  lpspi_pin_config_t {
  kLPSPI_SdiInSdoOut = 0U,
  kLPSPI_SdiInSdiOut = 1U,
  kLPSPI_SdoInSdoOut = 2U,
  kLPSPI_SdoInSdiOut = 3U
}
 LPSPI pin (SDO and SDI) configuration. More...
 
enum  lpspi_data_out_config_t {
  kLpspiDataOutRetained = 0U,
  kLpspiDataOutTristate = 1U
}
 LPSPI data output configuration. More...
 
enum  lpspi_transfer_width_t {
  kLPSPI_SingleBitXfer = 0U,
  kLPSPI_TwoBitXfer = 1U,
  kLPSPI_FourBitXfer = 2U
}
 LPSPI transfer width configuration. More...
 
enum  lpspi_delay_type_t {
  kLPSPI_PcsToSck = 1U,
  kLPSPI_LastSckToPcs,
  kLPSPI_BetweenTransfer
}
 LPSPI delay type selection. More...
 
enum  _lpspi_transfer_config_flag_for_master {
  kLPSPI_MasterPcs0 = 0U << LPSPI_MASTER_PCS_SHIFT,
  kLPSPI_MasterPcs1 = 1U << LPSPI_MASTER_PCS_SHIFT,
  kLPSPI_MasterPcs2 = 2U << LPSPI_MASTER_PCS_SHIFT,
  kLPSPI_MasterPcs3 = 3U << LPSPI_MASTER_PCS_SHIFT,
  kLPSPI_MasterPcsContinuous = 1U << 20,
  kLPSPI_MasterByteSwap
}
 Use this enumeration for LPSPI master transfer configFlags. More...
 
enum  _lpspi_transfer_config_flag_for_slave {
  kLPSPI_SlavePcs0 = 0U << LPSPI_SLAVE_PCS_SHIFT,
  kLPSPI_SlavePcs1 = 1U << LPSPI_SLAVE_PCS_SHIFT,
  kLPSPI_SlavePcs2 = 2U << LPSPI_SLAVE_PCS_SHIFT,
  kLPSPI_SlavePcs3 = 3U << LPSPI_SLAVE_PCS_SHIFT,
  kLPSPI_SlaveByteSwap
}
 Use this enumeration for LPSPI slave transfer configFlags. More...
 
enum  _lpspi_transfer_state {
  kLPSPI_Idle = 0x0U,
  kLPSPI_Busy,
  kLPSPI_Error
}
 LPSPI transfer state, which is used for LPSPI transactional API state machine. More...
 

Variables

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

Driver version

#define FSL_LPSPI_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))
 LPSPI driver version. More...
 

Initialization and deinitialization

void LPSPI_MasterInit (LPSPI_Type *base, const lpspi_master_config_t *masterConfig, uint32_t srcClock_Hz)
 Initializes the LPSPI master. More...
 
void LPSPI_MasterGetDefaultConfig (lpspi_master_config_t *masterConfig)
 Sets the lpspi_master_config_t structure to default values. More...
 
void LPSPI_SlaveInit (LPSPI_Type *base, const lpspi_slave_config_t *slaveConfig)
 LPSPI slave configuration. More...
 
void LPSPI_SlaveGetDefaultConfig (lpspi_slave_config_t *slaveConfig)
 Sets the lpspi_slave_config_t structure to default values. More...
 
void LPSPI_Deinit (LPSPI_Type *base)
 De-initializes the LPSPI peripheral. More...
 
void LPSPI_Reset (LPSPI_Type *base)
 Restores the LPSPI peripheral to reset state. More...
 
uint32_t LPSPI_GetInstance (LPSPI_Type *base)
 Get the LPSPI instance from peripheral base address. More...
 
static void LPSPI_Enable (LPSPI_Type *base, bool enable)
 Enables the LPSPI peripheral and sets the MCR MDIS to 0. More...
 

Status

static uint32_t LPSPI_GetStatusFlags (LPSPI_Type *base)
 Gets the LPSPI status flag state. More...
 
static uint8_t LPSPI_GetTxFifoSize (LPSPI_Type *base)
 Gets the LPSPI Tx FIFO size. More...
 
static uint8_t LPSPI_GetRxFifoSize (LPSPI_Type *base)
 Gets the LPSPI Rx FIFO size. More...
 
static uint32_t LPSPI_GetTxFifoCount (LPSPI_Type *base)
 Gets the LPSPI Tx FIFO count. More...
 
static uint32_t LPSPI_GetRxFifoCount (LPSPI_Type *base)
 Gets the LPSPI Rx FIFO count. More...
 
static void LPSPI_ClearStatusFlags (LPSPI_Type *base, uint32_t statusFlags)
 Clears the LPSPI status flag. More...
 

Interrupts

static void LPSPI_EnableInterrupts (LPSPI_Type *base, uint32_t mask)
 Enables the LPSPI interrupts. More...
 
static void LPSPI_DisableInterrupts (LPSPI_Type *base, uint32_t mask)
 Disables the LPSPI interrupts. More...
 

DMA Control

static void LPSPI_EnableDMA (LPSPI_Type *base, uint32_t mask)
 Enables the LPSPI DMA request. More...
 
static void LPSPI_DisableDMA (LPSPI_Type *base, uint32_t mask)
 Disables the LPSPI DMA request. More...
 
static uint32_t LPSPI_GetTxRegisterAddress (LPSPI_Type *base)
 Gets the LPSPI Transmit Data Register address for a DMA operation. More...
 
static uint32_t LPSPI_GetRxRegisterAddress (LPSPI_Type *base)
 Gets the LPSPI Receive Data Register address for a DMA operation. More...
 

Bus Operations

bool LPSPI_CheckTransferArgument (lpspi_transfer_t *transfer, uint32_t bitsPerFrame, uint32_t bytesPerFrame)
 Check the argument for transfer . More...
 
static void LPSPI_SetMasterSlaveMode (LPSPI_Type *base, lpspi_master_slave_mode_t mode)
 Configures the LPSPI for either master or slave. More...
 
static void LPSPI_SelectTransferPCS (LPSPI_Type *base, lpspi_which_pcs_t select)
 Configures the peripheral chip select used for the transfer. More...
 
static void LPSPI_SetPCSContinous (LPSPI_Type *base, bool IsContinous)
 Set the PCS signal to continuous or uncontinuous mode. More...
 
static bool LPSPI_IsMaster (LPSPI_Type *base)
 Returns whether the LPSPI module is in master mode. More...
 
static void LPSPI_FlushFifo (LPSPI_Type *base, bool flushTxFifo, bool flushRxFifo)
 Flushes the LPSPI FIFOs. More...
 
static void LPSPI_SetFifoWatermarks (LPSPI_Type *base, uint32_t txWater, uint32_t rxWater)
 Sets the transmit and receive FIFO watermark values. More...
 
static void LPSPI_SetAllPcsPolarity (LPSPI_Type *base, uint32_t mask)
 Configures all LPSPI peripheral chip select polarities simultaneously. More...
 
static void LPSPI_SetFrameSize (LPSPI_Type *base, uint32_t frameSize)
 Configures the frame size. More...
 
uint32_t LPSPI_MasterSetBaudRate (LPSPI_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz, uint32_t *tcrPrescaleValue)
 Sets the LPSPI baud rate in bits per second. More...
 
void LPSPI_MasterSetDelayScaler (LPSPI_Type *base, uint32_t scaler, lpspi_delay_type_t whichDelay)
 Manually configures a specific LPSPI delay parameter (module must be disabled to change the delay values). More...
 
uint32_t LPSPI_MasterSetDelayTimes (LPSPI_Type *base, uint32_t delayTimeInNanoSec, lpspi_delay_type_t whichDelay, uint32_t srcClock_Hz)
 Calculates the delay based on the desired delay input in nanoseconds (module must be disabled to change the delay values). More...
 
static void LPSPI_WriteData (LPSPI_Type *base, uint32_t data)
 Writes data into the transmit data buffer. More...
 
static uint32_t LPSPI_ReadData (LPSPI_Type *base)
 Reads data from the data buffer. More...
 
void LPSPI_SetDummyData (LPSPI_Type *base, uint8_t dummyData)
 Set up the dummy data. More...
 

Transactional

void LPSPI_MasterTransferCreateHandle (LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_master_transfer_callback_t callback, void *userData)
 Initializes the LPSPI master handle. More...
 
status_t LPSPI_MasterTransferBlocking (LPSPI_Type *base, lpspi_transfer_t *transfer)
 LPSPI master transfer data using a polling method. More...
 
status_t LPSPI_MasterTransferNonBlocking (LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_transfer_t *transfer)
 LPSPI master transfer data using an interrupt method. More...
 
status_t LPSPI_MasterTransferGetCount (LPSPI_Type *base, lpspi_master_handle_t *handle, size_t *count)
 Gets the master transfer remaining bytes. More...
 
void LPSPI_MasterTransferAbort (LPSPI_Type *base, lpspi_master_handle_t *handle)
 LPSPI master abort transfer which uses an interrupt method. More...
 
void LPSPI_MasterTransferHandleIRQ (LPSPI_Type *base, lpspi_master_handle_t *handle)
 LPSPI Master IRQ handler function. More...
 
void LPSPI_SlaveTransferCreateHandle (LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_slave_transfer_callback_t callback, void *userData)
 Initializes the LPSPI slave handle. More...
 
status_t LPSPI_SlaveTransferNonBlocking (LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_transfer_t *transfer)
 LPSPI slave transfer data using an interrupt method. More...
 
status_t LPSPI_SlaveTransferGetCount (LPSPI_Type *base, lpspi_slave_handle_t *handle, size_t *count)
 Gets the slave transfer remaining bytes. More...
 
void LPSPI_SlaveTransferAbort (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 LPSPI slave aborts a transfer which uses an interrupt method. More...
 
void LPSPI_SlaveTransferHandleIRQ (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 LPSPI Slave IRQ handler function. More...
 

Data Structure Documentation

struct lpspi_master_config_t

Data Fields

uint32_t baudRate
 Baud Rate for LPSPI. More...
 
uint32_t bitsPerFrame
 Bits per frame, minimum 8, maximum 4096. More...
 
lpspi_clock_polarity_t cpol
 Clock polarity. More...
 
lpspi_clock_phase_t cpha
 Clock phase. More...
 
lpspi_shift_direction_t direction
 MSB or LSB data shift direction. More...
 
uint32_t pcsToSckDelayInNanoSec
 PCS to SCK delay time in nanoseconds, setting to 0 sets the minimum delay. More...
 
uint32_t lastSckToPcsDelayInNanoSec
 Last SCK to PCS delay time in nanoseconds, setting to 0 sets the minimum delay. More...
 
uint32_t betweenTransferDelayInNanoSec
 
After the SCK delay time with nanoseconds, setting to 0 sets the

minimum delay. More...

 
lpspi_which_pcs_t whichPcs
 Desired Peripheral Chip Select (PCS). More...
 
lpspi_pcs_polarity_config_t pcsActiveHighOrLow
 Desired PCS active high or low.
 
lpspi_pin_config_t pinCfg
 Configures which pins are used for input and output data during single bit transfers. More...
 
lpspi_data_out_config_t dataOutConfig
 Configures if the output data is tristated between accesses (LPSPI_PCS is negated). More...
 

Field Documentation

uint32_t lpspi_master_config_t::baudRate
uint32_t lpspi_master_config_t::bitsPerFrame
lpspi_clock_polarity_t lpspi_master_config_t::cpol
lpspi_clock_phase_t lpspi_master_config_t::cpha
lpspi_shift_direction_t lpspi_master_config_t::direction
uint32_t lpspi_master_config_t::pcsToSckDelayInNanoSec

It sets the boundary value if out of range.

uint32_t lpspi_master_config_t::lastSckToPcsDelayInNanoSec

It sets the boundary value if out of range.

uint32_t lpspi_master_config_t::betweenTransferDelayInNanoSec

It sets the boundary value if out of range.

lpspi_which_pcs_t lpspi_master_config_t::whichPcs
lpspi_pin_config_t lpspi_master_config_t::pinCfg
lpspi_data_out_config_t lpspi_master_config_t::dataOutConfig
struct lpspi_slave_config_t

Data Fields

uint32_t bitsPerFrame
 Bits per frame, minimum 8, maximum 4096. More...
 
lpspi_clock_polarity_t cpol
 Clock polarity. More...
 
lpspi_clock_phase_t cpha
 Clock phase. More...
 
lpspi_shift_direction_t direction
 MSB or LSB data shift direction. More...
 
lpspi_which_pcs_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
lpspi_pcs_polarity_config_t pcsActiveHighOrLow
 Desired PCS active high or low.
 
lpspi_pin_config_t pinCfg
 Configures which pins are used for input and output data during single bit transfers. More...
 
lpspi_data_out_config_t dataOutConfig
 Configures if the output data is tristated between accesses (LPSPI_PCS is negated). More...
 

Field Documentation

uint32_t lpspi_slave_config_t::bitsPerFrame
lpspi_clock_polarity_t lpspi_slave_config_t::cpol
lpspi_clock_phase_t lpspi_slave_config_t::cpha
lpspi_shift_direction_t lpspi_slave_config_t::direction
lpspi_pin_config_t lpspi_slave_config_t::pinCfg
lpspi_data_out_config_t lpspi_slave_config_t::dataOutConfig
struct lpspi_transfer_t

Data Fields

uint8_t * txData
 Send buffer. More...
 
uint8_t * rxData
 Receive buffer. More...
 
volatile size_t dataSize
 Transfer bytes. More...
 
uint32_t configFlags
 Transfer transfer configuration flags. More...
 

Field Documentation

uint8_t* lpspi_transfer_t::txData
uint8_t* lpspi_transfer_t::rxData
volatile size_t lpspi_transfer_t::dataSize
uint32_t lpspi_transfer_t::configFlags

Set from _lpspi_transfer_config_flag_for_master if the transfer is used for master or _lpspi_transfer_config_flag_for_slave enumeration if the transfer is used for slave.

struct _lpspi_master_handle

Forward declaration of the _lpspi_master_handle typedefs.

Data Fields

volatile bool isPcsContinuous
 Is PCS continuous in transfer. More...
 
volatile bool writeTcrInIsr
 A flag that whether should write TCR in ISR. More...
 
volatile bool isByteSwap
 A flag that whether should byte swap. More...
 
volatile uint8_t fifoSize
 FIFO dataSize. More...
 
volatile uint8_t rxWatermark
 Rx watermark. More...
 
volatile uint8_t bytesEachWrite
 Bytes for each write TDR. More...
 
volatile uint8_t bytesEachRead
 Bytes for each read RDR. More...
 
uint8_t *volatile txData
 Send buffer. More...
 
uint8_t *volatile rxData
 Receive buffer. More...
 
volatile size_t txRemainingByteCount
 Number of bytes remaining to send. More...
 
volatile size_t rxRemainingByteCount
 Number of bytes remaining to receive. More...
 
volatile uint32_t writeRegRemainingTimes
 Write TDR register remaining times. More...
 
volatile uint32_t readRegRemainingTimes
 Read RDR register remaining times. More...
 
uint32_t totalByteCount
 Number of transfer bytes.
 
uint32_t txBuffIfNull
 Used if the txData is NULL. More...
 
volatile uint8_t state
 LPSPI transfer state , _lpspi_transfer_state. More...
 
lpspi_master_transfer_callback_t callback
 Completion callback. More...
 
void * userData
 Callback user data. More...
 

Field Documentation

volatile bool lpspi_master_handle_t::isPcsContinuous
volatile bool lpspi_master_handle_t::writeTcrInIsr
volatile bool lpspi_master_handle_t::isByteSwap
volatile uint8_t lpspi_master_handle_t::fifoSize
volatile uint8_t lpspi_master_handle_t::rxWatermark
volatile uint8_t lpspi_master_handle_t::bytesEachWrite
volatile uint8_t lpspi_master_handle_t::bytesEachRead
uint8_t* volatile lpspi_master_handle_t::txData
uint8_t* volatile lpspi_master_handle_t::rxData
volatile size_t lpspi_master_handle_t::txRemainingByteCount
volatile size_t lpspi_master_handle_t::rxRemainingByteCount
volatile uint32_t lpspi_master_handle_t::writeRegRemainingTimes
volatile uint32_t lpspi_master_handle_t::readRegRemainingTimes
uint32_t lpspi_master_handle_t::txBuffIfNull
volatile uint8_t lpspi_master_handle_t::state
lpspi_master_transfer_callback_t lpspi_master_handle_t::callback
void* lpspi_master_handle_t::userData
struct _lpspi_slave_handle

Forward declaration of the _lpspi_slave_handle typedefs.

Data Fields

volatile bool isByteSwap
 A flag that whether should byte swap. More...
 
volatile uint8_t fifoSize
 FIFO dataSize. More...
 
volatile uint8_t rxWatermark
 Rx watermark. More...
 
volatile uint8_t bytesEachWrite
 Bytes for each write TDR. More...
 
volatile uint8_t bytesEachRead
 Bytes for each read RDR. More...
 
uint8_t *volatile txData
 Send buffer. More...
 
uint8_t *volatile rxData
 Receive buffer. More...
 
volatile size_t txRemainingByteCount
 Number of bytes remaining to send. More...
 
volatile size_t rxRemainingByteCount
 Number of bytes remaining to receive. More...
 
volatile uint32_t writeRegRemainingTimes
 Write TDR register remaining times. More...
 
volatile uint32_t readRegRemainingTimes
 Read RDR register remaining times. More...
 
uint32_t totalByteCount
 Number of transfer bytes.
 
volatile uint8_t state
 LPSPI transfer state , _lpspi_transfer_state. More...
 
volatile uint32_t errorCount
 Error count for slave transfer. More...
 
lpspi_slave_transfer_callback_t callback
 Completion callback. More...
 
void * userData
 Callback user data. More...
 

Field Documentation

volatile bool lpspi_slave_handle_t::isByteSwap
volatile uint8_t lpspi_slave_handle_t::fifoSize
volatile uint8_t lpspi_slave_handle_t::rxWatermark
volatile uint8_t lpspi_slave_handle_t::bytesEachWrite
volatile uint8_t lpspi_slave_handle_t::bytesEachRead
uint8_t* volatile lpspi_slave_handle_t::txData
uint8_t* volatile lpspi_slave_handle_t::rxData
volatile size_t lpspi_slave_handle_t::txRemainingByteCount
volatile size_t lpspi_slave_handle_t::rxRemainingByteCount
volatile uint32_t lpspi_slave_handle_t::writeRegRemainingTimes
volatile uint32_t lpspi_slave_handle_t::readRegRemainingTimes
volatile uint8_t lpspi_slave_handle_t::state
volatile uint32_t lpspi_slave_handle_t::errorCount
lpspi_slave_transfer_callback_t lpspi_slave_handle_t::callback
void* lpspi_slave_handle_t::userData

Macro Definition Documentation

#define FSL_LPSPI_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))
#define LPSPI_DUMMY_DATA   (0x00U)

Dummy data used for tx if there is not txData.

#define SPI_RETRY_TIMES   0U /* Define to zero means keep waiting until the flag is assert/deassert. */
#define LPSPI_MASTER_PCS_SHIFT   (4U)
#define LPSPI_MASTER_PCS_MASK   (0xF0U)
#define LPSPI_SLAVE_PCS_SHIFT   (4U)
#define LPSPI_SLAVE_PCS_MASK   (0xF0U)

Typedef Documentation

typedef void(* lpspi_master_transfer_callback_t)(LPSPI_Type *base, lpspi_master_handle_t *handle, status_t status, void *userData)
Parameters
baseLPSPI peripheral address.
handlePointer to the handle for the LPSPI master.
statusSuccess or error code describing whether the transfer is completed.
userDataArbitrary pointer-dataSized value passed from the application.
typedef void(* lpspi_slave_transfer_callback_t)(LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData)
Parameters
baseLPSPI peripheral address.
handlePointer to the handle for the LPSPI slave.
statusSuccess or error code describing whether the transfer is completed.
userDataArbitrary pointer-dataSized value passed from the application.

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_LPSPI_Busy 

LPSPI transfer is busy.

kStatus_LPSPI_Error 

LPSPI driver error.

kStatus_LPSPI_Idle 

LPSPI is idle.

kStatus_LPSPI_OutOfRange 

LPSPI transfer out Of range.

kStatus_LPSPI_Timeout 

LPSPI timeout polling status flags.

Enumerator
kLPSPI_TxDataRequestFlag 

Transmit data flag.

kLPSPI_RxDataReadyFlag 

Receive data flag.

kLPSPI_WordCompleteFlag 

Word Complete flag.

kLPSPI_FrameCompleteFlag 

Frame Complete flag.

kLPSPI_TransferCompleteFlag 

Transfer Complete flag.

kLPSPI_TransmitErrorFlag 

Transmit Error flag (FIFO underrun)

kLPSPI_ReceiveErrorFlag 

Receive Error flag (FIFO overrun)

kLPSPI_DataMatchFlag 

Data Match flag.

kLPSPI_ModuleBusyFlag 

Module Busy flag.

kLPSPI_AllStatusFlag 

Used for clearing all w1c status flags.

Enumerator
kLPSPI_TxInterruptEnable 

Transmit data interrupt enable.

kLPSPI_RxInterruptEnable 

Receive data interrupt enable.

kLPSPI_WordCompleteInterruptEnable 

Word complete interrupt enable.

kLPSPI_FrameCompleteInterruptEnable 

Frame complete interrupt enable.

kLPSPI_TransferCompleteInterruptEnable 

Transfer complete interrupt enable.

kLPSPI_TransmitErrorInterruptEnable 

Transmit error interrupt enable(FIFO underrun)

kLPSPI_ReceiveErrorInterruptEnable 

Receive Error interrupt enable (FIFO overrun)

kLPSPI_DataMatchInterruptEnable 

Data Match interrupt enable.

kLPSPI_AllInterruptEnable 

All above interrupts enable.

Enumerator
kLPSPI_TxDmaEnable 

Transmit data DMA enable.

kLPSPI_RxDmaEnable 

Receive data DMA enable.

Enumerator
kLPSPI_Master 

LPSPI peripheral operates in master mode.

kLPSPI_Slave 

LPSPI peripheral operates in slave mode.

Enumerator
kLPSPI_Pcs0 

PCS[0].

kLPSPI_Pcs1 

PCS[1].

kLPSPI_Pcs2 

PCS[2].

kLPSPI_Pcs3 

PCS[3].

Enumerator
kLPSPI_PcsActiveHigh 

PCS Active High (idles low)

kLPSPI_PcsActiveLow 

PCS Active Low (idles high)

Enumerator
kLPSPI_Pcs0ActiveLow 

Pcs0 Active Low (idles high).

kLPSPI_Pcs1ActiveLow 

Pcs1 Active Low (idles high).

kLPSPI_Pcs2ActiveLow 

Pcs2 Active Low (idles high).

kLPSPI_Pcs3ActiveLow 

Pcs3 Active Low (idles high).

kLPSPI_PcsAllActiveLow 

Pcs0 to Pcs5 Active Low (idles high).

Enumerator
kLPSPI_ClockPolarityActiveHigh 

CPOL=0.

Active-high LPSPI clock (idles low)

kLPSPI_ClockPolarityActiveLow 

CPOL=1.

Active-low LPSPI clock (idles high)

Enumerator
kLPSPI_ClockPhaseFirstEdge 

CPHA=0.

Data is captured on the leading edge of the SCK and changed on the following edge.

kLPSPI_ClockPhaseSecondEdge 

CPHA=1.

Data is changed on the leading edge of the SCK and captured on the following edge.

Enumerator
kLPSPI_MsbFirst 

Data transfers start with most significant bit.

kLPSPI_LsbFirst 

Data transfers start with least significant bit.

Enumerator
kLPSPI_HostReqExtPin 

Host Request is an ext pin.

kLPSPI_HostReqInternalTrigger 

Host Request is an internal trigger.

Enumerator
kLPSI_MatchDisabled 

LPSPI Match Disabled.

kLPSI_1stWordEqualsM0orM1 

LPSPI Match Enabled.

kLPSI_AnyWordEqualsM0orM1 

LPSPI Match Enabled.

kLPSI_1stWordEqualsM0and2ndWordEqualsM1 

LPSPI Match Enabled.

kLPSI_AnyWordEqualsM0andNxtWordEqualsM1 

LPSPI Match Enabled.

kLPSI_1stWordAndM1EqualsM0andM1 

LPSPI Match Enabled.

kLPSI_AnyWordAndM1EqualsM0andM1 

LPSPI Match Enabled.

Enumerator
kLPSPI_SdiInSdoOut 

LPSPI SDI input, SDO output.

kLPSPI_SdiInSdiOut 

LPSPI SDI input, SDI output.

kLPSPI_SdoInSdoOut 

LPSPI SDO input, SDO output.

kLPSPI_SdoInSdiOut 

LPSPI SDO input, SDI output.

Enumerator
kLpspiDataOutRetained 

Data out retains last value when chip select is de-asserted.

kLpspiDataOutTristate 

Data out is tristated when chip select is de-asserted.

Enumerator
kLPSPI_SingleBitXfer 

1-bit shift at a time, data out on SDO, in on SDI (normal mode)

kLPSPI_TwoBitXfer 

2-bits shift out on SDO/SDI and in on SDO/SDI

kLPSPI_FourBitXfer 

4-bits shift out on SDO/SDI/PCS[3:2] and in on SDO/SDI/PCS[3:2]

Enumerator
kLPSPI_PcsToSck 

PCS-to-SCK delay.

kLPSPI_LastSckToPcs 

Last SCK edge to PCS delay.

kLPSPI_BetweenTransfer 

Delay between transfers.

Enumerator
kLPSPI_MasterPcs0 

LPSPI master transfer use PCS0 signal.

kLPSPI_MasterPcs1 

LPSPI master transfer use PCS1 signal.

kLPSPI_MasterPcs2 

LPSPI master transfer use PCS2 signal.

kLPSPI_MasterPcs3 

LPSPI master transfer use PCS3 signal.

kLPSPI_MasterPcsContinuous 

Is PCS signal continuous.

kLPSPI_MasterByteSwap 

Is master swap the byte.

For example, when want to send data 1 2 3 4 5 6 7 8 (suppose you set lpspi_shift_direction_t to MSB).

  1. If you set bitPerFrame = 8 , no matter the kLPSPI_MasterByteSwapyou flag is used or not, the waveform is 1 2 3 4 5 6 7 8.
  2. If you set bitPerFrame = 16 : (1) the waveform is 2 1 4 3 6 5 8 7 if you do not use the kLPSPI_MasterByteSwap flag. (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_MasterByteSwap flag.
  3. If you set bitPerFrame = 32 : (1) the waveform is 4 3 2 1 8 7 6 5 if you do not use the kLPSPI_MasterByteSwap flag. (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_MasterByteSwap flag.
Enumerator
kLPSPI_SlavePcs0 

LPSPI slave transfer use PCS0 signal.

kLPSPI_SlavePcs1 

LPSPI slave transfer use PCS1 signal.

kLPSPI_SlavePcs2 

LPSPI slave transfer use PCS2 signal.

kLPSPI_SlavePcs3 

LPSPI slave transfer use PCS3 signal.

kLPSPI_SlaveByteSwap 

Is slave swap the byte.

For example, when want to send data 1 2 3 4 5 6 7 8 (suppose you set lpspi_shift_direction_t to MSB).

  1. If you set bitPerFrame = 8 , no matter the kLPSPI_SlaveByteSwap flag is used or not, the waveform is 1 2 3 4 5 6 7 8.
  2. If you set bitPerFrame = 16 : (1) the waveform is 2 1 4 3 6 5 8 7 if you do not use the kLPSPI_SlaveByteSwap flag. (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_SlaveByteSwap flag.
  3. If you set bitPerFrame = 32 : (1) the waveform is 4 3 2 1 8 7 6 5 if you do not use the kLPSPI_SlaveByteSwap flag. (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_SlaveByteSwap flag.
Enumerator
kLPSPI_Idle 

Nothing in the transmitter/receiver.

kLPSPI_Busy 

Transfer queue is not finished.

kLPSPI_Error 

Transfer error.

Function Documentation

void LPSPI_MasterInit ( LPSPI_Type *  base,
const lpspi_master_config_t masterConfig,
uint32_t  srcClock_Hz 
)
Parameters
baseLPSPI peripheral address.
masterConfigPointer to structure lpspi_master_config_t.
srcClock_HzModule source input clock in Hertz
void LPSPI_MasterGetDefaultConfig ( lpspi_master_config_t masterConfig)

This API initializes the configuration structure for LPSPI_MasterInit(). The initialized structure can remain unchanged in LPSPI_MasterInit(), or can be modified before calling the LPSPI_MasterInit(). Example:

* lpspi_master_config_t masterConfig;
*
Parameters
masterConfigpointer to lpspi_master_config_t structure
void LPSPI_SlaveInit ( LPSPI_Type *  base,
const lpspi_slave_config_t slaveConfig 
)
Parameters
baseLPSPI peripheral address.
slaveConfigPointer to a structure lpspi_slave_config_t.
void LPSPI_SlaveGetDefaultConfig ( lpspi_slave_config_t slaveConfig)

This API initializes the configuration structure for LPSPI_SlaveInit(). The initialized structure can remain unchanged in LPSPI_SlaveInit() or can be modified before calling the LPSPI_SlaveInit(). Example:

* lpspi_slave_config_t slaveConfig;
*
Parameters
slaveConfigpointer to lpspi_slave_config_t structure.
void LPSPI_Deinit ( LPSPI_Type *  base)

Call this API to disable the LPSPI clock.

Parameters
baseLPSPI peripheral address.
void LPSPI_Reset ( LPSPI_Type *  base)

Note that this function sets all registers to reset state. As a result, the LPSPI module can't work after calling this API.

Parameters
baseLPSPI peripheral address.
uint32_t LPSPI_GetInstance ( LPSPI_Type *  base)
Parameters
baseLPSPI peripheral base address.
Returns
LPSPI instance.
static void LPSPI_Enable ( LPSPI_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseLPSPI peripheral address.
enablePass true to enable module, false to disable module.
static uint32_t LPSPI_GetStatusFlags ( LPSPI_Type *  base)
inlinestatic
Parameters
baseLPSPI peripheral address.
Returns
The LPSPI status(in SR register).
static uint8_t LPSPI_GetTxFifoSize ( LPSPI_Type *  base)
inlinestatic
Parameters
baseLPSPI peripheral address.
Returns
The LPSPI Tx FIFO size.
static uint8_t LPSPI_GetRxFifoSize ( LPSPI_Type *  base)
inlinestatic
Parameters
baseLPSPI peripheral address.
Returns
The LPSPI Rx FIFO size.
static uint32_t LPSPI_GetTxFifoCount ( LPSPI_Type *  base)
inlinestatic
Parameters
baseLPSPI peripheral address.
Returns
The number of words in the transmit FIFO.
static uint32_t LPSPI_GetRxFifoCount ( LPSPI_Type *  base)
inlinestatic
Parameters
baseLPSPI peripheral address.
Returns
The number of words in the receive FIFO.
static void LPSPI_ClearStatusFlags ( LPSPI_Type *  base,
uint32_t  statusFlags 
)
inlinestatic

This function clears the desired status bit by using a write-1-to-clear. The user passes in the base and the desired status flag bit to clear. The list of status flags is defined in the _lpspi_flags. Example usage:

Parameters
baseLPSPI peripheral address.
statusFlagsThe status flag used from type _lpspi_flags.

< The status flags are cleared by writing 1 (w1c).

static void LPSPI_EnableInterrupts ( LPSPI_Type *  base,
uint32_t  mask 
)
inlinestatic

This function configures the various interrupt masks of the LPSPI. The parameters are base and an interrupt mask. Note that, for Tx fill and Rx FIFO drain requests, enabling the interrupt request disables the DMA request.

Parameters
baseLPSPI peripheral address.
maskThe interrupt mask; Use the enum _lpspi_interrupt_enable.
static void LPSPI_DisableInterrupts ( LPSPI_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPSPI peripheral address.
maskThe interrupt mask; Use the enum _lpspi_interrupt_enable.
static void LPSPI_EnableDMA ( LPSPI_Type *  base,
uint32_t  mask 
)
inlinestatic

This function configures the Rx and Tx DMA mask of the LPSPI. The parameters are base and a DMA mask.

Parameters
baseLPSPI peripheral address.
maskThe interrupt mask; Use the enum _lpspi_dma_enable.
static void LPSPI_DisableDMA ( LPSPI_Type *  base,
uint32_t  mask 
)
inlinestatic

This function configures the Rx and Tx DMA mask of the LPSPI. The parameters are base and a DMA mask.

* SPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
*
Parameters
baseLPSPI peripheral address.
maskThe interrupt mask; Use the enum _lpspi_dma_enable.
static uint32_t LPSPI_GetTxRegisterAddress ( LPSPI_Type *  base)
inlinestatic

This function gets the LPSPI Transmit Data Register address because this value is needed for the DMA operation. This function can be used for either master or slave mode.

Parameters
baseLPSPI peripheral address.
Returns
The LPSPI Transmit Data Register address.
static uint32_t LPSPI_GetRxRegisterAddress ( LPSPI_Type *  base)
inlinestatic

This function gets the LPSPI Receive Data Register address because this value is needed for the DMA operation. This function can be used for either master or slave mode.

Parameters
baseLPSPI peripheral address.
Returns
The LPSPI Receive Data Register address.
bool LPSPI_CheckTransferArgument ( lpspi_transfer_t transfer,
uint32_t  bitsPerFrame,
uint32_t  bytesPerFrame 
)
Parameters
transferthe transfer struct to be used.
bitsPerFrameThe bit size of one frame.
bytesPerFrameThe byte size of one frame.
Returns
Return true for right and false for wrong.
static void LPSPI_SetMasterSlaveMode ( LPSPI_Type *  base,
lpspi_master_slave_mode_t  mode 
)
inlinestatic

Note that the CFGR1 should only be written when the LPSPI is disabled (LPSPIx_CR_MEN = 0).

Parameters
baseLPSPI peripheral address.
modeMode setting (master or slave) of type lpspi_master_slave_mode_t.
static void LPSPI_SelectTransferPCS ( LPSPI_Type *  base,
lpspi_which_pcs_t  select 
)
inlinestatic
Parameters
baseLPSPI peripheral address.
selectLPSPI Peripheral Chip Select (PCS) configuration.
static void LPSPI_SetPCSContinous ( LPSPI_Type *  base,
bool  IsContinous 
)
inlinestatic
Note
In master mode, continuous transfer will keep the PCS asserted at the end of the frame size, until a command word is received that starts a new frame. So PCS must be set back to uncontinuous when transfer finishes. In slave mode, when continuous transfer is enabled, the LPSPI will only transmit the first frame size bits, after that the LPSPI will transmit received data back (assuming a 32-bit shift register).
Parameters
baseLPSPI peripheral address.
IsContinousTrue to set the transfer PCS to continuous mode, false to set to uncontinuous mode.
static bool LPSPI_IsMaster ( LPSPI_Type *  base)
inlinestatic
Parameters
baseLPSPI peripheral address.
Returns
Returns true if the module is in master mode or false if the module is in slave mode.
static void LPSPI_FlushFifo ( LPSPI_Type *  base,
bool  flushTxFifo,
bool  flushRxFifo 
)
inlinestatic
Parameters
baseLPSPI peripheral address.
flushTxFifoFlushes (true) the Tx FIFO, else do not flush (false) the Tx FIFO.
flushRxFifoFlushes (true) the Rx FIFO, else do not flush (false) the Rx FIFO.
static void LPSPI_SetFifoWatermarks ( LPSPI_Type *  base,
uint32_t  txWater,
uint32_t  rxWater 
)
inlinestatic

This function allows the user to set the receive and transmit FIFO watermarks. The function does not compare the watermark settings to the FIFO size. The FIFO watermark should not be equal to or greater than the FIFO size. It is up to the higher level driver to make this check.

Parameters
baseLPSPI peripheral address.
txWaterThe TX FIFO watermark value. Writing a value equal or greater than the FIFO size is truncated.
rxWaterThe RX FIFO watermark value. Writing a value equal or greater than the FIFO size is truncated.
static void LPSPI_SetAllPcsPolarity ( LPSPI_Type *  base,
uint32_t  mask 
)
inlinestatic

Note that the CFGR1 should only be written when the LPSPI is disabled (LPSPIx_CR_MEN = 0).

This is an example: PCS0 and PCS1 set to active low and other PCSs set to active high. Note that the number of PCS is device-specific.

Parameters
baseLPSPI peripheral address.
maskThe PCS polarity mask; Use the enum _lpspi_pcs_polarity.
static void LPSPI_SetFrameSize ( LPSPI_Type *  base,
uint32_t  frameSize 
)
inlinestatic

The minimum frame size is 8-bits and the maximum frame size is 4096-bits. If the frame size is less than or equal to 32-bits, the word size and frame size are identical. If the frame size is greater than 32-bits, the word size is 32-bits for each word except the last (the last word contains the remainder bits if the frame size is not divisible by 32). The minimum word size is 2-bits. A frame size of 33-bits (or similar) is not supported.

Note 1: The transmit command register should be initialized before enabling the LPSPI in slave mode, although the command register does not update until after the LPSPI is enabled. After it is enabled, the transmit command register should only be changed if the LPSPI is idle.

Note 2: The transmit and command FIFO is a combined FIFO that includes both transmit data and command words. That means the TCR register should be written to when the Tx FIFO is not full.

Parameters
baseLPSPI peripheral address.
frameSizeThe frame size in number of bits.
uint32_t LPSPI_MasterSetBaudRate ( LPSPI_Type *  base,
uint32_t  baudRate_Bps,
uint32_t  srcClock_Hz,
uint32_t *  tcrPrescaleValue 
)

This function takes in the desired bitsPerSec (baud rate) and calculates the nearest possible baud rate without exceeding the desired baud rate and returns the calculated baud rate in bits-per-second. It requires the caller to provide the frequency of the module source clock (in Hertz). Note that the baud rate does not go into effect until the Transmit Control Register (TCR) is programmed with the prescale value. Hence, this function returns the prescale tcrPrescaleValue parameter for later programming in the TCR. The higher level peripheral driver should alert the user of an out of range baud rate input.

Note that the LPSPI module must first be disabled before configuring this. Note that the LPSPI module must be configured for master mode before configuring this.

Parameters
baseLPSPI peripheral address.
baudRate_BpsThe desired baud rate in bits per second.
srcClock_HzModule source input clock in Hertz.
tcrPrescaleValueThe TCR prescale value needed to program the TCR.
Returns
The actual calculated baud rate. This function may also return a "0" if the LPSPI is not configured for master mode or if the LPSPI module is not disabled.
void LPSPI_MasterSetDelayScaler ( LPSPI_Type *  base,
uint32_t  scaler,
lpspi_delay_type_t  whichDelay 
)

This function configures the following: SCK to PCS delay, or PCS to SCK delay, or The configurations must occur between the transfer delay.

The delay names are available in type lpspi_delay_type_t.

The user passes the desired delay along with the delay value. This allows the user to directly set the delay values if they have pre-calculated them or if they simply wish to manually increment the value.

Note that the LPSPI module must first be disabled before configuring this. Note that the LPSPI module must be configured for master mode before configuring this.

Parameters
baseLPSPI peripheral address.
scalerThe 8-bit delay value 0x00 to 0xFF (255).
whichDelayThe desired delay to configure, must be of type lpspi_delay_type_t.
uint32_t LPSPI_MasterSetDelayTimes ( LPSPI_Type *  base,
uint32_t  delayTimeInNanoSec,
lpspi_delay_type_t  whichDelay,
uint32_t  srcClock_Hz 
)

This function calculates the values for the following: SCK to PCS delay, or PCS to SCK delay, or The configurations must occur between the transfer delay.

The delay names are available in type lpspi_delay_type_t.

The user passes the desired delay and the desired delay value in nano-seconds. The function calculates the value needed for the desired delay parameter and returns the actual calculated delay because an exact delay match may not be possible. In this case, the closest match is calculated without going below the desired delay value input. It is possible to input a very large delay value that exceeds the capability of the part, in which case the maximum supported delay is returned. It is up to the higher level peripheral driver to alert the user of an out of range delay input.

Note that the LPSPI module must be configured for master mode before configuring this. And note that the delayTime = LPSPI_clockSource / (PRESCALE * Delay_scaler).

Parameters
baseLPSPI peripheral address.
delayTimeInNanoSecThe desired delay value in nano-seconds.
whichDelayThe desired delay to configuration, which must be of type lpspi_delay_type_t.
srcClock_HzModule source input clock in Hertz.
Returns
actual Calculated delay value in nano-seconds.
static void LPSPI_WriteData ( LPSPI_Type *  base,
uint32_t  data 
)
inlinestatic

This function writes data passed in by the user to the Transmit Data Register (TDR). The user can pass up to 32-bits of data to load into the TDR. If the frame size exceeds 32-bits, the user has to manage sending the data one 32-bit word at a time. Any writes to the TDR result in an immediate push to the transmit FIFO. This function can be used for either master or slave modes.

Parameters
baseLPSPI peripheral address.
dataThe data word to be sent.
static uint32_t LPSPI_ReadData ( LPSPI_Type *  base)
inlinestatic

This function reads the data from the Receive Data Register (RDR). This function can be used for either master or slave mode.

Parameters
baseLPSPI peripheral address.
Returns
The data read from the data buffer.
void LPSPI_SetDummyData ( LPSPI_Type *  base,
uint8_t  dummyData 
)
Parameters
baseLPSPI peripheral address.
dummyDataData to be transferred when tx buffer is NULL. Note: This API has no effect when LPSPI in slave interrupt mode, because driver will set the TXMSK bit to 1 if txData is NULL, no data is loaded from transmit FIFO and output pin is tristated.
void LPSPI_MasterTransferCreateHandle ( LPSPI_Type *  base,
lpspi_master_handle_t *  handle,
lpspi_master_transfer_callback_t  callback,
void *  userData 
)

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

Parameters
baseLPSPI peripheral address.
handleLPSPI handle pointer to lpspi_master_handle_t.
callbackDSPI callback.
userDatacallback function parameter.
status_t LPSPI_MasterTransferBlocking ( LPSPI_Type *  base,
lpspi_transfer_t transfer 
)

This function transfers data using a polling method. This is a blocking function, which does not return until all transfers have been completed.

Note: The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4. For bytesPerFrame greater than 4: The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4. Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.

Parameters
baseLPSPI peripheral address.
transferpointer to lpspi_transfer_t structure.
Returns
status of status_t.
status_t LPSPI_MasterTransferNonBlocking ( LPSPI_Type *  base,
lpspi_master_handle_t *  handle,
lpspi_transfer_t transfer 
)

This function transfers data using an interrupt method. This is a non-blocking function, which returns right away. When all data is transferred, the callback function is called.

Note: The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4. For bytesPerFrame greater than 4: The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4. Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_master_handle_t structure which stores the transfer state.
transferpointer to lpspi_transfer_t structure.
Returns
status of status_t.
status_t LPSPI_MasterTransferGetCount ( LPSPI_Type *  base,
lpspi_master_handle_t *  handle,
size_t *  count 
)

This function gets the master transfer remaining bytes.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_master_handle_t structure which stores the transfer state.
countNumber of bytes transferred so far by the non-blocking transaction.
Returns
status of status_t.
void LPSPI_MasterTransferAbort ( LPSPI_Type *  base,
lpspi_master_handle_t *  handle 
)

This function aborts a transfer which uses an interrupt method.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_master_handle_t structure which stores the transfer state.
void LPSPI_MasterTransferHandleIRQ ( LPSPI_Type *  base,
lpspi_master_handle_t *  handle 
)

This function processes the LPSPI transmit and receive IRQ.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_master_handle_t structure which stores the transfer state.
void LPSPI_SlaveTransferCreateHandle ( LPSPI_Type *  base,
lpspi_slave_handle_t *  handle,
lpspi_slave_transfer_callback_t  callback,
void *  userData 
)

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

Parameters
baseLPSPI peripheral address.
handleLPSPI handle pointer to lpspi_slave_handle_t.
callbackDSPI callback.
userDatacallback function parameter.
status_t LPSPI_SlaveTransferNonBlocking ( LPSPI_Type *  base,
lpspi_slave_handle_t *  handle,
lpspi_transfer_t transfer 
)

This function transfer data using an interrupt method. This is a non-blocking function, which returns right away. When all data is transferred, the callback function is called.

Note: The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4. For bytesPerFrame greater than 4: The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not an integer multiple of 4. Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_slave_handle_t structure which stores the transfer state.
transferpointer to lpspi_transfer_t structure.
Returns
status of status_t.
status_t LPSPI_SlaveTransferGetCount ( LPSPI_Type *  base,
lpspi_slave_handle_t *  handle,
size_t *  count 
)

This function gets the slave transfer remaining bytes.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_slave_handle_t structure which stores the transfer state.
countNumber of bytes transferred so far by the non-blocking transaction.
Returns
status of status_t.
void LPSPI_SlaveTransferAbort ( LPSPI_Type *  base,
lpspi_slave_handle_t *  handle 
)

This function aborts a transfer which uses an interrupt method.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_slave_handle_t structure which stores the transfer state.
void LPSPI_SlaveTransferHandleIRQ ( LPSPI_Type *  base,
lpspi_slave_handle_t *  handle 
)

This function processes the LPSPI transmit and receives an IRQ.

Parameters
baseLPSPI peripheral address.
handlepointer to lpspi_slave_handle_t structure which stores the transfer state.

Variable Documentation

volatile uint8_t g_lpspiDummyData[]