SPIM HAL

group nrf_spim_hal

Hardware access layer for managing the SPIM peripheral.

Defines

NRF_SPIM_HAS_32_MHZ_FREQ

Symbol indicating whether 32 MHz clock frequency is available.

NRF_SPIM_PIN_NOT_CONNECTED

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

NRF_SPIM_HW_CSN_PRESENT

Macro for checking if the hardware chip select function is available.

NRF_SPIM_DCX_PRESENT

Macro for checking if the DCX pin control is available.

NRF_SPIM_RXDELAY_PRESENT

Macro for checking if the RXDELAY function is available.

NRF_SPIM_DCX_CNT_ALL_CMD

This value specified in the DCX line configuration causes this line to be set low during whole transmission (all transmitted bytes are marked as command bytes). Any lower value causes the DCX line to be switched from low to high after this number of bytes is transmitted (all remaining bytes are marked as data bytes).

Enums

enum nrf_spim_task_t

SPIM tasks.

Values:

enumerator NRF_SPIM_TASK_START

Start SPI transaction.

enumerator NRF_SPIM_TASK_STOP

Stop SPI transaction.

enumerator NRF_SPIM_TASK_SUSPEND

Suspend SPI transaction.

enumerator NRF_SPIM_TASK_RESUME

Resume SPI transaction.

enum nrf_spim_event_t

SPIM events.

Values:

enumerator NRF_SPIM_EVENT_STOPPED

SPI transaction has stopped.

enumerator NRF_SPIM_EVENT_ENDRX

End of RXD buffer reached.

enumerator NRF_SPIM_EVENT_END

End of RXD buffer and TXD buffer reached.

enumerator NRF_SPIM_EVENT_ENDTX

End of TXD buffer reached.

enumerator NRF_SPIM_EVENT_STARTED

Transaction started.

enum nrf_spim_short_mask_t

SPIM shortcuts.

Values:

enumerator NRF_SPIM_SHORT_END_START_MASK

Shortcut between END event and START task.

enumerator NRF_SPIM_ALL_SHORTS_MASK

All SPIM shortcuts.

enum nrf_spim_int_mask_t

SPIM interrupts.

Values:

enumerator NRF_SPIM_INT_STOPPED_MASK

Interrupt on STOPPED event.

enumerator NRF_SPIM_INT_ENDRX_MASK

Interrupt on ENDRX event.

enumerator NRF_SPIM_INT_END_MASK

Interrupt on END event.

enumerator NRF_SPIM_INT_ENDTX_MASK

Interrupt on ENDTX event.

enumerator NRF_SPIM_INT_STARTED_MASK

Interrupt on STARTED event.

enumerator NRF_SPIM_ALL_INTS_MASK

All SPIM interrupts.

enum nrf_spim_frequency_t

SPI master data rates.

Values:

enumerator NRF_SPIM_FREQ_125K

125 kbps.

enumerator NRF_SPIM_FREQ_250K

250 kbps.

enumerator NRF_SPIM_FREQ_500K

500 kbps.

enumerator NRF_SPIM_FREQ_1M

1 Mbps.

enumerator NRF_SPIM_FREQ_2M

2 Mbps.

enumerator NRF_SPIM_FREQ_4M

4 Mbps.

enumerator NRF_SPIM_FREQ_8M

8 Mbps.

enumerator NRF_SPIM_FREQ_16M

16 Mbps.

enumerator NRF_SPIM_FREQ_32M

32 Mbps.

enum nrf_spim_mode_t

SPI modes.

Values:

enumerator NRF_SPIM_MODE_0

SCK active high, sample on leading edge of clock.

enumerator NRF_SPIM_MODE_1

SCK active high, sample on trailing edge of clock.

enumerator NRF_SPIM_MODE_2

SCK active low, sample on leading edge of clock.

enumerator NRF_SPIM_MODE_3

SCK active low, sample on trailing edge of clock.

enum nrf_spim_bit_order_t

SPI bit orders.

Values:

enumerator NRF_SPIM_BIT_ORDER_MSB_FIRST

Most significant bit shifted out first.

enumerator NRF_SPIM_BIT_ORDER_LSB_FIRST

Least significant bit shifted out first.

enum nrf_spim_csn_pol_t

SPI CSN pin polarity.

Values:

enumerator NRF_SPIM_CSN_POL_LOW

Active low (idle state high).

enumerator NRF_SPIM_CSN_POL_HIGH

Active high (idle state low).

Functions

NRF_STATIC_INLINE void nrf_spim_task_trigger(NRF_SPIM_Type *p_reg, nrf_spim_task_t task)

Function for activating the specified SPIM task.

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

  • task[in] Task to be activated.

NRF_STATIC_INLINE uint32_t nrf_spim_task_address_get(NRF_SPIM_Type const *p_reg, nrf_spim_task_t task)

Function for getting the address of the specified SPIM task register.

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

  • task[in] The specified task.

Returns

Address of the specified task register.

NRF_STATIC_INLINE void nrf_spim_event_clear(NRF_SPIM_Type *p_reg, nrf_spim_event_t event)

Function for clearing the specified SPIM 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_spim_event_check(NRF_SPIM_Type const *p_reg, nrf_spim_event_t event)

Function for retrieving the state of the SPIM 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_spim_event_address_get(NRF_SPIM_Type const *p_reg, nrf_spim_event_t event)

Function for getting the address of the specified SPIM 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_spim_shorts_enable(NRF_SPIM_Type *p_reg, uint32_t mask)

Function for enabling the specified shortcuts.

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

  • mask[in] Shortcuts to be enabled.

NRF_STATIC_INLINE void nrf_spim_shorts_disable(NRF_SPIM_Type *p_reg, uint32_t mask)

Function for disabling the specified shortcuts.

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

  • mask[in] Shortcuts to be disabled.

NRF_STATIC_INLINE uint32_t nrf_spim_shorts_get(NRF_SPIM_Type const *p_reg)

Function for getting the shortcut setting.

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

Returns

Current shortcut configuration.

NRF_STATIC_INLINE void nrf_spim_int_enable(NRF_SPIM_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_spim_int_disable(NRF_SPIM_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_spim_int_enable_check(NRF_SPIM_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_spim_subscribe_set(NRF_SPIM_Type *p_reg, nrf_spim_task_t task, uint8_t channel)

Function for setting the subscribe configuration for a given SPIM task.

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

  • task[in] Task for which to set the configuration.

  • channel[in] Channel through which to subscribe events.

NRF_STATIC_INLINE void nrf_spim_subscribe_clear(NRF_SPIM_Type *p_reg, nrf_spim_task_t task)

Function for clearing the subscribe configuration for a given SPIM task.

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

  • task[in] Task for which to clear the configuration.

NRF_STATIC_INLINE void nrf_spim_publish_set(NRF_SPIM_Type *p_reg, nrf_spim_event_t event, uint8_t channel)

Function for setting the publish configuration for a given SPIM event.

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

  • event[in] Event for which to set the configuration.

  • channel[in] Channel through which to publish the event.

NRF_STATIC_INLINE void nrf_spim_publish_clear(NRF_SPIM_Type *p_reg, nrf_spim_event_t event)

Function for clearing the publish configuration for a given SPIM event.

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

  • event[in] Event for which to clear the configuration.

NRF_STATIC_INLINE void nrf_spim_enable(NRF_SPIM_Type *p_reg)

Function for enabling the SPIM peripheral.

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

NRF_STATIC_INLINE void nrf_spim_disable(NRF_SPIM_Type *p_reg)

Function for disabling the SPIM peripheral.

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

NRF_STATIC_INLINE void nrf_spim_pins_set(NRF_SPIM_Type *p_reg, uint32_t sck_pin, uint32_t mosi_pin, uint32_t miso_pin)

Function for configuring SPIM pins.

If a given signal is not needed, pass the NRF_SPIM_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_spim_sck_pin_get(NRF_SPIM_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_spim_mosi_pin_get(NRF_SPIM_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_spim_miso_pin_get(NRF_SPIM_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_spim_csn_configure(NRF_SPIM_Type *p_reg, uint32_t pin, nrf_spim_csn_pol_t polarity, uint32_t duration)

Function for configuring the SPIM hardware CSN pin.

If this signal is not needed, pass the NRF_SPIM_PIN_NOT_CONNECTED value instead of its pin number.

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

  • pin[in] CSN pin number.

  • polarity[in] CSN pin polarity.

  • duration[in] Minimum duration between the edge of CSN and the edge of SCK and minimum duration of CSN must stay unselected between transactions. The value is specified in number of 64 MHz clock cycles (15.625 ns).

NRF_STATIC_INLINE void nrf_spim_dcx_pin_set(NRF_SPIM_Type *p_reg, uint32_t dcx_pin)

Function for configuring the SPIM DCX pin.

If this signal is not needed, pass the NRF_SPIM_PIN_NOT_CONNECTED value instead of its pin number.

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

  • dcx_pin[in] DCX pin number.

NRF_STATIC_INLINE uint32_t nrf_spim_dcx_pin_get(NRF_SPIM_Type const *p_reg)

Function for getting the DCX pin selection.

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

Returns

DCX pin selection.

NRF_STATIC_INLINE void nrf_spim_dcx_cnt_set(NRF_SPIM_Type *p_reg, uint32_t count)

Function for configuring the number of command 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 count parameter causes all transmitted bytes to be marked as command bytes.

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

  • count[in] Number of command bytes preceding the data bytes.

NRF_STATIC_INLINE void nrf_spim_iftiming_set(NRF_SPIM_Type *p_reg, uint32_t rxdelay)

Function for configuring the extended SPIM interface.

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

  • rxdelay[in] Sample delay for input serial data on MISO, specified in 64 MHz clock cycles (15.625 ns) from the sampling edge of SCK.

NRF_STATIC_INLINE void nrf_spim_stallstat_rx_clear(NRF_SPIM_Type *p_reg)

Function for clearing stall status for RX EasyDMA RAM accesses.

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

NRF_STATIC_INLINE bool nrf_spim_stallstat_rx_get(NRF_SPIM_Type const *p_reg)

Function for getting stall status for RX EasyDMA RAM accesses.

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

Returns

Stall status of RX EasyDMA RAM accesses.

NRF_STATIC_INLINE void nrf_spim_stallstat_tx_clear(NRF_SPIM_Type *p_reg)

Function for clearing stall status for TX EasyDMA RAM accesses.

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

NRF_STATIC_INLINE bool nrf_spim_stallstat_tx_get(NRF_SPIM_Type const *p_reg)

Function for getting stall status for TX EasyDMA RAM accesses.

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

Returns

Stall status of TX EasyDMA RAM accesses.

NRF_STATIC_INLINE void nrf_spim_frequency_set(NRF_SPIM_Type *p_reg, nrf_spim_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_spim_tx_buffer_set(NRF_SPIM_Type *p_reg, uint8_t const *p_buffer, size_t length)

Function for setting the transmit buffer.

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

  • p_buffer[in] Pointer to the buffer with data to send.

  • length[in] Maximum number of data bytes to transmit.

NRF_STATIC_INLINE void nrf_spim_rx_buffer_set(NRF_SPIM_Type *p_reg, uint8_t *p_buffer, size_t length)

Function for setting the receive buffer.

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

  • p_buffer[in] Pointer to the buffer for received data.

  • length[in] Maximum number of data bytes to receive.

NRF_STATIC_INLINE void nrf_spim_configure(NRF_SPIM_Type *p_reg, nrf_spim_mode_t spi_mode, nrf_spim_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.

NRF_STATIC_INLINE void nrf_spim_orc_set(NRF_SPIM_Type *p_reg, uint8_t orc)

Function for setting the over-read character.

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

  • orc[in] Over-read character that is clocked out in case of an over-read of the TXD buffer.

NRF_STATIC_INLINE void nrf_spim_tx_list_enable(NRF_SPIM_Type *p_reg)

Function for enabling the TX list feature.

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

NRF_STATIC_INLINE void nrf_spim_tx_list_disable(NRF_SPIM_Type *p_reg)

Function for disabling the TX list feature.

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

NRF_STATIC_INLINE void nrf_spim_rx_list_enable(NRF_SPIM_Type *p_reg)

Function for enabling the RX list feature.

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

NRF_STATIC_INLINE void nrf_spim_rx_list_disable(NRF_SPIM_Type *p_reg)

Function for disabling the RX list feature.

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