Quickstart

Informative

The shortest path to a working SPI controller: initialize and transfer a buffer to a device. Binding rules are in Spi — Requirements; signatures in API Reference.

Bring the driver up

Spi_Init(NULL_PTR);          /* driver: UNINIT -> INIT; every channel -> IDLE */

Transfer a buffer (controller mode)

A transaction is a buffer set — one or more chunks transferred within a chip-select sequence. Here a single TX chunk is sent while the received bytes are discarded (null RX pointer):

static uint8 txData[2] = { 0x10u, 0x2Au };

static Spi_BufferType txChunks[1] = { { txData, 2u } };   /* { bufferDataPtr, length } */
static Spi_BufferSetType txSet = { txChunks, 1u };        /* { bufferPtr, numOfBuffer } */

Std_ReturnType r = Spi_StartTransaction(
    0u,               /* channelId (configured as a controller) */
    0u,               /* csId (chip select in the channel) */
    &txSet,
    NULL_PTR);        /* no RX buffer set -> discard received data */

/* keep txData / txSet valid until Spi_Callout_OnTransactionEnd fires */

Handle completion

void Spi_Callout_OnTransactionEnd(uint8 channelId, uint8 csId, uint16 length)
{
    /* the transaction finished; `length` elements were transferred */
}

That is a complete controller transfer: Spi_Interrupt (or Spi_PollFunction) drives the buffer set and fires Spi_Callout_OnTransactionEnd. To also receive, supply an RX buffer set (see Controller transactions). To act as a target, see Target transactions.