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.
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
Select character size
Which clock source is used
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.
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.
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.
/**
* 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);
}
SPI slave peripheral and its related I/O lines and clocks