SPI外设
1.SPI_setConfig(uint32_t base, uint32_t lspclkHz, SPI_TransferProtocol protocol,SPI_Mode mode, uint32_t bitRate, uint16_t dataWidth)
- function description: Used to configure the serial peripheral interface (SPI). It sets the protocol, operating mode, bit rate, and data width of the SPI. This is a basic function for initializing or modifying SPI module settings, allowing the user to adjust the behavior of the SPI based on hardware requirements or specific communication standards.
- parameter description:
- input parameters:
- base: The base address of the SPI module
- lspclkHz: Low speed peripheral clock frequency supplied to the SPI module
- sPI _ TransferProtocol protocol: Specifies the data transfer protocol. This parameter defines the format of the data frame. Optional values include:
- sPI _ PROT _ POL0PHA0: Clock Polarity 0, Phase 0
- sPI _ PROT _ POL0PHA1: Clock Polarity 0, Phase 1
- sPI _ PROT _ POL1 PHA0: clock polarity 1, phase 0
- sPI _ PROT _ POL1PHA1: clock polarity 1, phase 1
- sPI _ Mode mode: Defines the operating mode of the SPI module, either controller mode or peripheral mode, and whether the serial output line is disabled. Optional values include:
- sPI _ MODE _ CONTROLLER: controller model
- sPI _ MODE _ PERIPHERAL: peripheral model
- sPI _ MODE _ CONTROLLER _ OD: controller mode, output disabled
- sPI _ MODE _ PERIPHERAL _ OD: peripheral mode, output disabled
- bitRate: The communication rate of SPI, which cannot exceed lspclkHz/4, and the value of lspclkHz/bitRate cannot be greater than 128
- dataWidth: Number of data bits transmitted per frame
- return parameter:/
2.SPI_setBaudRate(uint32_t base, uint32_t lspclkHz, uint32_t bitRate)
- function description: Configure the baud rate of the serial peripheral interface
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- lspclkHz: Low speed peripheral clock frequency supplied to the SPI module
- bitRate: Specifies the clock frequency, which cannot exceed lspclkHz/4. The value of lspclkHz/bitRate cannot be greater than 128
- return parameter:/
3.SPI_enableInterrupt(uint32_t base, uint32_t intFlags)
- function description: This function enables a specific SPI interrupt. It enables one or more SPI interrupt types based on the interrupt flag bits provided, enabling the generation of an interrupt signal when an associated SPI event occurs, such as transmission completion, receive overflow, and so on.
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- intFlags: Flags that specify the type of interrupt to enable
- return parameter:/
4.SPI_disableInterrupt(uint32_t base, uint32_t intFlags)
- function description: Used to disable the specified SPI interrupt. This function prevents the corresponding interrupt type from triggering the interrupt handler by clearing the corresponding bit in the interrupt mask register in the SPI controller.
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- intFlags: Flags that specify the type of interrupt to enable
- return parameter:/
5.SPI_getInterruptStatus(uint32_t base)
- function description: Get the current interrupt status
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- return parameters:
returns the current interrupt status, enumerating the following values as a bit field:
- sPI _ INT _ RX _ OVERRUN: receive overrun interrupt
- sPI _ INT _ RX _ DATA _ TX _ EMPTY: data received, transmission is null
- sPI _ INT _ RXFF-RX FIFOs: Level interrupt
- sPI _ INT _ RXFF _ OVERFLOW-RX FIFOs: overrun
- sPI _ INT _ TXFF-TX FIFOs: Level interrupt
6.SPI_clearInterruptStatus(uint32_t base, uint32_t intFlags)
- function description: Clears the SPI interrupt sources
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- intFlags: is the bitmask of the interrupt source to be cleared and can consist of bit fields of the following values:
- SPI_INT_RX_OVERRUN
- sPI _ INT _ RX _ DATA _ TX _ EMPTY: The receive buffer is cleared by reading the receive signal, so there is normally no need to clear it using this method
- SPI_INT_RXFF
- SPI_INT_RXFF_OVERFLOW
- SPI_INT_TXFF
- return parameter:/
7.SPI_transmit24Bits(uint32_t base, uint32_t data, uint16_t txDelay)
- function description: This function can be used to transfer a 24-bit data word, which is divided into three bytes of data
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- data: is the data transmitted via SPI
- txDelay: Specifies the number of serial clock cycles and the delay time
- return parameter:/
8.SPI_transmit32Bits(uint32_t base, uint32_t data, uint16_t txDelay)
- function description:
- parameter description:
- input parameters: This function can be used to transfer 32-bit data words
- base: Specifies the SPI module base address
- data: is the data transmitted via SPI
- txDelay: Specifies the number of serial clock cycles and the delay time
- return parameter:/
9.SPI_receive16Bits(uint32_t base, SPI_endianess endianness, uint16_t dummyData, uint16_t txDelay)
- function description: The SPI _ receive16Bits function receives a 16-bit data-word. Initiates an SPI transaction to receive actual data from the SPI bus by sending dummy data dummyData
- parameter description:
- input parameters:
- base: The base address of the SPI module
- endianness: Specifies the endianness of the received data. You can use one of two values:
- sPI _ LITTLE _ ENDIAN-little end
- sPI _ BIG _ ENDIAN-Big Ends
- dummyData: Dummy data, which is sent to trigger an SPI transaction to receive actual data from the SPI bus
- txDelay: Serial clock cycle delay after completion of each word
- return parameters:
- sPI _ readData NonBlocking: 16-bit data-word received
10.SPI_receive24Bits(uint32_t base, SPI_endianess endianness, uint16_t dummyData, uint16_t txDelay)
- function description: The SPI _ receive24Bits function receives a 24-bit data-word. Initiates an SPI transaction to receive actual data from the SPI bus by sending dummy data dummyData
- parameter description:
- input parameters:
- base: The base address of the SPI module
- endianness: Specifies the endianness of the received data. You can use one of two values:
- sPI _ LITTLE _ ENDIAN-little end
- sPI _ BIG _ ENDIAN-Big Ends
- dummyData: Dummy data, which is sent to trigger an SPI transaction to receive actual data from the SPI bus
- txDelay: Serial clock cycle delay after completion of each word
- return parameters:
- sPI _ readData NonBlocking: 24-bit data-word received
11.SPI_receive32Bits(uint32_t base, SPI_endianess endianness, uint16_t dummyData, uint16_t txDelay)
- function description: The SPI _ receive32Bits function is used to receive a 32-bit data word. Initiates an SPI transaction to receive actual data from the SPI bus by sending dummy data dummyData
- parameter description:
- input parameters:
- base: The base address of the SPI module
- endianness: Specifies the endianness of the received data. You can use one of two values:
- sPI _ LITTLE _ ENDIAN-little end
- sPI _ BIG _ ENDIAN-Big Ends
- dummyData: Dummy data, which is sent to trigger an SPI transaction to receive actual data from the SPI bus
- txDelay: Serial clock cycle delay after completion of each word
- return parameters:
- sPI _ readData NonBlocking: 32-bit data-word received
12.SPI_pollingNonFIFOTransaction(uint32_t base, uint16_t charLength, uint16_t data)
- function description: This function is used to start the SPI transaction of the specified character
- parameter description:
- input parameters:
- base: Specifies the SPI module base address
- charLength: Specifies the SPI character length of the SPI transaction
- data: specifies the data to be transferred
- return parameters:
0
13.SPI_pollingFIFOTransaction(uint32_t base, uint16_t charLength, uint16_t *pTxBuffer,uint16_t *pRxBuffer, uint16_t numOfWords, uint16_t txDelay)
- function description: Used to start an SPI transaction with a specified character length and N data words
- parameter description:
- input parameters:
- base Specifies: the SPI module base address
- charLength: Specifies the SPI character length of the SPI transaction
- pTxBuffer: Specifies a pointer to the transfer buffer
- pRxBuffer: Specifies a pointer to the receive buffer
- numOfWords: Specify the amount of data to send/receive
- txDelay: Serial clock cycle delay after completion of each word
- return parameter:/
14.SPI_isBaseValid(uint32_t base)
- function description: Check SPI base address
- parameter description:
- input parameters:
- base Specifies: the SPI module base address
- return parameters:
15.SPI_enableModule(uint32_t base)
- function description: Enables the serial peripheral interface
- parameter description:
- input parameters:
- base Specifies: the SPI module base address
- return parameters:
16.SPI_disableModule(uint32_t base)
- function description: Disables the serial peripheral interface
- parameter description:
- input parameters:
- base Specifies: the SPI module base address
- return parameters:
17.SPI_setcharLength(uint32_t base, uint16_t charLength)
- function description: Set the character length of SPI transaction
- parameter description:
- input parameters:
- base Specifies: the SPI module base address
- charLength specifies the character length of the SPI transaction
- return parameters:
18.SPI_setFIFOInterruptLevel(uint32_t base, SPI_TxFIFOLevel txLevel, SPI_RxFIFOLevel rxLevel)
- function description: Set the FIFO level for interrupt generation
- parameter description:
- input parameters:
- base is the base address of the SPI port.
- txLevel is the transmit FIFO interrupt level, specified as:
- SPI_FIFO_TX0
- SPI_FIFO _TX1
- SPI _FIFO_TX2
- SPI_FIFO_TX16
- rxLevel is the receive FIFO interrupt level, specified as:
- SPI_FIFO_RX0
- SPI_FIFO _RX1
- SPI _FIFO_RX2
- SPI_FIFO_RX16
- return parameters:
19.SPI_getFIFOInterruptLevel(uint32_t base, SPI_TxFIFOLevel *txLevel, SPI_RxFIFOLevel *rxLevel)
- function description: Gets the FIFO level that generates the interrupt
- parameter description:
- input parameters:
- base is the base address of the SPI port.
- txLevel is the transmit FIFO interrupt level, specified as:
- SPI_FIFO_TX0
- SPI_FIFO _TX1
- SPI _FIFO_TX2
- SPI_FIFO_TX16
- rxLevel is the receive FIFO interrupt level, specified as:
- SPI_FIFO_RX0
- SPI_FIFO _RX1
- SPI _FIFO_RX2
- SPI_FIFO_RX16
- return parameters:
20.SPI_getTxFIFOStatus(uint32_t base)
- function description: Get the transmission FIFO status
- parameter description:
- input parameters:
- base is the base address of the SPI port.
- return parameters:
21.SPI_getRxFIFOStatus(uint32_t base)
- function description: Get the receiving FIFO status
- parameter description:
- input parameters:
- base is the base address of the SPI port.
- return parameters:
22.SPI_isBusy(uint32_t base)
- function description: Determines if the SPI transmitter is busy.
- parameter description:
- input parameters:
- base is the base address of the SPI port.
- return parameters:
23.SPI_enableDMA(uint32_t base, bool tx, bool rx)
- function description: Enables the DMA function of the specified SPI module
- parameter description:
- input parameters:
- base: The base address of the SPI module
- tx: a Boolean value indicating whether the transmit (Tx) DMA feature is enabled
- rx: a Boolean value indicating whether the Receive (Rx) DMA feature is enabled
- return parameters:
24.SPI_disableDMA(uint32_t base, bool tx, bool rx)
- function description: Disables the DMA function of the specified SPI module
- parameter description:
- input parameters:
- base: The base address of the SPI module
- tx: a Boolean value indicating whether the transmit (Tx) DMA feature is enabled
- rx: a Boolean value indicating whether the Receive (Rx) DMA feature is enabled
- return parameters:
25.SPI_writeDataNonBlocking(uint32_t base, uint32_t data)
- function description: Put the data element into the SPI transmission buffer.
- parameter description:
- input parameters:
- base: The base address of the SPI module
- data: Left-justified data transmitted via SPI
- return parameters:
26.SPI_readDataNonBlocking(uint32_t base)
- function description: Get data elements from SPI receive buffer
- parameter description:
- input parameter: base: base address of SPI module
- return parameters:
27.SPI_writeDataBlockingFIFO(uint32_t base, uint32_t data)
- function description: Waits for space in the FIFO and then places data in the transmit buffer
- parameter description:
- input parameters:
- base: The base address of the SPI module
- data: Left-justified data transmitted via SPI
- return parameters:
28.SPI_readDataBlockingFIFO(uint32_t base)
- function description: Wait for data in FIFO and then read from receive buffer
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
29.SPI_writeDataBlockingNonFIFO(uint32_t base, uint32_t data)
- function description: Wait for the transmission buffer to be emptied, and then write data to it
- parameter description:
- input parameters:
- base: The base address of the SPI module
- data: Left-justified data transmitted via SPI
- return parameters:
30.SPI_readDataBlockingNonFIFO(uint32_t base)
- function description: Wait for data to be received, and then read data from the buffer
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
31.SPI_enableTriWire(uint32_t base)
- function description: Enable SPI 3-wire mode
- base: The base address of the SPI module
- parameter description:
- input parameters:
- return parameters:
32.SPI_disableTriWire(uint32_t base)
- function description: Turn off SPI 3-wire mode
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
33.SPI_enableLoopback(uint32_t base)
- function description: Enable SPI loopback mode
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
34.SPI_disableLoopback(uint32_t base)
- function description: Disable the SPI loopback mode
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
35.SPI_setPTESignalPolarity(uint32_t base, SPI_PTEPolarity polarity)
- function description: Sets the polarity of the peripheral device select (SPIPTE) signal
- parameter description:
- input parameters:
- param-base is the base address of the SPI port
- polarity is the polarity of the SPIPTE signal
- return parameters:
36.SPI_enableHighSpeedMode(uint32_t base)
- function description: Enable SPI high-speed mode
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
37.SPI_disableHighSpeedMode(uint32_t base)
- function description: Turn off SPI high-speed mode
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
38.SPI_setTxFifoTransmitDelay(uint32_t base, uint16_t delay)
- function description: Configure FIFO transmission delay
- parameter description:
- input parameters:
- base: is the base address of the SPI port
- delay: Tx FIFO delay is configured by cycle
- return parameters:
39.SPI_setEmulationMode(uint32_t base, SPI_EmulationMode mode)
- function description: Set SPI emulation mode
- parameter description:
- input parameters:
- base: is the base address of the SPI port
- mode is the emulation mode, and the parameter can be one of the following:
- SPI_EMULATION_STOP_MIDWAY
- SPI_EMULATION_STOP_AFTER_TRANSMIT
- SPI_EMULATION_FREE_RUN-SPI
- return parameters:
40.SPI_enableTalk(uint32_t base)
- function description: Enable trasnmit
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
41.SPI_disableTalk(uint32_t base)
- function description: Close trasnmit
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters:
42.SPI_reset(uint32_t base)
- function description: Reset SPI
- parameter description:
- input parameters:
- base: The base address of the SPI module
- return parameters: