nrfx 4.5.0
Loading...
Searching...
No Matches
SPIM driver

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

Topics

 SPIM peripheral driver configuration
 

Data Structures

struct  nrfx_spim_event_t
 SPIM event description with transmission details. More...
 
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...
 

Macros

#define NRFX_SPIM_INSTANCE(reg)
 Macro for creating an instance of the SPIM driver.
 
#define NRFX_SPIM_DEFAULT_CONFIG(_pin_sck, _pin_mosi, _pin_miso, _pin_ss)
 SPIM driver default configuration.
 
#define NRFX_SPIM_FREQUENCY_STATIC_CHECK(id, frequency)
 Macro for checking whether specified frequency can be achieved for a given SPIM instance.
 
#define NRFX_SPIM_BASE_FREQUENCY_GET(p_instance)
 Macro for getting base frequency value in Hz for a given SPIM instance.
 
#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.
 
#define NRFX_SPIM_XFER_TRX(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)
 Macro for setting the TX transfer.
 
#define NRFX_SPIM_XFER_RX(p_buf, length)
 Macro for setting the RX transfer.
 

Typedefs

typedef nrfy_spim_xfer_desc_t nrfx_spim_xfer_desc_t
 Single transfer descriptor structure.
 
typedef void(* nrfx_spim_event_handler_t) (nrfx_spim_event_t const *p_event, void *p_context)
 SPIM event handler type for user-defined callback function.
 

Enumerations

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

Functions

int nrfx_spim_init (nrfx_spim_t *p_instance, nrfx_spim_config_t const *p_config, nrfx_spim_event_handler_t handler, void *p_context)
 Function for initializing the SPIM driver instance.
 
int nrfx_spim_reconfigure (nrfx_spim_t *p_instance, nrfx_spim_config_t const *p_config)
 Function for reconfiguring the SPIM driver instance.
 
void nrfx_spim_uninit (nrfx_spim_t *p_instance)
 Function for uninitializing the SPIM driver instance.
 
bool nrfx_spim_init_check (nrfx_spim_t const *p_instance)
 Function for checking if the SPIM driver instance is initialized.
 
int nrfx_spim_xfer (nrfx_spim_t *p_instance, nrfx_spim_xfer_desc_t const *p_xfer_desc, uint32_t flags)
 Function for starting the SPIM data transfer.
 
int nrfx_spim_xfer_dcx (nrfx_spim_t *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.
 
NRFX_STATIC_INLINE uint32_t nrfx_spim_start_task_address_get (nrfx_spim_t const *p_instance)
 Function for returning the address of a SPIM start task.
 
NRFX_STATIC_INLINE uint32_t nrfx_spim_end_event_address_get (nrfx_spim_t const *p_instance)
 Function for returning the address of a END SPIM event.
 
void nrfx_spim_abort (nrfx_spim_t *p_instance)
 Function for aborting ongoing transfer.
 
void nrfx_spim_irq_handler (nrfx_spim_t *p_instance)
 Driver interrupt handler.
 
void nrfx_spim_nrf52_anomaly_58_init (nrfx_spim_t *p_instance, nrfx_gpiote_t *p_gpiote_inst)
 Function for providing GPIOTE driver instance for the nRF52 Anomaly 58 workaround.
 

Detailed Description

Serial Peripheral Interface Master with EasyDMA (SPIM) driver.

Macro Definition Documentation

◆ NRFX_SPIM_BASE_FREQUENCY_GET

#define NRFX_SPIM_BASE_FREQUENCY_GET ( p_instance)
Value:
NRF_SPIM_BASE_FREQUENCY_GET((p_instance)->p_reg)
#define NRF_SPIM_BASE_FREQUENCY_GET(p_reg)
Macro for getting base frequency value in Hz for the specified SPIM instance.
Definition nrf_spim.h:311

Macro for getting base frequency value in Hz for a given SPIM instance.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ NRFX_SPIM_DEFAULT_CONFIG

#define NRFX_SPIM_DEFAULT_CONFIG ( _pin_sck,
_pin_mosi,
_pin_miso,
_pin_ss )
Value:
{ \
.sck_pin = _pin_sck, \
.mosi_pin = _pin_mosi, \
.miso_pin = _pin_miso, \
.ss_pin = _pin_ss, \
.ss_active_high = false, \
.orc = 0xFF, \
.frequency = NRFX_MHZ_TO_HZ(4), \
.mode = NRF_SPIM_MODE_0, \
.miso_pull = NRF_GPIO_PIN_NOPULL, \
NRFX_COND_CODE_1(NRF_SPIM_HAS_DCX, (.dcx_pin = NRF_SPIM_DCX_DEFAULT,), ()) \
NRFX_COND_CODE_1(NRF_SPIM_HAS_RXDELAY, (.rx_delay = NRF_SPIM_RXDELAY_DEFAULT,), ()) \
NRFX_COND_CODE_1(NRF_SPIM_HAS_HW_CSN, (.use_hw_ss = false, \
.ss_duration = NRF_SPIM_CSNDUR_DEFAULT,), ()) \
}
@ NRF_GPIO_PIN_NOPULL
Pin pull-up resistor disabled.
Definition nrf_gpio.h:235
#define NRF_SPIM_HAS_DCX
Macro for checking if the DCX pin control is available.
Definition nrf_spim.h:145
#define NRF_SPIM_RXDELAY_DEFAULT
Symbol specifying default value of RX delay setting.
Definition nrf_spim.h:226
#define NRF_SPIM_CSNDUR_DEFAULT
Symbol specifying default value of CSN duration setting.
Definition nrf_spim.h:209
#define NRF_SPIM_HAS_RXDELAY
Macro for checking if the RXDELAY function is available.
Definition nrf_spim.h:152
#define NRF_SPIM_HAS_HW_CSN
Macro for checking if the hardware chip select function is available.
Definition nrf_spim.h:136
#define NRF_SPIM_DCX_DEFAULT
Symbol specifying default value of DCX pin setting.
Definition nrf_spim.h:197
@ NRF_SPIM_BIT_ORDER_MSB_FIRST
Most significant bit shifted out first.
Definition nrf_spim.h:519
@ NRF_SPIM_MODE_0
SCK active high, sample on leading edge of clock.
Definition nrf_spim.h:510
#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY
Interrupt priority.
Definition nrfx_spim_dox_config.h:30
#define NRFX_MHZ_TO_HZ(freq)
Macro for converting frequency in MHz to Hz.
Definition nrfx_utils.h:622

SPIM driver default configuration.

This configuration sets up SPIM with the following options:

  • SS pin active low
  • over-run character set to 0xFF
  • clock frequency: 4 MHz
  • mode: 0 (SCK active high, sample on leading edge of the clock signal)
  • MSB shifted out first
  • MISO pull-up disabled
Parameters
[in]_pin_sckSCK pin.
[in]_pin_mosiMOSI pin.
[in]_pin_misoMISO pin.
[in]_pin_ssSlave select pin.

◆ NRFX_SPIM_FREQUENCY_STATIC_CHECK

#define NRFX_SPIM_FREQUENCY_STATIC_CHECK ( id,
frequency )
Value:
#define NRF_SPIM_FREQUENCY_STATIC_CHECK(p_reg, frequency)
Macro for checking whether specified frequency can be achieved for a given SPIM instance.
Definition nrf_spim.h:360
#define NRF_SPIM_INST_GET(idx)
Macro getting pointer to the structure of registers of the SPIM peripheral.
Definition nrf_spim.h:80

Macro for checking whether specified frequency can be achieved for a given SPIM instance.

Note
This macro uses a compile-time assertion.
Parameters
[in]idIndex of the specified SPIM instance.
[in]frequencyDesired frequency value in Hz.

◆ NRFX_SPIM_INSTANCE

#define NRFX_SPIM_INSTANCE ( reg)
Value:
{ \
.p_reg = (NRF_SPIM_Type *)reg, \
.cb = {0}, \
}

Macro for creating an instance of the SPIM driver.

◆ NRFX_SPIM_SINGLE_XFER

#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.

◆ NRFX_SPIM_XFER_RX

#define NRFX_SPIM_XFER_RX ( p_buf,
length )
Value:
NRFX_SPIM_SINGLE_XFER(NULL, 0, p_buf, length)
#define NRFX_SPIM_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len)
Macro for setting up single transfer descriptor.
Definition nrfx_spim.h:265

Macro for setting the RX transfer.

◆ NRFX_SPIM_XFER_TRX

#define NRFX_SPIM_XFER_TRX ( p_tx_buf,
tx_length,
p_rx_buf,
rx_length )
Value:
NRFX_SPIM_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)

Macro for setting the duplex TX RX transfer.

◆ NRFX_SPIM_XFER_TX

#define NRFX_SPIM_XFER_TX ( p_buf,
length )
Value:
NRFX_SPIM_SINGLE_XFER(p_buf, length, NULL, 0)

Macro for setting the TX transfer.

Enumeration Type Documentation

◆ nrfx_spim_event_type_t

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

Enumerator
NRFX_SPIM_EVENT_DONE 

Transfer done.

Function Documentation

◆ nrfx_spim_abort()

void nrfx_spim_abort ( nrfx_spim_t * p_instance)

Function for aborting ongoing transfer.

Note
You should call the function if the first transfer has been started with one or more of the following options: NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER, NRFX_SPIM_FLAG_HOLD_XFER, and NRFX_SPIM_FLAG_REPEATED_XFER. When you do not expect more transfers, use this function so that the driver can put the peripheral into a low power state.
Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_spim_end_event_address_get()

NRFX_STATIC_INLINE uint32_t nrfx_spim_end_event_address_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_spim_init()

int nrfx_spim_init ( nrfx_spim_t * p_instance,
nrfx_spim_config_t const * p_config,
nrfx_spim_event_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. NULL if configuration is to be skipped and will be done later using nrfx_spim_reconfigure.
[in]handlerEvent handler provided by the user. If NULL, transfers will be performed in blocking mode.
[in]p_contextContext passed to event handler.
Warning
On nRF5340, 32 MHz setting for SPIM4 peripheral instance is supported only on the dedicated pins with NRF_GPIO_PIN_SEL_PERIPHERAL configuration. See the chapter Pin assignments in the Product Specification.
Return values
0Initialization was successful.
-EALREADYThe driver is already initialized.
-EBUSYSome other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.
-ENOTSUPRequested configuration is not supported by the SPIM instance.
-EINVALRequested frequency is not available on the specified driver instance or pins.

◆ nrfx_spim_init_check()

bool nrfx_spim_init_check ( nrfx_spim_t const * p_instance)

Function for checking if the SPIM driver instance is initialized.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueInstance is already initialized.
falseInstance is not initialized.

◆ nrfx_spim_irq_handler()

void nrfx_spim_irq_handler ( nrfx_spim_t * p_instance)

Driver interrupt handler.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_spim_nrf52_anomaly_58_init()

void nrfx_spim_nrf52_anomaly_58_init ( nrfx_spim_t * p_instance,
nrfx_gpiote_t * p_gpiote_inst )

Function for providing GPIOTE driver instance for the nRF52 Anomaly 58 workaround.

Warning
Must be called before nrfx_spim_xfer.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_gpiote_instPointer to the GPIOTE driver instance structure.

◆ nrfx_spim_reconfigure()

int nrfx_spim_reconfigure ( nrfx_spim_t * p_instance,
nrfx_spim_config_t const * p_config )

Function for reconfiguring the SPIM driver instance.

Note
This function can not be called during transmission.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the configuration.
Return values
0Reconfiguration was successful.
-EBUSYThe driver is during transfer.
-EINPROGRESSThe driver is uninitialized.
-ENOTSUPRequested configuration is not supported by the SPIM instance.
-EINVALRequested frequency is not available on the specified driver instance or pins.
-EPERMSoftware-controlled Slave Select and hardware-controlled Slave Select cannot be active at the same time.

◆ nrfx_spim_start_task_address_get()

NRFX_STATIC_INLINE uint32_t nrfx_spim_start_task_address_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.

◆ nrfx_spim_uninit()

void nrfx_spim_uninit ( nrfx_spim_t * p_instance)

Function for uninitializing the SPIM driver instance.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_spim_xfer()

int nrfx_spim_xfer ( nrfx_spim_t * 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 -EACCES.
Parameters
p_instancePointer to the driver instance structure.
p_xfer_descPointer to the transfer descriptor.
flagsTransfer options (0 for default settings).
Return values
0The procedure is successful.
-EBUSYThe driver is not ready for a new transfer.
-ENOTSUPThe provided parameters are not supported.
-EACCESThe provided buffers are not placed in the Data RAM region.

◆ nrfx_spim_xfer_dcx()

int nrfx_spim_xfer_dcx ( nrfx_spim_t * 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 -EACCES.
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
0The procedure is successful.
-EBUSYThe driver is not ready for a new transfer.
-ENOTSUPThe provided parameters are not supported.
-EACCESThe provided buffers are not placed in the Data RAM region.