Mini51 BSP  V3.02.002
The Board Support Package for Mini51 Series
Macros | Functions
SPI Exported Functions

Macros

#define SPI_ABORT_3WIRE_TRANSFER(spi)   ( (spi)->CNTRL2 |= SPI_CNTRL2_SLV_ABORT_Msk )
 Abort the current transfer in slave 3-wire mode. More...
 
#define SPI_CLR_3WIRE_START_INT_FLAG(spi)   ( (spi)->STATUS = SPI_STATUS_SLV_START_INTSTS_Msk )
 Clear the slave 3-wire mode start interrupt flag. More...
 
#define SPI_CLR_UNIT_TRANS_INT_FLAG(spi)   ( (spi)->STATUS = SPI_STATUS_IF_Msk )
 Clear the unit transfer interrupt flag. More...
 
#define SPI_DISABLE_3WIRE_MODE(spi)   ( (spi)->CNTRL2 &= ~SPI_CNTRL2_NOSLVSEL_Msk )
 Disable slave 3-wire mode. More...
 
#define SPI_ENABLE_3WIRE_MODE(spi)   ( (spi)->CNTRL2 |= SPI_CNTRL2_NOSLVSEL_Msk )
 Enable slave 3-wire mode. More...
 
#define SPI_GET_RX_FIFO_COUNT(spi)   ( (((spi)->STATUS & SPI_STATUS_RX_FIFO_COUNT_Msk) >> SPI_STATUS_RX_FIFO_COUNT_Pos) & 0xf )
 Get the count of available data in RX FIFO. More...
 
#define SPI_GET_RX_FIFO_EMPTY_FLAG(spi)   ( ((spi)->STATUS & SPI_STATUS_RX_EMPTY_Msk) == SPI_STATUS_RX_EMPTY_Msk ? 1:0 )
 Get the Rx FIFO empty flag. More...
 
#define SPI_GET_TX_FIFO_EMPTY_FLAG(spi)   ( ((spi)->STATUS & SPI_STATUS_TX_EMPTY_Msk) == SPI_STATUS_TX_EMPTY_Msk ? 1:0 )
 Get the Tx FIFO empty flag. More...
 
#define SPI_GET_TX_FIFO_FULL_FLAG(spi)   ( ((spi)->STATUS & SPI_STATUS_TX_FULL_Msk) == SPI_STATUS_TX_FULL_Msk ? 1:0 )
 Get the Tx FIFO full flag. More...
 
#define SPI_READ_RX(spi)   ( (spi)->RX )
 Get the datum read from Rx FIFO. More...
 
#define SPI_WRITE_TX(spi, u32TxData)   ( (spi)->TX = u32TxData )
 Write datum to TX register. More...
 
#define SPI_ENABLE_BYTE_REORDER(spi)   ( (spi)->CNTRL |= SPI_CNTRL_REORDER_Msk )
 Enable byte reorder function. More...
 
#define SPI_DISABLE_BYTE_REORDER(spi)   ( (spi)->CNTRL &= ~SPI_CNTRL_REORDER_Msk )
 Disable byte reorder function. More...
 
#define SPI_SET_SUSPEND_CYCLE(spi, u32SuspCycle)   ( (spi)->CNTRL = ((spi)->CNTRL & ~SPI_CNTRL_SP_CYCLE_Msk) | (u32SuspCycle << SPI_CNTRL_SP_CYCLE_Pos) )
 Set the length of suspend interval. More...
 
#define SPI_SET_LSB_FIRST(spi)   ( (spi)->CNTRL |= SPI_CNTRL_LSB_Msk )
 Set the SPI transfer sequence with LSB first. More...
 
#define SPI_SET_MSB_FIRST(spi)   ( (spi)->CNTRL &= ~SPI_CNTRL_LSB_Msk )
 Set the SPI transfer sequence with MSB first. More...
 
#define SPI_IS_BUSY(spi)   ( ((spi)->CNTRL & SPI_CNTRL_GO_BUSY_Msk) == SPI_CNTRL_GO_BUSY_Msk ? 1:0 )
 Get the SPI busy state. More...
 
#define SPI_TRIGGER(spi)   ( (spi)->CNTRL |= SPI_CNTRL_GO_BUSY_Msk )
 Set the GO_BUSY bit to trigger SPI transfer. More...
 

Functions

static __INLINE void SPI_SET_SS_HIGH (SPI_T *spi)
 Disable automatic slave select function and set SPI_SS pin to high state. More...
 
static __INLINE void SPI_SET_SS_LOW (SPI_T *spi)
 Disable automatic slave select function and set SPI_SS pin to low state. More...
 
static __INLINE void SPI_SET_DATA_WIDTH (SPI_T *spi, uint32_t u32Width)
 Set the data width of a SPI transaction. More...
 
uint32_t SPI_Open (SPI_T *spi, uint32_t u32MasterSlave, uint32_t u32SPIMode, uint32_t u32DataWidth, uint32_t u32BusClock)
 This function make SPI module be ready to transfer. By default, the SPI transfer sequence is MSB first and the automatic slave select function is disabled. In Slave mode, the u32BusClock must be NULL and the SPI clock divider setting will be 0. More...
 
void SPI_Close (SPI_T *spi)
 Reset SPI module and disable SPI peripheral clock. More...
 
void SPI_ClearRxFIFO (SPI_T *spi)
 Clear Rx FIFO buffer. More...
 
void SPI_ClearTxFIFO (SPI_T *spi)
 Clear Tx FIFO buffer. More...
 
void SPI_DisableAutoSS (SPI_T *spi)
 Disable the automatic slave select function. More...
 
void SPI_EnableAutoSS (SPI_T *spi, uint32_t u32SSPinMask, uint32_t u32ActiveLevel)
 Enable the automatic slave select function. Only available in Master mode. More...
 
uint32_t SPI_SetBusClock (SPI_T *spi, uint32_t u32BusClock)
 Set the SPI bus clock. Only available in Master mode. More...
 
void SPI_EnableFIFO (SPI_T *spi, uint32_t u32TxThreshold, uint32_t u32RxThreshold)
 Enable FIFO mode with user-specified Tx FIFO threshold and Rx FIFO threshold configurations. More...
 
void SPI_DisableFIFO (SPI_T *spi)
 Disable FIFO mode. More...
 
uint32_t SPI_GetBusClock (SPI_T *spi)
 Get the actual frequency of SPI bus clock. Only available in Master mode. More...
 
void SPI_EnableInt (SPI_T *spi, uint32_t u32Mask)
 Enable FIFO related interrupts specified by u32Mask parameter. More...
 
void SPI_DisableInt (SPI_T *spi, uint32_t u32Mask)
 Disable FIFO related interrupts specified by u32Mask parameter. More...
 

Detailed Description

Macro Definition Documentation

◆ SPI_ABORT_3WIRE_TRANSFER

#define SPI_ABORT_3WIRE_TRANSFER (   spi)    ( (spi)->CNTRL2 |= SPI_CNTRL2_SLV_ABORT_Msk )

Abort the current transfer in slave 3-wire mode.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 65 of file spi.h.

◆ SPI_CLR_3WIRE_START_INT_FLAG

#define SPI_CLR_3WIRE_START_INT_FLAG (   spi)    ( (spi)->STATUS = SPI_STATUS_SLV_START_INTSTS_Msk )

Clear the slave 3-wire mode start interrupt flag.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 72 of file spi.h.

◆ SPI_CLR_UNIT_TRANS_INT_FLAG

#define SPI_CLR_UNIT_TRANS_INT_FLAG (   spi)    ( (spi)->STATUS = SPI_STATUS_IF_Msk )

Clear the unit transfer interrupt flag.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 79 of file spi.h.

◆ SPI_DISABLE_3WIRE_MODE

#define SPI_DISABLE_3WIRE_MODE (   spi)    ( (spi)->CNTRL2 &= ~SPI_CNTRL2_NOSLVSEL_Msk )

Disable slave 3-wire mode.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 86 of file spi.h.

◆ SPI_DISABLE_BYTE_REORDER

#define SPI_DISABLE_BYTE_REORDER (   spi)    ( (spi)->CNTRL &= ~SPI_CNTRL_REORDER_Msk )

Disable byte reorder function.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 180 of file spi.h.

◆ SPI_ENABLE_3WIRE_MODE

#define SPI_ENABLE_3WIRE_MODE (   spi)    ( (spi)->CNTRL2 |= SPI_CNTRL2_NOSLVSEL_Msk )

Enable slave 3-wire mode.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 93 of file spi.h.

◆ SPI_ENABLE_BYTE_REORDER

#define SPI_ENABLE_BYTE_REORDER (   spi)    ( (spi)->CNTRL |= SPI_CNTRL_REORDER_Msk )

Enable byte reorder function.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 173 of file spi.h.

◆ SPI_GET_RX_FIFO_COUNT

#define SPI_GET_RX_FIFO_COUNT (   spi)    ( (((spi)->STATUS & SPI_STATUS_RX_FIFO_COUNT_Msk) >> SPI_STATUS_RX_FIFO_COUNT_Pos) & 0xf )

Get the count of available data in RX FIFO.

Parameters
spiis the base address of SPI module.
Returns
The count of available data in RX FIFO.

Definition at line 100 of file spi.h.

◆ SPI_GET_RX_FIFO_EMPTY_FLAG

#define SPI_GET_RX_FIFO_EMPTY_FLAG (   spi)    ( ((spi)->STATUS & SPI_STATUS_RX_EMPTY_Msk) == SPI_STATUS_RX_EMPTY_Msk ? 1:0 )

Get the Rx FIFO empty flag.

Parameters
spiis the base address of SPI module.
Returns
Rx FIFO flag
Return values
0Rx FIFO is not empty
1Rx FIFO is empty

Definition at line 109 of file spi.h.

◆ SPI_GET_TX_FIFO_EMPTY_FLAG

#define SPI_GET_TX_FIFO_EMPTY_FLAG (   spi)    ( ((spi)->STATUS & SPI_STATUS_TX_EMPTY_Msk) == SPI_STATUS_TX_EMPTY_Msk ? 1:0 )

Get the Tx FIFO empty flag.

Parameters
spiis the base address of SPI module.
Returns
Tx FIFO flag
Return values
0Tx FIFO is not empty
1Tx FIFO is empty

Definition at line 118 of file spi.h.

◆ SPI_GET_TX_FIFO_FULL_FLAG

#define SPI_GET_TX_FIFO_FULL_FLAG (   spi)    ( ((spi)->STATUS & SPI_STATUS_TX_FULL_Msk) == SPI_STATUS_TX_FULL_Msk ? 1:0 )

Get the Tx FIFO full flag.

Parameters
spiis the base address of SPI module.
Returns
Tx FIFO flag
Return values
0Tx FIFO is not full
1Tx FIFO is full

Definition at line 127 of file spi.h.

◆ SPI_IS_BUSY

#define SPI_IS_BUSY (   spi)    ( ((spi)->CNTRL & SPI_CNTRL_GO_BUSY_Msk) == SPI_CNTRL_GO_BUSY_Msk ? 1:0 )

Get the SPI busy state.

Parameters
spiis the base address of SPI module.
Returns
SPI busy status
Return values
0SPI module is not busy
1SPI module is busy

Definition at line 225 of file spi.h.

◆ SPI_READ_RX

#define SPI_READ_RX (   spi)    ( (spi)->RX )

Get the datum read from Rx FIFO.

Parameters
spiis the base address of SPI module.
Returns
Data in Rx buffer

Definition at line 134 of file spi.h.

◆ SPI_SET_LSB_FIRST

#define SPI_SET_LSB_FIRST (   spi)    ( (spi)->CNTRL |= SPI_CNTRL_LSB_Msk )

Set the SPI transfer sequence with LSB first.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 195 of file spi.h.

◆ SPI_SET_MSB_FIRST

#define SPI_SET_MSB_FIRST (   spi)    ( (spi)->CNTRL &= ~SPI_CNTRL_LSB_Msk )

Set the SPI transfer sequence with MSB first.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 202 of file spi.h.

◆ SPI_SET_SUSPEND_CYCLE

#define SPI_SET_SUSPEND_CYCLE (   spi,
  u32SuspCycle 
)    ( (spi)->CNTRL = ((spi)->CNTRL & ~SPI_CNTRL_SP_CYCLE_Msk) | (u32SuspCycle << SPI_CNTRL_SP_CYCLE_Pos) )

Set the length of suspend interval.

Parameters
spiis the base address of SPI module.
u32SuspCycledecides the length of suspend interval.
Returns
none

Definition at line 188 of file spi.h.

◆ SPI_TRIGGER

#define SPI_TRIGGER (   spi)    ( (spi)->CNTRL |= SPI_CNTRL_GO_BUSY_Msk )

Set the GO_BUSY bit to trigger SPI transfer.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 232 of file spi.h.

◆ SPI_WRITE_TX

#define SPI_WRITE_TX (   spi,
  u32TxData 
)    ( (spi)->TX = u32TxData )

Write datum to TX register.

Parameters
spiis the base address of SPI module.
u32TxDatais the datum which user attempt to transfer through SPI bus.
Returns
none

Definition at line 142 of file spi.h.

Function Documentation

◆ SPI_ClearRxFIFO()

void SPI_ClearRxFIFO ( SPI_T spi)

Clear Rx FIFO buffer.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 87 of file spi.c.

◆ SPI_ClearTxFIFO()

void SPI_ClearTxFIFO ( SPI_T spi)

Clear Tx FIFO buffer.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 97 of file spi.c.

◆ SPI_Close()

void SPI_Close ( SPI_T spi)

Reset SPI module and disable SPI peripheral clock.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 75 of file spi.c.

◆ SPI_DisableAutoSS()

void SPI_DisableAutoSS ( SPI_T spi)

Disable the automatic slave select function.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 107 of file spi.c.

◆ SPI_DisableFIFO()

void SPI_DisableFIFO ( SPI_T spi)

Disable FIFO mode.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 172 of file spi.c.

◆ SPI_DisableInt()

void SPI_DisableInt ( SPI_T spi,
uint32_t  u32Mask 
)

Disable FIFO related interrupts specified by u32Mask parameter.

Parameters
spiis the base address of SPI module.
u32Maskis the combination of all related interrupt enable bits. Each bit corresponds to a interrupt bit. This parameter decides which interrupts will be disabled. (SPI_IE_MASK, SPI_SSTA_INTEN_MASK, SPI_FIFO_TX_INTEN_MASK, SPI_FIFO_RX_INTEN_MASK, SPI_FIFO_RXOV_INTEN_MASK, SPI_FIFO_TIMEOUT_INTEN_MASK)
Returns
none

Definition at line 233 of file spi.c.

◆ SPI_EnableAutoSS()

void SPI_EnableAutoSS ( SPI_T spi,
uint32_t  u32SSPinMask,
uint32_t  u32ActiveLevel 
)

Enable the automatic slave select function. Only available in Master mode.

Parameters
spiis the base address of SPI module.
u32SSPinMaskspecifies slave select pins. (SPI_SS)
u32ActiveLevelspecifies the active level of slave select signal. (SPI_SS_ACTIVE_HIGH, SPI_SS_ACTIVE_LOW)
Returns
none

Definition at line 119 of file spi.c.

◆ SPI_EnableFIFO()

void SPI_EnableFIFO ( SPI_T spi,
uint32_t  u32TxThreshold,
uint32_t  u32RxThreshold 
)

Enable FIFO mode with user-specified Tx FIFO threshold and Rx FIFO threshold configurations.

Parameters
spiis the base address of SPI module.
u32TxThresholddecides the Tx FIFO threshold.
u32RxThresholddecides the Rx FIFO threshold.
Returns
none

Definition at line 158 of file spi.c.

◆ SPI_EnableInt()

void SPI_EnableInt ( SPI_T spi,
uint32_t  u32Mask 
)

Enable FIFO related interrupts specified by u32Mask parameter.

Parameters
spiis the base address of SPI module.
u32Maskis the combination of all related interrupt enable bits. Each bit corresponds to a interrupt bit. This parameter decides which interrupts will be enabled. (SPI_IE_MASK, SPI_SSTA_INTEN_MASK, SPI_FIFO_TX_INTEN_MASK, SPI_FIFO_RX_INTEN_MASK, SPI_FIFO_RXOV_INTEN_MASK, SPI_FIFO_TIMEOUT_INTEN_MASK)
Returns
none

Definition at line 202 of file spi.c.

◆ SPI_GetBusClock()

uint32_t SPI_GetBusClock ( SPI_T spi)

Get the actual frequency of SPI bus clock. Only available in Master mode.

Parameters
spiis the base address of SPI module.
Returns
Actual SPI bus clock frequency.

Definition at line 182 of file spi.c.

◆ SPI_Open()

uint32_t SPI_Open ( SPI_T spi,
uint32_t  u32MasterSlave,
uint32_t  u32SPIMode,
uint32_t  u32DataWidth,
uint32_t  u32BusClock 
)

This function make SPI module be ready to transfer. By default, the SPI transfer sequence is MSB first and the automatic slave select function is disabled. In Slave mode, the u32BusClock must be NULL and the SPI clock divider setting will be 0.

Parameters
spiis the base address of SPI module.
u32MasterSlavedecides the SPI module is operating in master mode or in slave mode. (SPI_SLAVE, SPI_MASTER)
u32SPIModedecides the transfer timing. (SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3)
u32DataWidthdecides the data width of a SPI transaction.
u32BusClockis the expected frequency of SPI bus clock in Hz.
Returns
Actual frequency of SPI peripheral clock.

Definition at line 39 of file spi.c.

◆ SPI_SET_DATA_WIDTH()

static __INLINE void SPI_SET_DATA_WIDTH ( SPI_T spi,
uint32_t  u32Width 
)
static

Set the data width of a SPI transaction.

Parameters
spiis the base address of SPI module.
u32Widthis the bit width of transfer data.
Returns
none

Definition at line 210 of file spi.h.

◆ SPI_SET_SS_HIGH()

static __INLINE void SPI_SET_SS_HIGH ( SPI_T spi)
static

Disable automatic slave select function and set SPI_SS pin to high state.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 149 of file spi.h.

◆ SPI_SET_SS_LOW()

static __INLINE void SPI_SET_SS_LOW ( SPI_T spi)
static

Disable automatic slave select function and set SPI_SS pin to low state.

Parameters
spiis the base address of SPI module.
Returns
none

Definition at line 160 of file spi.h.

◆ SPI_SetBusClock()

uint32_t SPI_SetBusClock ( SPI_T spi,
uint32_t  u32BusClock 
)

Set the SPI bus clock. Only available in Master mode.

Parameters
spiis the base address of SPI module.
u32BusClockis the expected frequency of SPI bus clock.
Returns
Actual frequency of SPI peripheral clock.

Definition at line 130 of file spi.c.