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

Serial Peripheral Interface master (SPI) driver. More...

Topics

 SPI peripheral driver configuration
 

Data Structures

struct  nrfx_spi_xfer_desc_t
 Single transfer descriptor structure. More...
 
struct  nrfx_spi_event_t
 SPI master event description with transmission details. More...
 
struct  nrfx_spi_t
 Data structure of the Serial Peripheral Interface master (SPI) driver instance. More...
 
struct  nrfx_spi_config_t
 Configuration structure of the SPI master driver instance. More...
 

Macros

#define NRFX_SPI_INSTANCE(reg)
 Macro for creating an instance of the SPI master driver.
 
#define NRFX_SPI_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_SPI_DEFAULT_CONFIG(_pin_sck, _pin_mosi, _pin_miso, _pin_ss)
 SPI master instance default configuration. This configuration sets up SPI with the following options:
 
#define NRFX_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len)
 Macro for setting up single transfer descriptor.
 
#define NRFX_SPI_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length)
 Macro for setting the duplex TX RX transfer.
 
#define NRFX_SPI_XFER_TX(p_buf, length)
 Macro for setting the TX transfer.
 
#define NRFX_SPI_XFER_RX(p_buf, length)
 Macro for setting the RX transfer.
 
#define NRFX_SPI_INST_HANDLER_GET(idx)
 Macro returning SPI interrupt handler.
 

Typedefs

typedef void(* nrfx_spi_event_handler_t) (nrfx_spi_event_t const *p_event, void *p_context)
 SPI master driver event handler type.
 

Enumerations

enum  nrfx_spi_event_type_t { NRFX_SPI_EVENT_DONE }
 SPI master driver event types, passed to the handler routine provided during initialization. More...
 

Functions

int nrfx_spi_init (nrfx_spi_t *p_instance, nrfx_spi_config_t const *p_config, nrfx_spi_event_handler_t handler, void *p_context)
 Function for initializing the SPI master driver instance.
 
int nrfx_spi_reconfigure (nrfx_spi_t *p_instance, nrfx_spi_config_t const *p_config)
 Function for reconfiguring the SPI master driver instance.
 
void nrfx_spi_uninit (nrfx_spi_t *p_instance)
 Function for uninitializing the SPI master driver instance.
 
int nrfx_spi_xfer (nrfx_spi_t *p_instance, nrfx_spi_xfer_desc_t const *p_xfer_desc, uint32_t flags)
 Function for starting the SPI data transfer.
 
void nrfx_spi_abort (nrfx_spi_t *p_instance)
 Function for aborting the ongoing transfer.
 
void nrfx_spi_irq_handler (nrfx_spi_t *p_instance)
 Driver interrupt handler.
 
bool nrfx_spi_init_check (nrfx_spi_t const *p_instance)
 Function for checking if the SPI driver instance is initialized.
 

Detailed Description

Serial Peripheral Interface master (SPI) driver.

Macro Definition Documentation

◆ NRFX_SPI_DEFAULT_CONFIG

#define NRFX_SPI_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, \
.orc = 0xFF, \
.frequency = NRF_SPI_FREQ_4M, \
.mode = NRF_SPI_MODE_0, \
.miso_pull = NRF_GPIO_PIN_NOPULL, \
}
@ NRF_GPIO_PIN_NOPULL
Pin pull-up resistor disabled.
Definition nrf_gpio.h:235
@ NRF_SPI_MODE_0
SCK active high, sample on leading edge of clock.
Definition nrf_spi.h:97
@ NRF_SPI_FREQ_4M
4 Mbps.
Definition nrf_spi.h:88
@ NRF_SPI_BIT_ORDER_MSB_FIRST
Most significant bit shifted out first.
Definition nrf_spi.h:106
#define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY
Interrupt priority.
Definition nrfx_spi_dox_config.h:30

SPI master instance default configuration. This configuration sets up SPI with the following options:

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

◆ NRFX_SPI_INST_HANDLER_GET

#define NRFX_SPI_INST_HANDLER_GET ( idx)
Value:
NRFX_CONCAT_3(nrfx_spi_, idx, _irq_handler)
#define NRFX_CONCAT_3(p1, p2, p3)
Macro for concatenating three tokens in macro expansion.
Definition nrfx_utils.h:164

Macro returning SPI interrupt handler.

param[in] idx SPI index.

Returns
Interrupt handler.

◆ NRFX_SPI_INSTANCE

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

Macro for creating an instance of the SPI master driver.

◆ NRFX_SPI_SINGLE_XFER

#define NRFX_SPI_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_SPI_XFER_RX

#define NRFX_SPI_XFER_RX ( p_buf,
length )
Value:
NRFX_SPI_SINGLE_XFER(NULL, 0, p_buf, length)
#define NRFX_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len)
Macro for setting up single transfer descriptor.
Definition nrfx_spi.h:242

Macro for setting the RX transfer.

◆ NRFX_SPI_XFER_TRX

#define NRFX_SPI_XFER_TRX ( p_tx_buf,
tx_length,
p_rx_buf,
rx_length )
Value:
NRFX_SPI_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)

Macro for setting the duplex TX RX transfer.

◆ NRFX_SPI_XFER_TX

#define NRFX_SPI_XFER_TX ( p_buf,
length )
Value:
NRFX_SPI_SINGLE_XFER(p_buf, length, NULL, 0)

Macro for setting the TX transfer.

Enumeration Type Documentation

◆ nrfx_spi_event_type_t

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

Enumerator
NRFX_SPI_EVENT_DONE 

Transfer done.

Function Documentation

◆ nrfx_spi_abort()

void nrfx_spi_abort ( nrfx_spi_t * p_instance)

Function for aborting the ongoing transfer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_spi_init()

int nrfx_spi_init ( nrfx_spi_t * p_instance,
nrfx_spi_config_t const * p_config,
nrfx_spi_event_handler_t handler,
void * p_context )

Function for initializing the SPI master 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 the event handler.
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.

◆ nrfx_spi_init_check()

bool nrfx_spi_init_check ( nrfx_spi_t const * p_instance)

Function for checking if the SPI driver instance is initialized.

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

◆ nrfx_spi_irq_handler()

void nrfx_spi_irq_handler ( nrfx_spi_t * p_instance)

Driver interrupt handler.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_spi_reconfigure()

int nrfx_spi_reconfigure ( nrfx_spi_t * p_instance,
nrfx_spi_config_t const * p_config )

Function for reconfiguring the SPI master driver instance.

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.

◆ nrfx_spi_uninit()

void nrfx_spi_uninit ( nrfx_spi_t * p_instance)

Function for uninitializing the SPI master driver instance.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_spi_xfer()

int nrfx_spi_xfer ( nrfx_spi_t * p_instance,
nrfx_spi_xfer_desc_t const * p_xfer_desc,
uint32_t flags )

Function for starting the SPI data transfer.

If an event handler was provided in the nrfx_spi_init call, this function returns immediately and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, which means that this function returns when the transfer is finished.

Parameters
p_instancePointer to the driver instance structure.
p_xfer_descPointer to the transfer descriptor.
flagsTransfer options (0 for default settings). Currently, no additional flags are available.
Return values
0The procedure is successful.
-EBUSYThe driver is not ready for a new transfer.
-ENOTSUPThe provided parameters are not supported.