MT7687 API Reference  LinkIt SDK v4
SPI_SLAVE

This section introduces the SPI Slave APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enums, structures and functions. More...

Overview

This section introduces the SPI Slave APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enums, structures and functions.

Terms and acronyms

Terms Details
DMA Direct Memory Access. DMA is a feature of computer systems that allows certain hardware subsystems to access main system memory independent from the central processing unit (CPU).
GPIO General Purpose Inputs-Outputs. For more details, please refer to GPIO.
IRQ Interrupt Request. For more information, please refer to IRQ.
MISO Master Input, Slave Output. Output from the SPI slave.
MOSI Master Output, Slave Input. Output from the SPI master.
NVIC Nested Vectored Interrupt Controller. NVIC is the interrupt controller of ARM Cortex-M series processors. For more details, please refer to ARM Cortex-M4 technical reference manual.
SCLK Serial Clock. Output from the SPI master.
SPI Serial Peripheral Interface. The Serial Peripheral Interface bus is a synchronous serial communication interface specification used for short distance communication. For more information, please refer to Serial Peripheral Interface Bus in Wikipedia.
SS Slave Select. Output from the SPI master, active low.

Supported features

Emerging sensor applications support SPI interface communication. An SPI slave interface is required to communicate with an SPI master interface. This controller is the SPI slave interface with five functional registers for communication.

Software architecture of the SPI slave

The architecture is similar to the interrupt mode architecture in HAL overview. See HAL Driver Model for interrupt mode architecture.

How to use this driver

Call hal_pinmux_set_function() to pinmux the GPIO pins to four SPI pins (SS, SCLK, MOSI, and MISO) based on the user's hardware platform design. Please note that user should choose the SPI pins for SPI slave, which can support 20MHz SPI clock, to get a better throughput. Then call hal_spi_slave_init() to apply basic settings for SPI slave hardware. After that call hal_spi_slave_register_callback() to register a user callback function. The steps are shown below:

Functions

hal_spi_slave_status_t hal_spi_slave_init (hal_spi_slave_port_t spi_port, hal_spi_slave_config_t *spi_configure)
 This function initializes the SPI slave and sets user defined common parameters such as clock polarity and clock phase, always setup internal configuration for 20MHz SPI clock for better throughput. More...
 
hal_spi_slave_status_t hal_spi_slave_register_callback (hal_spi_slave_port_t spi_port, hal_spi_slave_callback_t callback_function, void *user_data)
 This function registers user's callback in the SPI slave driver. More...
 

Modules

 Enum
 
 Struct
 
 Typedef
 

Function Documentation

hal_spi_slave_status_t hal_spi_slave_init ( hal_spi_slave_port_t  spi_port,
hal_spi_slave_config_t spi_configure 
)

This function initializes the SPI slave and sets user defined common parameters such as clock polarity and clock phase, always setup internal configuration for 20MHz SPI clock for better throughput.

Note that the SPI slave supports only MSB bit order and can't be config to LSB bit order.

Parameters
[in]spi_portis the SPI slave port number, the value is defined at hal_spi_slave_port_t.
[in]spi_configureis the SPI slave configure parameters. Details are described at hal_spi_slave_config_t.
Returns
HAL_SPI_SLAVE_STATUS_ERROR_PORT, if the SPI slave port is invalid.
HAL_SPI_SLAVE_STATUS_INVALID_PARAMETER, if an invalid parameter is given by user.
HAL_SPI_SLAVE_STATUS_OK, if this function returned successfully.
hal_spi_slave_status_t hal_spi_slave_register_callback ( hal_spi_slave_port_t  spi_port,
hal_spi_slave_callback_t  callback_function,
void *  user_data 
)

This function registers user's callback in the SPI slave driver.

This function may be called when using the SPI slave driver, the callback will be called in SPI interrupt service routine.

Parameters
[in]spi_portis the SPI slave port number, the value is defined at hal_spi_slave_port_t.
[in]callback_functionis the callback function given by user, which will be called at SPI slave interrupt service routine.
[in]user_datais a parameter given by user and will pass to user while the callback function is called.
Returns
HAL_SPI_SLAVE_STATUS_ERROR_PORT, if the SPI slave port is invalid.
HAL_SPI_SLAVE_STATUS_INVALID_PARAMETER, if an invalid parameter is given by user.
HAL_SPI_SLAVE_STATUS_OK, if this function returned successfully.