SPI driver
- group nrfx_spi
Serial Peripheral Interface master (SPI) driver.
Defines
-
NRFX_SPI_INSTANCE(id)
Macro for creating an instance of the SPI master driver.
-
NRFX_SPI_PIN_NOT_USED
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.
-
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:
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:
_pin_sck – [in] SCK pin.
_pin_mosi – [in] MOSI pin.
_pin_miso – [in] MISO pin.
_pin_ss – [in] SS pin.
-
NRFX_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len)
Macro for setting up single transfer descriptor.
This macro is for internal use only.
-
NRFX_SPI_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length)
Macro for setting the duplex TX RX transfer.
-
NRFX_SPI_XFER_TX(p_buf, length)
Macro for setting the TX transfer.
-
NRFX_SPI_XFER_RX(p_buf, length)
Macro for setting the RX transfer.
-
NRFX_SPI_INST_HANDLER_GET(idx)
Macro returning SPI interrupt handler.
param[in] idx SPI index.
- Returns:
Interrupt handler.
Typedefs
-
typedef void (*nrfx_spi_evt_handler_t)(nrfx_spi_evt_t const *p_event, void *p_context)
SPI master driver event handler type.
Enums
Functions
-
nrfx_err_t nrfx_spi_init(nrfx_spi_t const *p_instance, nrfx_spi_config_t const *p_config, nrfx_spi_evt_handler_t handler, void *p_context)
Function for initializing the SPI master driver instance.
This function configures and enables the specified peripheral.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_config – [in] Pointer to the structure with the initial configuration.
handler – [in] Event handler provided by the user. If NULL, transfers will be performed in blocking mode.
p_context – [in] Context passed to the event handler.
- Return values:
NRFX_SUCCESS – Initialization was successful.
NRFX_ERROR_ALREADY – The driver is already initialized.
NRFX_ERROR_INVALID_STATE – The driver is already initialized. Deprecated - use NRFX_ERROR_ALREADY instead.
NRFX_ERROR_BUSY – Some other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.
-
nrfx_err_t nrfx_spi_reconfigure(nrfx_spi_t const *p_instance, nrfx_spi_config_t const *p_config)
Function for reconfiguring the SPI master driver instance.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
p_config – [in] Pointer to the structure with the configuration.
- Return values:
NRFX_SUCCESS – Reconfiguration was successful.
NRFX_ERROR_BUSY – The driver is during transfer.
NRFX_ERROR_INVALID_STATE – The driver is uninitialized.
-
void nrfx_spi_uninit(nrfx_spi_t const *p_instance)
Function for uninitializing the SPI master driver instance.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
-
bool nrfx_spi_init_check(nrfx_spi_t const *p_instance)
Function for checking if the SPI driver instance is initialized.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
- Return values:
true – Instance is already initialized.
false – Instance is not initialized.
-
nrfx_err_t nrfx_spi_xfer(nrfx_spi_t const *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_instance – Pointer to the driver instance structure.
p_xfer_desc – Pointer to the transfer descriptor.
flags – Transfer options (0 for default settings). Currently, no additional flags are available.
- Return values:
NRFX_SUCCESS – The procedure is successful.
NRFX_ERROR_BUSY – The driver is not ready for a new transfer.
NRFX_ERROR_NOT_SUPPORTED – The provided parameters are not supported.
-
void nrfx_spi_abort(nrfx_spi_t const *p_instance)
Function for aborting the ongoing transfer.
- Parameters:
p_instance – [in] Pointer to the driver instance structure.
-
struct nrfx_spi_t
- #include <nrfx_spi.h>
Data structure of the Serial Peripheral Interface master (SPI) driver instance.
-
struct nrfx_spi_config_t
- #include <nrfx_spi.h>
Configuration structure of the SPI master driver instance.
Public Members
-
uint8_t sck_pin
SCK pin number.
-
uint8_t mosi_pin
MOSI pin number (optional).
Set to NRFX_SPI_PIN_NOT_USED if this signal is not needed.
-
uint8_t miso_pin
MISO pin number (optional).
Set to NRFX_SPI_PIN_NOT_USED if this signal is not needed.
-
uint8_t ss_pin
Slave Select pin number (optional).
Set to NRFX_SPI_PIN_NOT_USED if this signal is not needed. The driver supports only active low for this signal. If the signal must be active high, it must be controlled externally.
Note
Unlike the other fields that specify pin numbers, this one cannot be omitted when both GPIO configuration and pin selection are to be skipped, as the driver must control the signal as a regular GPIO.
-
uint8_t irq_priority
Interrupt priority.
-
uint8_t orc
Overrun character.
This character is used when all bytes from the TX buffer are sent, but the transfer continues due to RX.
-
nrf_spi_frequency_t frequency
SPI frequency.
-
nrf_spi_mode_t mode
SPI mode.
-
nrf_spi_bit_order_t bit_order
SPI bit order.
-
nrf_gpio_pin_pull_t miso_pull
MISO pull up configuration.
-
bool skip_gpio_cfg
Skip GPIO configuration of pins.
When set to true, the driver does not modify any GPIO parameters of the used pins. Those parameters are supposed to be configured externally before the driver is initialized.
-
bool skip_psel_cfg
Skip pin selection configuration.
When set to true, the driver does not modify pin select registers in the peripheral. Those registers are supposed to be set up externally before the driver is initialized.
Note
When both GPIO configuration and pin selection are to be skipped, the structure fields that specify pins can be omitted, as they are ignored anyway. This does not apply to the
ss_pin
field.
-
uint8_t sck_pin
-
struct nrfx_spi_xfer_desc_t
- #include <nrfx_spi.h>
Single transfer descriptor structure.
-
struct nrfx_spi_evt_t
- #include <nrfx_spi.h>
SPI master event description with transmission details.
Public Members
-
nrfx_spi_evt_type_t type
Event type.
-
nrfx_spi_xfer_desc_t xfer_desc
Transfer details.
-
nrfx_spi_evt_type_t type
-
NRFX_SPI_INSTANCE(id)