SPI Interface
SPI Platform interface
SPI Overview
The Serial Peripheral Interface (SPI) is a widely-used synchronous serial communication protocol that facilitates high-speed data exchange between a master device and one or more slave devices. It is commonly employed in embedded systems to connect microcontrollers, sensors, displays, memory devices, and other peripherals.
An SPI interface operates in a master-slave architecture, where the master controls the communication and provides the clock signal. The protocol is simple, efficient, and highly configurable, making it ideal for applications requiring fast and reliable data transfer.
Supported Communication Modes
The following modes of spi communication are supported:
Blocking - Here the read/write register function waits(blocked) till the operation is performed or time out
Non-Blocking - The read/write register function returns immediately and the registered callback is invoked after the completion of operation or time out
SPI Role Operation
The role operation for SPI determines whether a device operates as the Master or Slave in the SPI communication setup. The role defines how the device behaves in terms of generating the clock signal and controlling data flow during communication.
Further all the transfer counts will be in bits(rather than bytes) as there are many devices that will need it. Each SPI port+ChipSel will be created as a separate handle each.
Application Interface
Users can directly call the API’s though most of them will be called by device drivers.
The below table captures the functions that are to be called from the application layer.
Function |
Description |
|---|---|
rs_spi_open |
To open the SPI interface. |
rs_spi_set_config |
To configure the SPI interface. |
rs_spi_master_transfer |
To performs transfers over SPI master mode. |
rs_spi_master_write_reg8 |
To transfer given number of bits |
rs_spi_master_read_reg8 |
To receive given number of bits |
rs_spi_master_set_chip_select |
To sets the chip select signal as given |
rs_spi_register_callback |
To registers the given callback function for completion of SPI transfer operation |
rs_spi_close |
To close the SPI interface. |
Error Code
Every API’s for the SPI returns some success or failure values. Please refer below section,
Implementation Guide
This section explains how to implement the SPI interface using the RAPIDSEA stack, the steps to be followed are
Configure the preferred method of RX or TX communication(Blocking / Non-Blocking)
Configure the SPI interface(port, chip select control, direction, mode, bit rate, mode, role, datasize).
Then call the open call of the SPI interface.
Register the callback function.
Perform the read and write register functions as required and handle the error codes.
Close the SPI interface.
Documentation from the relevant header as follows:
Warning
doxygenfile: Cannot find file “rs_spi.h