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.
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.
- Returns NRFX_SUCCESS
Initialization was successful.
- Returns NRFX_ERROR_INVALID_STATE
The driver was already initialized.
- Returns 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.
-
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.
-
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.
- Returns NRFX_SUCCESS
The procedure is successful.
- Returns NRFX_ERROR_BUSY
The driver is not ready for a new transfer.
- Returns 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.
-
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.
-
uint8_t
-
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
-