SPI Slave Synchronous Driver

The functions in the serial peripheral interface (SPI) Slave synchronous driver provides an interface to read/write the data from/to the master device.

When data is read or written through the I/O writing function, the driver keeps polling until the correct amount of data is achieved. Also, it's possible to perform a full-duplex read and write through transfer function, which process both read and write at the same time.

When SS detection is considered, a "break on SS detection" option can be enabled to make it possible to terminate the read/write/transfer on SS desertion.

Refer SPI Drivers for more detailed SPI basics.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Register I/O descriptor

  • Enable or disable SPI slave

  • Read/Write message to/from the master

  • Data transfer: transmission, reception, and full-duplex

Summary of Configuration Options

Below is a list of the main SPI slave parameters that can be configured in START. Many of these parameters are used by the spi_s_sync_init function when initializing the driver and underlying hardware. Most of the initial values can be overridden.
  • Select character size

  • Which clock source is used

Driver Implementation Description

After the SPI hardware initialization, the spi_s_sync_get_io_descriptor function is needed to register an I/O descriptor. Then enable SPI hardware and start the read/write operation.

Known Issues and Workarounds

When writing data through SPI slave, the time that the data appears on the data line depends on the SPI hardware and previous writing state, since there can be data in output FIFO filled by previous broken transmitting. The number of such dummy/broken characters is limited by the hardware. Whether these dummy/broken characters can be flushed is also limited by the hardware.

Example of Usage

The following shows a simple example of using the SPI slave. The SPI slave must have been initialized by spi_s_sync_init. This initialization will configure the operation of the SPI slave.

The example enables SPI slave, and finally starts a reading operation to the master.
/** * Example of using SPI_0 to write "Hello World" using the I/O abstraction. */static uint8_t example_SPI_0[12] = "Hello World!";void SPI_0_example(void){    struct io_descriptor *io;    spi_s_sync_get_io_descriptor(&SPI_0, &io);    spi_s_sync_enable(&SPI_0);    io_write(io, example_SPI_0, 12);}

Dependencies

  • SPI slave peripheral and its related I/O lines and clocks