nRF5 SDK v17.1.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
SPIM driver

Serial Peripheral Interface Master with EasyDMA (SPIM) driver. More...

Modules

 SPIM peripheral driver configuration
 

Data Structures

struct  nrfx_spim_t
 Data structure of the Serial Peripheral Interface Master with EasyDMA (SPIM) driver instance. More...
 
struct  nrfx_spim_config_t
 Configuration structure of the SPIM driver instance. More...
 
struct  nrfx_spim_xfer_desc_t
 Single transfer descriptor structure. More...
 
struct  nrfx_spim_evt_t
 SPIM event description with transmission details. More...
 

Macros

#define NRFX_SPIM_INSTANCE(id)
 Macro for creating an instance of the SPIM driver. More...
 
#define NRFX_SPIM_PIN_NOT_USED   0xFF
 This value can be provided instead of a pin number for signals MOSI, MISO, and Slave Select to specify that the given signal is not used and therefore does not need to be connected to a pin.
 
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG
 Extended default configuration of the SPIM instance. More...
 
#define NRFX_SPIM_DEFAULT_CONFIG
 The default configuration of the SPIM master instance. More...
 
#define NRFX_SPIM_FLAG_TX_POSTINC   (1UL << 0)
 Flag indicating that TX buffer address will be incremented after transfer.
 
#define NRFX_SPIM_FLAG_RX_POSTINC   (1UL << 1)
 Flag indicating that RX buffer address will be incremented after transfer.
 
#define NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER   (1UL << 2)
 Flag indicating that the interrupt after each transfer will be suppressed, and the event handler will not be called.
 
#define NRFX_SPIM_FLAG_HOLD_XFER   (1UL << 3)
 Flag indicating that the transfer will be set up, but not started.
 
#define NRFX_SPIM_FLAG_REPEATED_XFER   (1UL << 4)
 Flag indicating that the transfer will be executed multiple times.
 
#define NRFX_SPIM_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len)
 Macro for setting up single transfer descriptor. More...
 
#define NRFX_SPIM_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length)   NRFX_SPIM_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
 Macro for setting the duplex TX RX transfer.
 
#define NRFX_SPIM_XFER_TX(p_buf, length)   NRFX_SPIM_SINGLE_XFER(p_buf, length, NULL, 0)
 Macro for setting the TX transfer.
 
#define NRFX_SPIM_XFER_RX(p_buf, length)   NRFX_SPIM_SINGLE_XFER(NULL, 0, p_buf, length)
 Macro for setting the RX transfer.
 

Typedefs

typedef void(* nrfx_spim_evt_handler_t )(nrfx_spim_evt_t const *p_event, void *p_context)
 SPIM driver event handler type.
 

Enumerations

enum  nrfx_spim_evt_type_t { NRFX_SPIM_EVENT_DONE }
 SPIM master driver event types, passed to the handler routine provided during initialization. More...
 

Functions

nrfx_err_t nrfx_spim_init (nrfx_spim_t const *const p_instance, nrfx_spim_config_t const *p_config, nrfx_spim_evt_handler_t handler, void *p_context)
 Function for initializing the SPIM driver instance. More...
 
void nrfx_spim_uninit (nrfx_spim_t const *const p_instance)
 Function for uninitializing the SPIM driver instance. More...
 
nrfx_err_t nrfx_spim_xfer (nrfx_spim_t const *const p_instance, nrfx_spim_xfer_desc_t const *p_xfer_desc, uint32_t flags)
 Function for starting the SPIM data transfer. More...
 
nrfx_err_t nrfx_spim_xfer_dcx (nrfx_spim_t const *const p_instance, nrfx_spim_xfer_desc_t const *p_xfer_desc, uint32_t flags, uint8_t cmd_length)
 Function for starting the SPIM data transfer with DCX control. More...
 
uint32_t nrfx_spim_start_task_get (nrfx_spim_t const *p_instance)
 Function for returning the address of a SPIM start task. More...
 
uint32_t nrfx_spim_end_event_get (nrfx_spim_t const *p_instance)
 Function for returning the address of a END SPIM event. More...
 
void nrfx_spim_abort (nrfx_spim_t const *p_instance)
 Function for aborting ongoing transfer. More...
 

Detailed Description

Serial Peripheral Interface Master with EasyDMA (SPIM) driver.

Macro Definition Documentation

#define NRFX_SPIM_DEFAULT_CONFIG
Value:
{ \
.sck_pin = NRFX_SPIM_PIN_NOT_USED, \
.mosi_pin = NRFX_SPIM_PIN_NOT_USED, \
.miso_pin = NRFX_SPIM_PIN_NOT_USED, \
.ss_active_high = false, \
.orc = 0xFF, \
.frequency = NRF_SPIM_FREQ_4M, \
.mode = NRF_SPIM_MODE_0, \
NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
}

The default configuration of the SPIM master instance.

#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG
Value:
.rx_delay = 0x02, \
.use_hw_ss = false, \
.ss_duration = 0x02,

Extended default configuration of the SPIM instance.

#define NRFX_SPIM_INSTANCE (   id)
Value:
{ \
.p_reg = NRFX_CONCAT_2(NRF_SPIM, id), \
.drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
}

Macro for creating an instance of the SPIM driver.

#define NRFX_SPIM_SINGLE_XFER (   p_tx,
  tx_len,
  p_rx,
  rx_len 
)
Value:
{ \
.p_tx_buffer = (uint8_t const *)(p_tx), \
.tx_length = (tx_len), \
.p_rx_buffer = (p_rx), \
.rx_length = (rx_len), \
}

Macro for setting up single transfer descriptor.

This macro is for internal use only.

Enumeration Type Documentation

SPIM master driver event types, passed to the handler routine provided during initialization.

Enumerator
NRFX_SPIM_EVENT_DONE 

Transfer done.

Function Documentation

void nrfx_spim_abort ( nrfx_spim_t const *  p_instance)

Function for aborting ongoing transfer.

Parameters
[in]p_instancePointer to the driver instance structure.
uint32_t nrfx_spim_end_event_get ( nrfx_spim_t const *  p_instance)

Function for returning the address of a END SPIM event.

The END event can be used to detect the end of a transfer if the NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER option is used.

Parameters
[in]p_instancePointer to the driver instance structure.
Returns
END event address.
nrfx_err_t nrfx_spim_init ( nrfx_spim_t const *const  p_instance,
nrfx_spim_config_t const *  p_config,
nrfx_spim_evt_handler_t  handler,
void *  p_context 
)

Function for initializing the SPIM driver instance.

This function configures and enables the specified peripheral.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the initial configuration.
[in]handlerEvent handler provided by the user. If NULL, transfers will be performed in blocking mode.
[in]p_contextContext passed to event handler.
Return values
NRFX_SUCCESSInitialization was successful.
NRFX_ERROR_INVALID_STATEThe driver was already initialized.
NRFX_ERROR_BUSYSome 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_NOT_SUPPORTEDRequested configuration is not supported by the SPIM instance.
uint32_t nrfx_spim_start_task_get ( nrfx_spim_t const *  p_instance)

Function for returning the address of a SPIM start task.

This function is to be used if nrfx_spim_xfer was called with the flag NRFX_SPIM_FLAG_HOLD_XFER. In that case, the transfer is not started by the driver, but it must be started externally by PPI.

Parameters
[in]p_instancePointer to the driver instance structure.
Returns
Start task address.
void nrfx_spim_uninit ( nrfx_spim_t const *const  p_instance)

Function for uninitializing the SPIM driver instance.

Parameters
[in]p_instancePointer to the driver instance structure.
nrfx_err_t nrfx_spim_xfer ( nrfx_spim_t const *const  p_instance,
nrfx_spim_xfer_desc_t const *  p_xfer_desc,
uint32_t  flags 
)

Function for starting the SPIM data transfer.

Additional options are provided using the flags parameter:

Note
Peripherals using EasyDMA (including SPIM) 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_instancePointer to the driver instance structure.
p_xfer_descPointer to the transfer descriptor.
flagsTransfer options (0 for default settings).
Return values
NRFX_SUCCESSThe procedure is successful.
NRFX_ERROR_BUSYThe driver is not ready for a new transfer.
NRFX_ERROR_NOT_SUPPORTEDThe provided parameters are not supported.
NRFX_ERROR_INVALID_ADDRThe provided buffers are not placed in the Data RAM region.
nrfx_err_t nrfx_spim_xfer_dcx ( nrfx_spim_t const *const  p_instance,
nrfx_spim_xfer_desc_t const *  p_xfer_desc,
uint32_t  flags,
uint8_t  cmd_length 
)

Function for starting the SPIM data transfer with DCX control.

See nrfx_spim_xfer for description of additional options of transfer provided by the flags parameter.

Note
Peripherals that use EasyDMA (including SPIM) 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_instancePointer to the driver instance structure.
p_xfer_descPointer to the transfer descriptor.
flagsTransfer options (0 for default settings).
cmd_lengthLength of the command bytes preceding the data bytes. The DCX line will be low during transmission of command bytes and high during transmission of data bytes. Maximum value available for dividing the transmitted bytes into command bytes and data bytes is NRF_SPIM_DCX_CNT_ALL_CMD - 1. The NRF_SPIM_DCX_CNT_ALL_CMD value passed as the cmd_length parameter causes all transmitted bytes to be marked as command bytes.
Return values
NRFX_SUCCESSThe procedure is successful.
NRFX_ERROR_BUSYThe driver is not ready for a new transfer.
NRFX_ERROR_NOT_SUPPORTEDThe provided parameters are not supported.
NRFX_ERROR_INVALID_ADDRThe provided buffers are not placed in the Data RAM region.

Documentation feedback | Developer Zone | Subscribe | Updated