Software controlled SPI slave driver

nRF5 SDK v10.0.0

nRF51 SDK v10.0.0

Driver for the software controlled SPI slave. 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_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 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_DEFAULT_DEF 0xFF
#define NRF_DRV_SPIS_DEFAULT_ORC 0xFF
#define SPIS0_IRQ SPI0_TWI0_IRQn
#define SPIS0_IRQ_HANDLER SPI0_TWI0_IRQHandler
#define SPIS1_IRQ SPI1_TWI1_IRQn
#define SPIS1_IRQ_HANDLER SPI1_TWI1_IRQHandler
#define NRF_DRV_SPIS_INSTANCE (id)
Macro for creating an SPI slave driver instance. More...
#define NRF_DRV_SPIS_DEFAULT_CONFIG (id)
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

Driver for the software controlled SPI slave.

Macro Definition Documentation

#define NRF_DRV_SPIS_DEFAULT_CONFIG ( id )
Value:
{ \
.sck_pin = CONCAT_3(SPIS, id , _CONFIG_SCK_PIN), \
.mosi_pin = CONCAT_3(SPIS, id , _CONFIG_MOSI_PIN), \
.miso_pin = CONCAT_3(SPIS, id , _CONFIG_MISO_PIN), \
.irq_priority = CONCAT_3(SPIS, id , _CONFIG_IRQ_PRIORITY), \
}

SPI slave instance default configuration.

#define NRF_DRV_SPIS_DEFAULT_CSN_PULLUP NRF_GPIO_PIN_NOPULL

Default pull-up configuration of the SPI CS.

#define NRF_DRV_SPIS_DEFAULT_DEF   0xFF

Default DEF character.

#define NRF_DRV_SPIS_DEFAULT_MISO_DRIVE NRF_GPIO_PIN_S0S1

Default drive configuration of the SPI MISO.

#define NRF_DRV_SPIS_DEFAULT_ORC   0xFF

Default ORC character.

#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 SPIS instance.
[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 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.
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 instance structure.

Please send us your feedback about the documentation! For technical questions, visit the Nordic Developer Zone .