PSoC 4 Peripheral Driver Library - Alpha

General Description

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. More...
 
void Cy_SCB_SPI_AbortTransfer (CySCB_Type *base, cy_stc_scb_spi_context_t *context)
 Aborts the current SPI transfer. More...
 
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. More...
 
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. More...
 

Function Documentation

◆ Cy_SCB_SPI_Transfer()

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.

Parameters
baseThe pointer to the SPI SCB instance.
txBufferThe 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.
rxBufferThe 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.
sizeThe number of data elements to transmit and receive.
contextThe 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.
Returns
cy_en_scb_spi_status_t
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.

◆ Cy_SCB_SPI_AbortTransfer()

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.

Parameters
baseThe pointer to the SPI SCB instance.
contextThe 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.
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.

◆ Cy_SCB_SPI_GetTransferStatus()

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.

Parameters
baseThe pointer to the SPI SCB instance.
contextThe 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.
Returns
SPI Transfer Status.
Note
The status is cleared by calling Cy_SCB_SPI_Transfer or Cy_SCB_SPI_AbortTransfer.

◆ Cy_SCB_SPI_GetNumTransfered()

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.

Parameters
baseThe pointer to the SPI SCB instance.
contextThe 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.
Returns
The number of data elements transferred.