Astra MCU SDK Peripheral Driver Library
 
Loading...
Searching...
No Matches

High Level functions for SPI. More...

Functions

spi_status_en spi_transfer_blocking (spi_instance_en id, spi_xfer_config_t *xfer)
 
spi_status_en spi_transfer_non_blocking (spi_instance_en id, spi_xfer_config_t *xfer)
 
spi_status_en spi_transfer_abort (spi_instance_en id)
 
spi_transfer_status_en spi_transfer_status (spi_instance_en id)
 
uint32_t spi_transfer_elements_transferred (spi_instance_en id)
 

Detailed Description

High Level functions for SPI.

Function Documentation

◆ spi_transfer_blocking()

spi_status_en spi_transfer_blocking ( spi_instance_en id,
spi_xfer_config_t * xfer )

Transfers specified number of data elements. Does not return until all data elements are transferred or timeout. This function blocks all other code from running until it completes. If tx_buff is NULL then tx_dummy is sent for each data element. If rx_buff is NULL all received data is discarded.

If receive is not important pass a NULL pointer for rx_buff If TX is not required pass a NULL pointer for tx_buff, and set tx_dummy. Setting both tx_buff and rx_buff NULL is an invalid use case.

When this function exits both the RX and TX FIFO shall be empty and all level sensitive statuses and interrupts cleared.

Note both the tx_buff and rx_buff must have equal to or greater data elements than the specified xfer_size.

Parameters
idSPI Instance ID.
xferspi_xfer_config_t
Returns
spi_status_en Status code indicating success or the reason for failure.

◆ spi_transfer_non_blocking()

spi_status_en spi_transfer_non_blocking ( spi_instance_en id,
spi_xfer_config_t * xfer )

Initiates a non-blocking SPI transfer in full-duplex or half-duplex mode.

This function sets up the hardware SPI configuration, preloads available data into the TX FIFO (if applicable), and enables relevant interrupts. Once the initial setup is complete, the function returns immediately. All remaining data transmission and reception are managed by the interrupt handler spi_transfer_non_blocking_interrupt.

If transmit data (tx_buff) is provided, data is loaded into the TX FIFO; otherwise, the tx_dummy value is used. If receive data (rx_buff) is provided, the ISR copies received words from the RX FIFO; otherwise, received data is discarded.

The caller must ensure that tx_buff and rx_buff (if used) remain valid and unmodified for the duration of the transfer. The completion callback specified in the spi_xfer_config_t structure is invoked from the interrupt context when the transfer ends.

Parameters
idSPI Instance ID.
xferPointer to a spi_xfer_config_t structure containing transfer details such as buffers, transfer size, dummy data, and completion callback.
Returns
spi_status_en Status code indicating success or the reason for failure.
Note
  • Do not modify or free tx_buff or rx_buff during the transfer.
  • Both tx_buff and rx_buff must have space for at least xfer_size elements.
  • This function does not support the SPI_EEPROM_READ transfer mode.
  • If there is more data to be transmitted after the initial preload, it will be handled by the driver interrupt logic.

◆ spi_transfer_abort()

spi_status_en spi_transfer_abort ( spi_instance_en id)

Stop current SPI Transfer, clears TX and RX buffers, disables SPI interrupts. Disables SPI block.

Note this could stop a data transfer in the middle of a data element.

Parameters
idSPI Instance ID.
Returns
spi_status_en Status code indicating success or the reason for failure.

◆ spi_transfer_status()

spi_transfer_status_en spi_transfer_status ( spi_instance_en id)

Returns current transfer status, complete and error status are cleared when reading the status.

Parameters
idSPI Instance ID.
Returns
spi_transfer_status_en

◆ spi_transfer_elements_transferred()

uint32_t spi_transfer_elements_transferred ( spi_instance_en id)

Returns how many elements have been transferred since last call to transfer_non_blocking.

Parameters
idSPI Instance ID.
Returns
Number of elements transferred.