| Nano100AN Series BSP V3.02.002 The Board Support Package for Nano100AN Series

Macros | Functions
SPI Exported Functions
NANO100 Device Driver » SPI Driver

## Macros
#define | SPI_ABORT_3WIRE_TRANSFER(spi)
| Abort the current transfer in slave 3-wire mode. More...
#define | SPI_CLR_3WIRE_START_INT_FLAG(spi)
| Clear the slave 3-wire mode start interrupt flag. More...
#define | SPI_CLR_UNIT_TRANS_INT_FLAG(spi)
| Clear the unit transfer interrupt flag. More...
#define | SPI_DISABLE_3WIRE_MODE(spi)
| Disable slave 3-wire mode. More...
#define | SPI_ENABLE_3WIRE_MODE(spi)
| Enable slave 3-wire mode. More...
#define | SPI_GET_RX_FIFO_EMPTY_FLAG(spi)
| Get the Rx FIFO empty flag. More...
#define | SPI_GET_TX_FIFO_EMPTY_FLAG(spi)
| Get the Tx FIFO empty flag. More...
#define | SPI_GET_TX_FIFO_FULL_FLAG(spi)
| Get the Tx FIFO full flag. More...
#define | SPI_READ_RX0(spi)
| Get the datum read from RX0 FIFO. More...
#define | SPI_READ_RX1(spi) ( (spi)->RX1 )
| Get the datum read from RX1 FIFO. More...
#define | SPI_WRITE_TX0(spi, u32TxData)
| Write datum to TX0 register. More...
#define | SPI_WRITE_TX1(spi, u32TxData)
| Write datum to TX1 register. More...
#define | SPI_ENABLE_BYTE_REORDER(spi)
| Enable byte reorder function. More...
#define | SPI_DISABLE_BYTE_REORDER(spi)
| Disable byte reorder function. More...
#define | SPI_SET_SUSPEND_CYCLE(spi, u32SuspCycle)
| Set the length of suspend interval. More...
#define | SPI_SET_LSB_FIRST(spi)
| Set the SPI transfer sequence with LSB first. More...
#define | SPI_SET_MSB_FIRST(spi)
| Set the SPI transfer sequence with MSB first. More...
#define | SPI_IS_BUSY(spi)
| Get the SPI busy state. More...
#define | SPI_TRIGGER(spi)
| Set the GO_BUSY bit to trigger SPI transfer. More...
#define | SPI_TRIGGER_RX_PDMA(spi)
| Trigger RX PDMA transfer. More...
#define | SPI_TRIGGER_TX_PDMA(spi)
| Trigger TX PDMA transfer. More...
#define | SPI_ENABLE_2BIT_MODE(spi)
| Enable 2-bit transfer mode. More...
#define | SPI_DISABLE_2BIT_MODE(spi)
| Disable 2-bit transfer mode. More...
#define | SPI_GET_STATUS(spi)
| Get the status register value. More...

## Functions
static __INLINE void | SPI_SET_SS0_HIGH (SPI_T *spi)
| Disable automatic slave select function and set SPI_SS pin to high state. More...
static __INLINE void | SPI_SET_SS0_LOW (SPI_T *spi)
| Disable automatic slave select function and set SPI_SS pin to low state. More...
static __INLINE void | SPI_SET_SS1_HIGH (SPI_T *spi)
| Disable automatic slave select function and set SPI_SS pin to high state. More...
static __INLINE void | SPI_SET_SS1_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. 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)
| 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...
void | SPI_EnableWakeup (SPI_T *spi)
| Enable wake-up function. More...
void | SPI_DisableWakeup (SPI_T *spi)
| Disable wake-up function. More...

## Detailed Description

## Macro Definition Documentation

## ◆ SPI_ABORT_3WIRE_TRANSFER

#define SPI_ABORT_3WIRE_TRANSFER | ( |  | spi | ) |

Abort the current transfer in slave 3-wire mode.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 66 of file spi.h.

## ◆ SPI_CLR_3WIRE_START_INT_FLAG

#define SPI_CLR_3WIRE_START_INT_FLAG | ( |  | spi | ) |

Clear the slave 3-wire mode start interrupt flag.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 74 of file spi.h.

## ◆ SPI_CLR_UNIT_TRANS_INT_FLAG

#define SPI_CLR_UNIT_TRANS_INT_FLAG | ( |  | spi | ) |

Clear the unit transfer interrupt flag.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 82 of file spi.h.

## ◆ SPI_DISABLE_2BIT_MODE

#define SPI_DISABLE_2BIT_MODE | ( |  | spi | ) |

Disable 2-bit transfer mode.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 323 of file spi.h.

## ◆ SPI_DISABLE_3WIRE_MODE

#define SPI_DISABLE_3WIRE_MODE | ( |  | spi | ) |

Disable slave 3-wire mode.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 90 of file spi.h.

## ◆ SPI_DISABLE_BYTE_REORDER

#define SPI_DISABLE_BYTE_REORDER | ( |  | spi | ) |

Disable byte reorder function.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 233 of file spi.h.

## ◆ SPI_ENABLE_2BIT_MODE

#define SPI_ENABLE_2BIT_MODE | ( |  | spi | ) |

Enable 2-bit transfer mode.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 315 of file spi.h.

## ◆ SPI_ENABLE_3WIRE_MODE

#define SPI_ENABLE_3WIRE_MODE | ( |  | spi | ) |

Enable slave 3-wire mode.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 98 of file spi.h.

## ◆ SPI_ENABLE_BYTE_REORDER

#define SPI_ENABLE_BYTE_REORDER | ( |  | spi | ) |

Enable byte reorder function.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 225 of file spi.h.

## ◆ SPI_GET_RX_FIFO_EMPTY_FLAG

#define SPI_GET_RX_FIFO_EMPTY_FLAG | ( |  | spi | ) |

Get the Rx FIFO empty flag.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  Rx FIFO flag

Return values

  0 | Rx FIFO is not empty
  1 | Rx FIFO is empty

Definition at line 108 of file spi.h.

## ◆ SPI_GET_STATUS

#define SPI_GET_STATUS | ( |  | spi | ) |

Get the status register value.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  status value.

Definition at line 331 of file spi.h.

## ◆ SPI_GET_TX_FIFO_EMPTY_FLAG

#define SPI_GET_TX_FIFO_EMPTY_FLAG | ( |  | spi | ) |

Get the Tx FIFO empty flag.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  Tx FIFO flag

Return values

  0 | Tx FIFO is not empty
  1 | Tx 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 | ) |

Get the Tx FIFO full flag.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  Tx FIFO flag

Return values

  0 | Tx FIFO is not full
  1 | Tx FIFO is full

Definition at line 128 of file spi.h.

## ◆ SPI_IS_BUSY

#define SPI_IS_BUSY | ( |  | spi | ) |

Get the SPI busy state.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  SPI busy status

Return values

  0 | SPI module is not busy
  1 | SPI module is busy

Definition at line 283 of file spi.h.

## ◆ SPI_READ_RX0

#define SPI_READ_RX0 | ( |  | spi | ) |

Get the datum read from RX0 FIFO.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  Data in Rx0 register.

Definition at line 136 of file spi.h.

## ◆ SPI_READ_RX1

#define SPI_READ_RX1 | ( |  | spi | ) | ( (spi)->RX1 )

Get the datum read from RX1 FIFO.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  Data in Rx1 register.

Definition at line 143 of file spi.h.

## ◆ SPI_SET_LSB_FIRST

#define SPI_SET_LSB_FIRST | ( |  | spi | ) |

Set the SPI transfer sequence with LSB first.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 250 of file spi.h.

## ◆ SPI_SET_MSB_FIRST

#define SPI_SET_MSB_FIRST | ( |  | spi | ) |

Set the SPI transfer sequence with MSB first.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 258 of file spi.h.

## ◆ SPI_SET_SUSPEND_CYCLE

#define SPI_SET_SUSPEND_CYCLE | ( |  | spi,
|  |  | u32SuspCycle
| ) |  |

Set the length of suspend interval.

Parameters

  [in] | spi | is the base address of SPI module.
  [in] | u32SuspCycle | decides the length of suspend interval.

Returns
  none

Definition at line 242 of file spi.h.

## ◆ SPI_TRIGGER

#define SPI_TRIGGER | ( |  | spi | ) |

Set the GO_BUSY bit to trigger SPI transfer.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 291 of file spi.h.

## ◆ SPI_TRIGGER_RX_PDMA

#define SPI_TRIGGER_RX_PDMA | ( |  | spi | ) |

Trigger RX PDMA transfer.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 299 of file spi.h.

## ◆ SPI_TRIGGER_TX_PDMA

#define SPI_TRIGGER_TX_PDMA | ( |  | spi | ) |

Trigger TX PDMA transfer.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 307 of file spi.h.

## ◆ SPI_WRITE_TX0

#define SPI_WRITE_TX0 | ( |  | spi,
|  |  | u32TxData
| ) |  |

Write datum to TX0 register.

Parameters

  [in] | spi | is the base address of SPI module.
  [in] | u32TxData | is the datum which user attempt to transfer through SPI bus.

Returns
  none

Definition at line 152 of file spi.h.

## ◆ SPI_WRITE_TX1

#define SPI_WRITE_TX1 | ( |  | spi,
|  |  | u32TxData
| ) |  |

Write datum to TX1 register.

Parameters

  [in] | spi | is the base address of SPI module.
  [in] | u32TxData | is the datum which user attempt to transfer through SPI bus.

Returns
  none

Definition at line 161 of file spi.h.

## Function Documentation

## ◆ SPI_ClearRxFIFO()

void SPI_ClearRxFIFO | ( | SPI_T * | spi | ) |

Clear Rx FIFO buffer.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 85 of file spi.c.

## ◆ SPI_ClearTxFIFO()

void SPI_ClearTxFIFO | ( | SPI_T * | spi | ) |

Clear Tx FIFO buffer.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 95 of file spi.c.

## ◆ SPI_Close()

void SPI_Close | ( | SPI_T * | spi | ) |

Reset SPI module.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 60 of file spi.c.

## ◆ SPI_DisableAutoSS()

void SPI_DisableAutoSS | ( | SPI_T * | spi | ) |

Disable the automatic slave select function.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 105 of file spi.c.

## ◆ SPI_DisableFIFO()

void SPI_DisableFIFO | ( | SPI_T * | spi | ) |

Disable FIFO mode.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 166 of file spi.c.

## ◆ SPI_DisableInt()

void SPI_DisableInt | ( | SPI_T * | spi,
|  | uint32_t | u32Mask
| ) |  |

Disable FIFO related interrupts specified by u32Mask parameter.

Parameters

  [in] | spi | is the base address of SPI module.
  [in] | u32Mask | is the combination of all related interrupt enable bits. Each bit corresponds to a interrupt bit. This parameter decides which interrupts will be enabled. Valid values are: SPI_IE_MASK SPI_SSTA_INTEN_MASK

Returns
  none

Definition at line 216 of file spi.c.

## ◆ SPI_DisableWakeup()

void SPI_DisableWakeup | ( | SPI_T * | spi | ) |

Disable wake-up function.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 240 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

  [in] | spi | is the base address of SPI module.
  [in] | u32SSPinMask | specifies slave select pins. ( SPI_SS0 or SPI_SS1 )
  [in] | u32ActiveLevel | specifies the active level of slave select signal. ( SPI_SS0_ACTIVE_HIGH, SPI_SS0_ACTIVE_LOW, SPI_SS1_ACTIVE_HIGH, or SPI_SS1_ACTIVE_LOW)

Returns
  none

Definition at line 117 of file spi.c.

## ◆ SPI_EnableFIFO()

void SPI_EnableFIFO | ( | SPI_T * | spi | ) |

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

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 156 of file spi.c.

## ◆ SPI_EnableInt()

void SPI_EnableInt | ( | SPI_T * | spi,
|  | uint32_t | u32Mask
| ) |  |

Enable FIFO related interrupts specified by u32Mask parameter.

Parameters

  [in] | spi | is the base address of SPI module.
  [in] | u32Mask | is the combination of all related interrupt enable bits. Each bit corresponds to a interrupt bit. This parameter decides which interrupts will be enabled. Valid values are: SPI_IE_MASK SPI_SSTA_INTEN_MASK

Returns
  none

Definition at line 197 of file spi.c.

## ◆ SPI_EnableWakeup()

void SPI_EnableWakeup | ( | SPI_T * | spi | ) |

Enable wake-up function.

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 230 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

  [in] | spi | is the base address of SPI module.

Returns
  Actual SPI bus clock frequency.

Definition at line 176 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

  [in] | spi | is the base address of SPI module.
  [in] | u32MasterSlave | decides the SPI module is operating in master mode or in slave mode. ( SPI_SLAVE, SPI_MASTER)
  [in] | u32SPIMode | decides the transfer timing. ( SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3)
  [in] | u32DataWidth | decides the data width of a SPI transaction.
  [in] | u32BusClock | is the expected frequency of SPI bus clock in Hz.

Returns
  Actual frequency of SPI peripheral clock.

Definition at line 41 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

  [in] | spi | is the base address of SPI module.
  [in] | u32Width | is the data width (from 8-32 bits).

Returns
  none

Definition at line 267 of file spi.h.

## ◆ SPI_SET_SS0_HIGH()

static __INLINE void SPI_SET_SS0_HIGH | ( | SPI_T * | spi | ) |
| static

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

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 169 of file spi.h.

## ◆ SPI_SET_SS0_LOW()

static __INLINE void SPI_SET_SS0_LOW | ( | SPI_T * | spi | ) |
| static

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

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 183 of file spi.h.

## ◆ SPI_SET_SS1_HIGH()

static __INLINE void SPI_SET_SS1_HIGH | ( | SPI_T * | spi | ) |
| static

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

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 197 of file spi.h.

## ◆ SPI_SET_SS1_LOW()

static __INLINE void SPI_SET_SS1_LOW | ( | SPI_T * | spi | ) |
| static

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

Parameters

  [in] | spi | is the base address of SPI module.

Returns
  none

Definition at line 211 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

  [in] | spi | is the base address of SPI module.
  [in] | u32BusClock | is the expected frequency of SPI bus clock.

Returns
  Actual frequency of SPI peripheral clock.

Definition at line 128 of file spi.c.