SPI slave driver

nRF5 SDK v12.2.0

Multi-instance SPI slave driver. More...

Data Structures

struct nrf_drv_spis_event_t
Structure containing the event context from the SPI slave driver. More...
struct nrf_drv_spis_t
SPI slave driver instance data structure. More...
struct nrf_drv_spis_config_t
SPI peripheral device configuration data. More...

Macros

#define NRF_DRV_SPIS_DEFAULT_CSN_PULLUP NRF_GPIO_PIN_NOPULL
#define NRF_DRV_SPIS_DEFAULT_MISO_DRIVE NRF_GPIO_PIN_S0S1
#define NRF_DRV_SPIS_PIN_NOT_USED 0xFF
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.
#define SPIS0_INSTANCE_INDEX 0
#define SPIS1_INSTANCE_INDEX SPIS0_INSTANCE_INDEX+ SPIS0_ENABLED
#define SPIS2_INSTANCE_INDEX SPIS1_INSTANCE_INDEX+ SPIS1_ENABLED
#define NRF_DRV_SPIS_INSTANCE (id)
Macro for creating an SPI slave driver instance. More...
#define NRF_DRV_SPIS_DEFAULT_CONFIG
SPI slave instance default configuration. More...

Typedefs

typedef void(* nrf_drv_spis_event_handler_t )( nrf_drv_spis_event_t event)
SPI slave event callback function type. More...

Enumerations

enum nrf_drv_spis_endian_t {
NRF_DRV_SPIS_BIT_ORDER_LSB_FIRST = NRF_SPIS_BIT_ORDER_LSB_FIRST,
NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST = NRF_SPIS_BIT_ORDER_MSB_FIRST
}
SPIS transaction bit order definitions. More...
enum nrf_drv_spis_mode_t {
NRF_DRV_SPIS_MODE_0 = NRF_SPIS_MODE_0,
NRF_DRV_SPIS_MODE_1 = NRF_SPIS_MODE_1,
NRF_DRV_SPIS_MODE_2 = NRF_SPIS_MODE_2,
NRF_DRV_SPIS_MODE_3 = NRF_SPIS_MODE_3
}
SPIS mode definitions for clock polarity and phase. More...
enum nrf_drv_spis_event_type_t {
NRF_DRV_SPIS_BUFFERS_SET_DONE ,
NRF_DRV_SPIS_XFER_DONE ,
NRF_DRV_SPIS_EVT_TYPE_MAX
}
Event callback function event definitions. More...

Functions

ret_code_t nrf_drv_spis_init ( nrf_drv_spis_t const *const p_instance, nrf_drv_spis_config_t const *p_config, nrf_drv_spis_event_handler_t event_handler)
Function for initializing the SPI slave driver instance. More...
void nrf_drv_spis_uninit ( nrf_drv_spis_t const *const p_instance)
Function for uninitializing the SPI slave driver instance. More...
ret_code_t nrf_drv_spis_buffers_set ( nrf_drv_spis_t const *const p_instance, const uint8_t *p_tx_buffer, uint8_t tx_buffer_length, uint8_t *p_rx_buffer, uint8_t rx_buffer_length)
Function for preparing the SPI slave instance for a single SPI transaction. More...

Detailed Description

Multi-instance SPI slave driver.

Macro Definition Documentation

#define NRF_DRV_SPIS_DEFAULT_CONFIG
#define NRF_DRV_SPIS_DEFAULT_CSN_PULLUP NRF_GPIO_PIN_NOPULL

Default pull-up configuration of the SPI CS.

#define NRF_DRV_SPIS_DEFAULT_MISO_DRIVE NRF_GPIO_PIN_S0S1

Default drive configuration of the SPI MISO.

#define NRF_DRV_SPIS_INSTANCE ( id )
Value:
{ \
.p_reg = CONCAT_2 (NRF_SPIS, id ), \
.irq = CONCAT_3(SPIS, id , _IRQ), \
.instance_id = CONCAT_3(SPIS, id , _INSTANCE_INDEX), \
}

Macro for creating an SPI slave driver instance.

Typedef Documentation

typedef void(* nrf_drv_spis_event_handler_t)( nrf_drv_spis_event_t event)

SPI slave event callback function type.

Parameters
[in] event SPI slave driver event.

Enumeration Type Documentation

SPIS transaction bit order definitions.

Enumerator
NRF_DRV_SPIS_BIT_ORDER_LSB_FIRST

Least significant bit shifted out first.

NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST

Most significant bit shifted out first.

Event callback function event definitions.

Enumerator
NRF_DRV_SPIS_BUFFERS_SET_DONE

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

NRF_DRV_SPIS_XFER_DONE

SPI transaction event. SPI transaction has been completed.

NRF_DRV_SPIS_EVT_TYPE_MAX

Enumeration upper bound.

SPIS mode definitions for clock polarity and phase.

Enumerator
NRF_DRV_SPIS_MODE_0

(CPOL = 0, CPHA = 0).

NRF_DRV_SPIS_MODE_1

(CPOL = 0, CPHA = 1).

NRF_DRV_SPIS_MODE_2

(CPOL = 1, CPHA = 0).

NRF_DRV_SPIS_MODE_3

(CPOL = 1, CPHA = 1).

Function Documentation

ret_code_t nrf_drv_spis_buffers_set ( nrf_drv_spis_t const *const p_instance ,
const uint8_t * p_tx_buffer ,
uint8_t tx_buffer_length ,
uint8_t * p_rx_buffer ,
uint8_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 nrf_drv_spis_event_type_t . Note that 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.
Client applications must call this function after every NRF_DRV_SPIS_XFER_DONE event if the SPI slave driver should be prepared for a possible new SPI transaction.
Peripherals that are using EasyDMA (for example, SPIS) require the transfer buffers to be placed in the Data RAM region. Otherwise, this function will fail with the error code NRF_ERROR_INVALID_ADDR.
Parameters
[in] p_instance Pointer to the driver instance structure.
[in] p_tx_buffer Pointer to the TX buffer.
[in] p_rx_buffer Pointer to the RX buffer.
[in] tx_buffer_length Length of the TX buffer in bytes.
[in] rx_buffer_length Length of the RX buffer in bytes.
Return values
NRF_SUCCESS If the operation was successful.
NRF_ERROR_NULL If the operation failed because a NULL pointer was supplied.
NRF_ERROR_INVALID_STATE If the operation failed because the SPI slave device is in an incorrect state.
NRF_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data RAM region.
NRF_ERROR_INTERNAL If the operation failed because of an internal error.
ret_code_t nrf_drv_spis_init ( nrf_drv_spis_t const *const p_instance ,
nrf_drv_spis_config_t const * p_config ,
nrf_drv_spis_event_handler_t event_handler
)

Function for initializing the SPI slave driver instance.

Parameters
[in] p_instance Pointer to the driver instance structure.
[in] p_config Pointer to the structure with the initial configuration. If NULL, the default configuration will be used.
[in] event_handler Function to be called by the SPI slave driver upon event.
Return values
NRF_SUCCESS If the initialization was successful.
NRF_ERROR_INVALID_PARAM If an invalid parameter is supplied.
NRF_ERROR_BUSY If some other peripheral with the same instance ID is already in use. This is possible only if PERIPHERAL_RESOURCE_SHARING_ENABLED is set to a value other than zero.
void nrf_drv_spis_uninit ( nrf_drv_spis_t const *const p_instance )

Function for uninitializing the SPI slave driver instance.

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