SPIM HAL

nRF5 SDK v12.2.0

Hardware access layer for accessing the SPIM peripheral. More...

Macros

#define NRF_SPIM_PIN_NOT_CONNECTED 0xFFFFFFFF
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.

Enumerations

enum nrf_spim_task_t {
NRF_SPIM_TASK_START = offsetof(NRF_SPIM_Type, TASKS_START),
NRF_SPIM_TASK_STOP = offsetof(NRF_SPIM_Type, TASKS_STOP),
NRF_SPIM_TASK_SUSPEND = offsetof(NRF_SPIM_Type, TASKS_SUSPEND),
NRF_SPIM_TASK_RESUME = offsetof(NRF_SPIM_Type, TASKS_RESUME)
}
SPIM tasks. More...
enum nrf_spim_event_t {
NRF_SPIM_EVENT_STOPPED = offsetof(NRF_SPIM_Type, EVENTS_STOPPED),
NRF_SPIM_EVENT_ENDRX = offsetof(NRF_SPIM_Type, EVENTS_ENDRX),
NRF_SPIM_EVENT_END = offsetof(NRF_SPIM_Type, EVENTS_END),
NRF_SPIM_EVENT_ENDTX = offsetof(NRF_SPIM_Type, EVENTS_ENDTX),
NRF_SPIM_EVENT_STARTED = offsetof(NRF_SPIM_Type, EVENTS_STARTED)
}
SPIM events. More...
enum nrf_spim_short_mask_t { NRF_SPIM_SHORT_END_START_MASK = SPIM_SHORTS_END_START_Msk }
SPIM shortcuts. More...
enum nrf_spim_int_mask_t {
NRF_SPIM_INT_STOPPED_MASK = SPIM_INTENSET_STOPPED_Msk,
NRF_SPIM_INT_ENDRX_MASK = SPIM_INTENSET_ENDRX_Msk,
NRF_SPIM_INT_END_MASK = SPIM_INTENSET_END_Msk,
NRF_SPIM_INT_ENDTX_MASK = SPIM_INTENSET_ENDTX_Msk,
NRF_SPIM_INT_STARTED_MASK = SPIM_INTENSET_STARTED_Msk
}
SPIM interrupts. More...
enum nrf_spim_frequency_t {
NRF_SPIM_FREQ_125K = SPIM_FREQUENCY_FREQUENCY_K125,
NRF_SPIM_FREQ_250K = SPIM_FREQUENCY_FREQUENCY_K250,
NRF_SPIM_FREQ_500K = SPIM_FREQUENCY_FREQUENCY_K500,
NRF_SPIM_FREQ_1M = SPIM_FREQUENCY_FREQUENCY_M1,
NRF_SPIM_FREQ_2M = SPIM_FREQUENCY_FREQUENCY_M2,
NRF_SPIM_FREQ_4M = SPIM_FREQUENCY_FREQUENCY_M4,
NRF_SPIM_FREQ_8M = (int)SPIM_FREQUENCY_FREQUENCY_M8
}
SPI master data rates. More...
enum nrf_spim_mode_t {
NRF_SPIM_MODE_0 ,
NRF_SPIM_MODE_1 ,
NRF_SPIM_MODE_2 ,
NRF_SPIM_MODE_3
}
SPI modes. More...
enum nrf_spim_bit_order_t {
NRF_SPIM_BIT_ORDER_MSB_FIRST = SPIM_CONFIG_ORDER_MsbFirst,
NRF_SPIM_BIT_ORDER_LSB_FIRST = SPIM_CONFIG_ORDER_LsbFirst
}
SPI bit orders. More...

Functions

__STATIC_INLINE void nrf_spim_task_trigger (NRF_SPIM_Type *p_reg, nrf_spim_task_t spim_task)
Function for activating a specific SPIM task. More...
__STATIC_INLINE uint32_t nrf_spim_task_address_get (NRF_SPIM_Type *p_reg, nrf_spim_task_t spim_task)
Function for getting the address of a specific SPIM task register. More...
__STATIC_INLINE void nrf_spim_event_clear (NRF_SPIM_Type *p_reg, nrf_spim_event_t spim_event)
Function for clearing a specific SPIM event. More...
__STATIC_INLINE bool nrf_spim_event_check (NRF_SPIM_Type *p_reg, nrf_spim_event_t spim_event)
Function for checking the state of a specific SPIM event. More...
__STATIC_INLINE uint32_t nrf_spim_event_address_get (NRF_SPIM_Type *p_reg, nrf_spim_event_t spim_event)
Function for getting the address of a specific SPIM event register. More...
__STATIC_INLINE void nrf_spim_shorts_enable (NRF_SPIM_Type *p_reg, uint32_t spim_shorts_mask)
Function for enabling specified shortcuts. More...
__STATIC_INLINE void nrf_spim_shorts_disable (NRF_SPIM_Type *p_reg, uint32_t spim_shorts_mask)
Function for disabling specified shortcuts. More...
__STATIC_INLINE uint32_t nrf_spim_shorts_get (NRF_SPIM_Type *p_reg)
Function for getting shorts setting. More...
__STATIC_INLINE void nrf_spim_int_enable (NRF_SPIM_Type *p_reg, uint32_t spim_int_mask)
Function for enabling specified interrupts. More...
__STATIC_INLINE void nrf_spim_int_disable (NRF_SPIM_Type *p_reg, uint32_t spim_int_mask)
Function for disabling specified interrupts. More...
__STATIC_INLINE bool nrf_spim_int_enable_check (NRF_SPIM_Type *p_reg, nrf_spim_int_mask_t spim_int)
Function for retrieving the state of a given interrupt. More...
__STATIC_INLINE void nrf_spim_enable (NRF_SPIM_Type *p_reg)
Function for enabling the SPIM peripheral. More...
__STATIC_INLINE void nrf_spim_disable (NRF_SPIM_Type *p_reg)
Function for disabling the SPIM peripheral. More...
__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. More...
__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. More...
__STATIC_INLINE void nrf_spim_tx_buffer_set (NRF_SPIM_Type *p_reg, uint8_t const *p_buffer, uint8_t length)
Function for setting the transmit buffer. More...
__STATIC_INLINE void nrf_spim_rx_buffer_set (NRF_SPIM_Type *p_reg, uint8_t *p_buffer, uint8_t length)
Function for setting the receive buffer. More...
__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. More...
__STATIC_INLINE void nrf_spim_orc_set (NRF_SPIM_Type *p_reg, uint8_t orc)
Function for setting the over-read character. More...
__STATIC_INLINE void nrf_spim_tx_list_enable (NRF_SPIM_Type *p_reg)
Function for enabling the TX list feature. More...
__STATIC_INLINE void nrf_spim_tx_list_disable (NRF_SPIM_Type *p_reg)
Function for disabling the TX list feature. More...
__STATIC_INLINE void nrf_spim_rx_list_enable (NRF_SPIM_Type *p_reg)
Function for enabling the RX list feature. More...
__STATIC_INLINE void nrf_spim_rx_list_disable (NRF_SPIM_Type *p_reg)
Function for disabling the RX list feature. More...

Detailed Description

Hardware access layer for accessing the SPIM peripheral.

Enumeration Type Documentation

SPI bit orders.

Enumerator
NRF_SPIM_BIT_ORDER_MSB_FIRST

Most significant bit shifted out first.

NRF_SPIM_BIT_ORDER_LSB_FIRST

Least significant bit shifted out first.

SPIM events.

Enumerator
NRF_SPIM_EVENT_STOPPED

SPI transaction has stopped.

NRF_SPIM_EVENT_ENDRX

End of RXD buffer reached.

NRF_SPIM_EVENT_END

End of RXD buffer and TXD buffer reached.

NRF_SPIM_EVENT_ENDTX

End of TXD buffer reached.

NRF_SPIM_EVENT_STARTED

Transaction started.

SPI master data rates.

Enumerator
NRF_SPIM_FREQ_125K

125 kbps.

NRF_SPIM_FREQ_250K

250 kbps.

NRF_SPIM_FREQ_500K

500 kbps.

NRF_SPIM_FREQ_1M

1 Mbps.

NRF_SPIM_FREQ_2M

2 Mbps.

NRF_SPIM_FREQ_4M

4 Mbps.

NRF_SPIM_FREQ_8M

8 Mbps.

SPIM interrupts.

Enumerator
NRF_SPIM_INT_STOPPED_MASK

Interrupt on STOPPED event.

NRF_SPIM_INT_ENDRX_MASK

Interrupt on ENDRX event.

NRF_SPIM_INT_END_MASK

Interrupt on END event.

NRF_SPIM_INT_ENDTX_MASK

Interrupt on ENDTX event.

NRF_SPIM_INT_STARTED_MASK

Interrupt on STARTED event.

SPI modes.

Enumerator
NRF_SPIM_MODE_0

SCK active high, sample on leading edge of clock.

NRF_SPIM_MODE_1

SCK active high, sample on trailing edge of clock.

NRF_SPIM_MODE_2

SCK active low, sample on leading edge of clock.

NRF_SPIM_MODE_3

SCK active low, sample on trailing edge of clock.

SPIM shortcuts.

Enumerator
NRF_SPIM_SHORT_END_START_MASK

Shortcut between END event and START task.

SPIM tasks.

Enumerator
NRF_SPIM_TASK_START

Start SPI transaction.

NRF_SPIM_TASK_STOP

Stop SPI transaction.

NRF_SPIM_TASK_SUSPEND

Suspend SPI transaction.

NRF_SPIM_TASK_RESUME

Resume SPI transaction.

Function Documentation

__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
[in] p_reg Pointer to the peripheral registers structure.
[in] spi_mode SPI mode.
[in] spi_bit_order SPI bit order.
__STATIC_INLINE void nrf_spim_disable ( NRF_SPIM_Type * p_reg )

Function for disabling the SPIM peripheral.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
__STATIC_INLINE void nrf_spim_enable ( NRF_SPIM_Type * p_reg )

Function for enabling the SPIM peripheral.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
__STATIC_INLINE uint32_t nrf_spim_event_address_get ( NRF_SPIM_Type * p_reg ,
nrf_spim_event_t spim_event
)

Function for getting the address of a specific SPIM event register.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_event Requested event.
Returns
Address of the specified event register.
__STATIC_INLINE bool nrf_spim_event_check ( NRF_SPIM_Type * p_reg ,
nrf_spim_event_t spim_event
)

Function for checking the state of a specific SPIM event.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_event Event to check.
Return values
true If the event is set.
false If the event is not set.
__STATIC_INLINE void nrf_spim_event_clear ( NRF_SPIM_Type * p_reg ,
nrf_spim_event_t spim_event
)

Function for clearing a specific SPIM event.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_event Event to clear.
__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
[in] p_reg Pointer to the peripheral registers structure.
[in] frequency SPI frequency.
__STATIC_INLINE void nrf_spim_int_disable ( NRF_SPIM_Type * p_reg ,
uint32_t spim_int_mask
)

Function for disabling specified interrupts.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_int_mask Interrupts to disable.
__STATIC_INLINE void nrf_spim_int_enable ( NRF_SPIM_Type * p_reg ,
uint32_t spim_int_mask
)

Function for enabling specified interrupts.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_int_mask Interrupts to enable.
__STATIC_INLINE bool nrf_spim_int_enable_check ( NRF_SPIM_Type * p_reg ,
nrf_spim_int_mask_t spim_int
)

Function for retrieving the state of a given interrupt.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_int Interrupt to check.
Return values
true If the interrupt is enabled.
false If the interrupt is not enabled.
__STATIC_INLINE void nrf_spim_orc_set ( NRF_SPIM_Type * p_reg ,
uint8_t orc
)

Function for setting the over-read character.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] orc Over-read character that is clocked out in case of an over-read of the TXD buffer.
__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
[in] p_reg Pointer to the peripheral registers structure.
[in] sck_pin SCK pin number.
[in] mosi_pin MOSI pin number.
[in] miso_pin MISO pin number.
__STATIC_INLINE void nrf_spim_rx_buffer_set ( NRF_SPIM_Type * p_reg ,
uint8_t * p_buffer ,
uint8_t length
)

Function for setting the receive buffer.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] p_buffer Pointer to the buffer for received data.
[in] length Maximum number of data bytes to receive.
__STATIC_INLINE void nrf_spim_rx_list_disable ( NRF_SPIM_Type * p_reg )

Function for disabling the RX list feature.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
__STATIC_INLINE void nrf_spim_rx_list_enable ( NRF_SPIM_Type * p_reg )

Function for enabling the RX list feature.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
__STATIC_INLINE void nrf_spim_shorts_disable ( NRF_SPIM_Type * p_reg ,
uint32_t spim_shorts_mask
)

Function for disabling specified shortcuts.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_shorts_mask Shortcuts to disable.
__STATIC_INLINE void nrf_spim_shorts_enable ( NRF_SPIM_Type * p_reg ,
uint32_t spim_shorts_mask
)

Function for enabling specified shortcuts.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_shorts_mask Shortcuts to enable.
__STATIC_INLINE uint32_t nrf_spim_shorts_get ( NRF_SPIM_Type * p_reg )

Function for getting shorts setting.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
__STATIC_INLINE uint32_t nrf_spim_task_address_get ( NRF_SPIM_Type * p_reg ,
nrf_spim_task_t spim_task
)

Function for getting the address of a specific SPIM task register.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_task Requested task.
Returns
Address of the specified task register.
__STATIC_INLINE void nrf_spim_task_trigger ( NRF_SPIM_Type * p_reg ,
nrf_spim_task_t spim_task
)

Function for activating a specific SPIM task.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] spim_task Task to activate.
__STATIC_INLINE void nrf_spim_tx_buffer_set ( NRF_SPIM_Type * p_reg ,
uint8_t const * p_buffer ,
uint8_t length
)

Function for setting the transmit buffer.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
[in] p_buffer Pointer to the buffer with data to send.
[in] length Maximum number of data bytes to transmit.
__STATIC_INLINE void nrf_spim_tx_list_disable ( NRF_SPIM_Type * p_reg )

Function for disabling the TX list feature.

Parameters
[in] p_reg Pointer to the peripheral registers structure.
__STATIC_INLINE void nrf_spim_tx_list_enable ( NRF_SPIM_Type * p_reg )

Function for enabling the TX list feature.

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