SPI HAL

group nrf_spi_hal

Hardware access layer for managing the SPI peripheral.

Defines

NRF_SPI_INST_GET(idx)

Macro getting pointer to the structure of registers of the SPI peripheral.

Parameters:
  • idx[in] SPI instance index.

Returns:

Pointer to the structure of registers of the SPI peripheral.

NRF_SPI_PIN_NOT_CONNECTED

This value can be used as a parameter for the nrf_spi_pins_set function to specify that a given SPI signal (SCK, MOSI, or MISO) shall not be connected to a physical pin.

Enums

enum nrf_spi_event_t

SPI events.

Values:

enumerator NRF_SPI_EVENT_READY

TXD byte sent and RXD byte received.

enum nrf_spi_int_mask_t

SPI interrupts.

Values:

enumerator NRF_SPI_INT_READY_MASK

Interrupt on READY event.

enumerator NRF_SPI_ALL_INTS_MASK

All SPI interrupts.

enum nrf_spi_frequency_t

SPI data rates.

Values:

enumerator NRF_SPI_FREQ_125K

125 kbps.

enumerator NRF_SPI_FREQ_250K

250 kbps.

enumerator NRF_SPI_FREQ_500K

500 kbps.

enumerator NRF_SPI_FREQ_1M

1 Mbps.

enumerator NRF_SPI_FREQ_2M

2 Mbps.

enumerator NRF_SPI_FREQ_4M

4 Mbps.

enumerator NRF_SPI_FREQ_8M

8 Mbps.

enum nrf_spi_mode_t

SPI modes.

Values:

enumerator NRF_SPI_MODE_0

SCK active high, sample on leading edge of clock.

enumerator NRF_SPI_MODE_1

SCK active high, sample on trailing edge of clock.

enumerator NRF_SPI_MODE_2

SCK active low, sample on leading edge of clock.

enumerator NRF_SPI_MODE_3

SCK active low, sample on trailing edge of clock.

enum nrf_spi_bit_order_t

SPI bit orders.

Values:

enumerator NRF_SPI_BIT_ORDER_MSB_FIRST

Most significant bit shifted out first.

enumerator NRF_SPI_BIT_ORDER_LSB_FIRST

Least significant bit shifted out first.

Functions

NRF_STATIC_INLINE void nrf_spi_event_clear(NRF_SPI_Type *p_reg, nrf_spi_event_t event)

Function for clearing the specified SPI event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to be cleared.

NRF_STATIC_INLINE bool nrf_spi_event_check(NRF_SPI_Type const *p_reg, nrf_spi_event_t event)

Function for retrieving the state of the SPI event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to be checked.

Return values:
  • true – The event has been generated.

  • false – The event has not been generated.

NRF_STATIC_INLINE uint32_t nrf_spi_event_address_get(NRF_SPI_Type const *p_reg, nrf_spi_event_t event)

Function for getting the address of the specified SPI event register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] The specified event.

Returns:

Address of the specified event register.

NRF_STATIC_INLINE void nrf_spi_int_enable(NRF_SPI_Type *p_reg, uint32_t mask)

Function for enabling the specified interrupts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be enabled.

NRF_STATIC_INLINE void nrf_spi_int_disable(NRF_SPI_Type *p_reg, uint32_t mask)

Function for disabling the specified interrupts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be disabled.

NRF_STATIC_INLINE uint32_t nrf_spi_int_enable_check(NRF_SPI_Type const *p_reg, uint32_t mask)

Function for checking if the specified interrupts are enabled.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be checked.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE void nrf_spi_enable(NRF_SPI_Type *p_reg)

Function for enabling the SPI peripheral.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_spi_disable(NRF_SPI_Type *p_reg)

Function for disabling the SPI peripheral.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_spi_pins_set(NRF_SPI_Type *p_reg, uint32_t sck_pin, uint32_t mosi_pin, uint32_t miso_pin)

Function for configuring SPI pins.

If a given signal is not needed, pass the NRF_SPI_PIN_NOT_CONNECTED value instead of its pin number.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • sck_pin[in] SCK pin number.

  • mosi_pin[in] MOSI pin number.

  • miso_pin[in] MISO pin number.

NRF_STATIC_INLINE uint32_t nrf_spi_sck_pin_get(NRF_SPI_Type const *p_reg)

Function for getting the SCK pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

SCK pin selection;

NRF_STATIC_INLINE uint32_t nrf_spi_mosi_pin_get(NRF_SPI_Type const *p_reg)

Function for getting the MOSI pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

MOSI pin selection;

NRF_STATIC_INLINE uint32_t nrf_spi_miso_pin_get(NRF_SPI_Type const *p_reg)

Function for getting the MISO pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

MISO pin selection;

NRF_STATIC_INLINE void nrf_spi_txd_set(NRF_SPI_Type *p_reg, uint8_t data)

Function for writing data to the SPI transmitter register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • data[in] TX data to send.

NRF_STATIC_INLINE uint8_t nrf_spi_rxd_get(NRF_SPI_Type const *p_reg)

Function for reading data from the SPI receiver register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

RX data received.

NRF_STATIC_INLINE void nrf_spi_frequency_set(NRF_SPI_Type *p_reg, nrf_spi_frequency_t frequency)

Function for setting the SPI master data rate.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • frequency[in] SPI frequency.

NRF_STATIC_INLINE void nrf_spi_configure(NRF_SPI_Type *p_reg, nrf_spi_mode_t spi_mode, nrf_spi_bit_order_t spi_bit_order)

Function for setting the SPI configuration.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • spi_mode[in] SPI mode.

  • spi_bit_order[in] SPI bit order.