The SPI slave driver includes two layers: the hardware access layer (HAL) and the driver layer (DRV).
The hardware access layer provides basic APIs for accessing the registers of the SPIS peripheral. See the API documentation for the SPIS HAL for details.
The driver layer provides APIs on a higher level than the HAL. See the API documentation for the SPIS driver - legacy layer for details.
Key features include:
Note that peripherals using EasyDMA can work only with buffers that are placed in the data RAM region. Under certain circumstances, compilers might choose to use a different region for data placement and, for example, place a constant buffer in the code FLASH. In such a case, the SPIS peripheral cannot be used to transfer data from the buffer.
To quickly get started, use the sample code from the SPI Slave Example.
The SPI slave driver can use multiple instances of SPIS. The instances of the peripherals that are to be assigned to the driver must be selected statically in sdk_config.h
, for example:
For enabled instances, you can use the macro that provides the default configuration - NRF_DRV_SPIS_DEFAULT_CONFIG. The settings for this macro are defined in sdk.config.h
, for example:
The macro sets pins to value NRF_DRV_SPIS_PIN_NOT_USED. Remember to refer to the nrf_drv_spis_config_t struct and set proper pins.
Call the NRF_DRV_SPIS_INSTANCE macro with the ID of the peripheral instance that you want to use to create a driver instance. For example, this code will create a driver instance that uses the SPIS1 peripheral:
Next, call nrf_drv_spis_init to initialize and configure the instance. See the nrf_drv_spis_config_t structure documentation for possible configuration options. To receive data, the SPI buffers must be set by calling nrf_drv_spis_buffers_set after initialization.
For example:
The callback handler function will be called after every successful buffer setup and every completed transfer. New buffers must be set by calling nrf_drv_spis_buffers_set after every finished transaction. Otherwise, the transaction is ignored, and the default character is clocked out.
When the SPI slave driver instance is no longer needed or its configuration must be changed, call nrf_drv_spis_uninit.