High-Level

group group_scb_spi_high_level_functions

Functions

cy_en_scb_spi_status_t Cy_SCB_SPI_Transfer(CySCB_Type *base, void *txBuffer, void *rxBuffer, uint32_t size, cy_stc_scb_spi_context_t *context)

This function starts an SPI transfer operation.

It configures transmit and receive buffers for an SPI transfer. If the data that will be received is not important, pass NULL as rxBuffer. If the data that will be transmitted is not important, pass NULL as txBuffer and then the CY_SCB_SPI_DEFAULT_TX is sent out as each data element. Note that passing NULL as rxBuffer and txBuffer are considered invalid cases.

After the function configures TX and RX interrupt sources, it returns and Cy_SCB_SPI_Interrupt manages further data transfer.

  • In the master mode, the transfer operation starts after calling this function

  • In the slave mode, the transfer registers and will start when the master request arrives.

When the transfer operation is completed (requested number of data elements sent and received), the CY_SCB_SPI_TRANSFER_ACTIVE status is cleared and the CY_SCB_SPI_TRANSFER_CMPLT_EVENT event is generated.

note

  • The buffers must not be modified and must stay allocated until the end of the transfer.

  • This function overrides all RX and TX FIFO interrupt sources and changes the RX and TX FIFO level.

Return

cy_en_scb_spi_status_t

Parameters
  • base: The pointer to the SPI SCB instance.

  • txBuffer: The pointer of the buffer with data to transmit. The element size is defined by the data type that depends on the configured TX data width.

  • rxBuffer: The pointer to the buffer to store received data. The element size is defined by the data type that depends on the configured RX data width.

  • size: The number of data elements to transmit and receive.

  • context: The pointer to the context structure cy_stc_scb_spi_context_t allocated by the user. The structure is used during the SPI operation for internal configuration and data retention. The user must not modify anything in this structure.

void Cy_SCB_SPI_AbortTransfer(CySCB_Type *base, cy_stc_scb_spi_context_t *context)

Aborts the current SPI transfer.

It disables the TX and RX interrupt sources, clears the TX and RX FIFOs and the status.

note

If slave aborts transfer and the master is still transferring data, that data will be placed in the RX FIFO, and the TX underflow will be set. To drop data received into the RX FIFO, RX FIFO must be cleared when the transfer is complete. Otherwise, received data will be kept and copied to the buffer when Cy_SCB_SPI_Transfer is called.

Side Effects

The transmit FIFO clear operation also clears the shift register, so that the shifter can be cleared in the middle of a data element transfer, corrupting it. The data element corruption means that all bits that have not been transmitted are transmitted as “ones” on the bus.

Parameters
  • base: The pointer to the SPI SCB instance.

  • context: The pointer to the context structure cy_stc_scb_spi_context_t allocated by the user. The structure is used during the SPI operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_SPI_GetTransferStatus(CySCB_Type const *base, cy_stc_scb_spi_context_t const *context)

Returns the status of the transfer operation started by Cy_SCB_SPI_Transfer.

This status is a bit mask and the value returned may have a multiple-bit set.

note

The status is cleared by calling Cy_SCB_SPI_Transfer or Cy_SCB_SPI_AbortTransfer.

Return

SPI Transfer Status.

Parameters
  • base: The pointer to the SPI SCB instance.

  • context: The pointer to the context structure cy_stc_scb_spi_context_t allocated by the user. The structure is used during the SPI operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_SPI_GetNumTransfered(CySCB_Type const *base, cy_stc_scb_spi_context_t const *context)

Returns the number of data elements transferred since the last call to Cy_SCB_SPI_Transfer.

Return

The number of data elements transferred.

Parameters
  • base: The pointer to the SPI SCB instance.

  • context: The pointer to the context structure cy_stc_scb_spi_context_t allocated by the user. The structure is used during the SPI operation for internal configuration and data retention. The user must not modify anything in this structure.