SPI Master Synchronous Driver

The Serial Peripheral Interface (SPI) Master synchronous driver provides a communication interface to read/write the data from/to the slave device.

Refer SPI Drivers for more detailed calendar 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 master

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

Summary of Configuration Options

Below is a list of the main SPI master parameters that can be configured in START. Many of these parameters are used by the spi_m_sync_init function when initializing the driver and underlying hardware. Most of the initial values can be overridden and changed runtime by calling the appropriate API functions.
  • Select character size

  • Set SPI baudrate

  • Which clock source is used

Driver Implementation Description

After SPI hardware initialization, the spi_m_sync_get_io_descriptor function is needed to register an I/O descriptor. Then enable the SPI hardware. At the end, control the slave select (SS) pin, and start the read/write operation.

Limitations

The slave select (SS) is not automatically inserted during read/write/transfer, user must use I/O to control the devices' SS.

Example of Usage

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

The example enables the SPI master, and finally starts a writing operation to the 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_m_sync_get_io_descriptor(&SPI_0, &io);    spi_m_sync_enable(&SPI_0);    /* Control the slave select (SS) pin */    //gpio_set_pin_level(SPI_0_SS, false);    io_write(io, example_SPI_0, 12);    /* Control the slave select (SS) pin */    //gpio_set_pin_level(SPI_0_SS, true);}

Dependencies

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