SPIS driver

group nrfx_spis

Serial Peripheral Interface Slave with EasyDMA (SPIS) driver.

Defines

NRFX_SPIS_INSTANCE(id)

Macro for creating an instance of the SPI slave driver.

NRFX_SPIS_PIN_NOT_USED

This value can be provided instead of a pin number for the signals MOSI and MISO to specify that the given signal is not used and therefore does not need to be connected to a pin.

NRFX_SPIS_DEFAULT_CONFIG(_pin_sck, _pin_mosi, _pin_miso, _pin_csn)

SPIS driver default configuration.

This configuration sets up SPIS with the following options:

  • mode: 0 (SCK active high, sample on leading edge of the clock signal)

  • MSB shifted out first

  • CSN pull-up disabled

  • MISO pin drive set to standard ‘0’ and standard ‘1’

  • default character set to 0xFF

  • over-read character set to 0xFE

Parameters
  • _pin_sck[in] SCK pin.

  • _pin_mosi[in] MOSI pin.

  • _pin_miso[in] MISO pin.

  • _pin_csn[in] CSN pin.

Typedefs

typedef void (*nrfx_spis_event_handler_t)(nrfx_spis_evt_t const *p_event, void *p_context)

SPI slave driver event handler type.

Param p_event

[in] Pointer to the event structure. The structure is allocated on the stack so it is valid only until the event handler returns.

Param p_context

[in] Context set on initialization.

Enums

enum nrfx_spis_evt_type_t

SPI slave driver event types.

Values:

enumerator NRFX_SPIS_BUFFERS_SET_DONE

Memory buffer set event. Memory buffers have been set successfully to the SPI slave device, and SPI transaction can be done.

enumerator NRFX_SPIS_XFER_DONE

SPI transaction event. SPI transaction has been completed.

enumerator NRFX_SPIS_EVT_TYPE_MAX

Enumeration upper bound.

Functions

nrfx_err_t nrfx_spis_init(nrfx_spis_t const *p_instance, nrfx_spis_config_t const *p_config, nrfx_spis_event_handler_t event_handler, void *p_context)

Function for initializing the SPI slave driver instance.

Note

When the nRF52 Anomaly 109 workaround for SPIS is enabled, this function initializes the GPIOTE driver as well, and uses one of GPIOTE channels to detect falling edges on CSN pin.

Parameters
  • p_instance[in] Pointer to the driver instance structure.

  • p_config[in] Pointer to the structure with the initial configuration.

  • event_handler[in] Function to be called by the SPI slave driver upon event. Must not be NULL.

  • p_context[in] Context passed to the event handler.

Return values
  • NRFX_SUCCESS – The initialization was successful.

  • NRFX_ERROR_INVALID_STATE – The instance is already initialized.

  • NRFX_ERROR_INVALID_PARAM – Invalid parameter is supplied.

  • NRFX_ERROR_BUSY – Some other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.

  • NRFX_ERROR_INTERNAL – GPIOTE channel for detecting falling edges on CSN pin cannot be initialized. Possible only when using nRF52 Anomaly 109 workaround.

void nrfx_spis_uninit(nrfx_spis_t const *p_instance)

Function for uninitializing the SPI slave driver instance.

Parameters
  • p_instance[in] Pointer to the driver instance structure.

nrfx_err_t nrfx_spis_buffers_set(nrfx_spis_t const *p_instance, uint8_t const *p_tx_buffer, size_t tx_buffer_length, uint8_t *p_rx_buffer, size_t rx_buffer_length)

Function for preparing the SPI slave instance for a single SPI transaction.

This function prepares the SPI slave device to be ready for a single SPI transaction. It configures the SPI slave device to use the memory supplied with the function call in SPI transactions.

When either the memory buffer configuration or the SPI transaction has been completed, the event callback function will be called with the appropriate event nrfx_spis_evt_type_t. The callback function can be called before returning from this function, because it is called from the SPI slave interrupt context.

Note

This function can be called from the callback function context.

Note

Client applications must call this function after every NRFX_SPIS_XFER_DONE event if the SPI slave driver must be prepared for a possible new SPI transaction.

Note

Peripherals using EasyDMA (including SPIS) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code NRFX_ERROR_INVALID_ADDR.

Parameters
  • p_instance[in] Pointer to the driver instance structure.

  • p_tx_buffer[in] Pointer to the TX buffer. Can be NULL when the buffer length is zero.

  • p_rx_buffer[in] Pointer to the RX buffer. Can be NULL when the buffer length is zero.

  • tx_buffer_length[in] Length of the TX buffer in bytes.

  • rx_buffer_length[in] Length of the RX buffer in bytes.

Return values
  • NRFX_SUCCESS – The operation was successful.

  • NRFX_ERROR_INVALID_STATE – The operation failed because the SPI slave device is in an incorrect state.

  • NRFX_ERROR_INVALID_ADDR – The provided buffers are not placed in the Data RAM region.

  • NRFX_ERROR_INVALID_LENGTH – Provided lengths exceed the EasyDMA limits for the peripheral.

  • NRFX_ERROR_INTERNAL – The operation failed because of an internal error.

struct nrfx_spis_t
#include <nrfx_spis.h>

Data structure for the Serial Peripheral Interface Slave with EasyDMA (SPIS) driver instance.

Public Members

NRF_SPIS_Type *p_reg

Pointer to a structure with SPIS registers.

uint8_t drv_inst_idx

Index of the driver instance. For internal use only.

struct nrfx_spis_evt_t
#include <nrfx_spis.h>

SPI slave driver event structure.

Public Members

nrfx_spis_evt_type_t evt_type

Type of the event.

size_t rx_amount

Number of bytes received in the last transaction. This parameter is only valid for NRFX_SPIS_XFER_DONE events.

size_t tx_amount

Number of bytes transmitted in the last transaction. This parameter is only valid for NRFX_SPIS_XFER_DONE events.

struct nrfx_spis_config_t
#include <nrfx_spis.h>

SPI peripheral device configuration data.

Public Members

uint32_t miso_pin

SPI MISO pin (optional).

Set NRFX_SPIS_PIN_NOT_USED if this signal is not needed.

uint32_t mosi_pin

SPI MOSI pin (optional).

Set NRFX_SPIS_PIN_NOT_USED if this signal is not needed.

uint32_t sck_pin

SPI SCK pin.

uint32_t csn_pin

SPI CSN pin.

nrf_spis_mode_t mode

SPI mode.

nrf_spis_bit_order_t bit_order

SPI transaction bit order.

nrf_gpio_pin_pull_t csn_pullup

CSN pin pull-up configuration.

nrf_gpio_pin_drive_t miso_drive

MISO pin drive configuration.

uint8_t def

Character clocked out in case of an ignored transaction.

uint8_t orc

Character clocked out after an over-read of the transmit buffer.

uint8_t irq_priority

Interrupt priority.

bool skip_gpio_cfg

Skip GPIO configuration of pins.

When set to true, the driver does not modify any GPIO parameters of the used pins. Those parameters are supposed to be configured externally before the driver is initialized.

bool skip_psel_cfg

Skip pin selection configuration.

When set to true, the driver does not modify pin select registers in the peripheral. Those registers are supposed to be set up externally before the driver is initialized.

Note

When both GPIO configuration and pin selection are to be skipped, the structure fields that specify pins can be omitted, as they are ignored anyway.