nRF51 SDK v10.0.0
Data Structures | Macros | Typedefs | Enumerations | Functions
SPI master driver

Multi-instance SPI master driver. More...

Data Structures

struct  nrf_drv_spi_t
 SPI master driver instance data structure. More...
 
struct  nrf_drv_spi_config_t
 SPI master driver instance configuration structure. More...
 

Macros

#define NRF_DRV_SPI_INSTANCE(id)
 Macro for creating an SPI master driver instance. More...
 
#define NRF_DRV_SPI_PIN_NOT_USED   0xFF
 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.
 
#define NRF_DRV_SPI_DEFAULT_CONFIG(id)
 SPI master instance default configuration. More...
 

Typedefs

typedef void(* nrf_drv_spi_handler_t )(nrf_drv_spi_event_t event)
 SPI master driver event handler type.
 

Enumerations

enum  nrf_drv_spi_frequency_t {
  NRF_DRV_SPI_FREQ_125K = NRF_SPI_FREQ_125K,
  NRF_DRV_SPI_FREQ_250K = NRF_SPI_FREQ_250K,
  NRF_DRV_SPI_FREQ_500K = NRF_SPI_FREQ_500K,
  NRF_DRV_SPI_FREQ_1M = NRF_SPI_FREQ_1M,
  NRF_DRV_SPI_FREQ_2M = NRF_SPI_FREQ_2M,
  NRF_DRV_SPI_FREQ_4M = NRF_SPI_FREQ_4M,
  NRF_DRV_SPI_FREQ_8M = NRF_SPI_FREQ_8M
}
 SPI data rates. More...
 
enum  nrf_drv_spi_mode_t {
  NRF_DRV_SPI_MODE_0 = NRF_SPI_MODE_0,
  NRF_DRV_SPI_MODE_1 = NRF_SPI_MODE_1,
  NRF_DRV_SPI_MODE_2 = NRF_SPI_MODE_2,
  NRF_DRV_SPI_MODE_3 = NRF_SPI_MODE_3
}
 SPI modes. More...
 
enum  nrf_drv_spi_bit_order_t {
  NRF_DRV_SPI_BIT_ORDER_MSB_FIRST = NRF_SPI_BIT_ORDER_MSB_FIRST,
  NRF_DRV_SPI_BIT_ORDER_LSB_FIRST = NRF_SPI_BIT_ORDER_LSB_FIRST
}
 SPI bit orders. More...
 
enum  nrf_drv_spi_event_t { NRF_DRV_SPI_EVENT_DONE }
 SPI master driver events, passed to the handler routine provided during initialization. More...
 

Functions

ret_code_t nrf_drv_spi_init (nrf_drv_spi_t const *const p_instance, nrf_drv_spi_config_t const *p_config, nrf_drv_spi_handler_t handler)
 Function for initializing the SPI master driver instance. More...
 
void nrf_drv_spi_uninit (nrf_drv_spi_t const *const p_instance)
 Function for uninitializing the SPI master driver instance. More...
 
ret_code_t nrf_drv_spi_transfer (nrf_drv_spi_t const *const p_instance, uint8_t const *p_tx_buffer, uint8_t tx_buffer_length, uint8_t *p_rx_buffer, uint8_t rx_buffer_length)
 Function for starting the SPI data transfer. More...
 

Detailed Description

Multi-instance SPI master driver.

Macro Definition Documentation

#define NRF_DRV_SPI_DEFAULT_CONFIG (   id)
Value:
{ \
.sck_pin = CONCAT_3(SPI, id, _CONFIG_SCK_PIN), \
.mosi_pin = CONCAT_3(SPI, id, _CONFIG_MOSI_PIN), \
.miso_pin = CONCAT_3(SPI, id, _CONFIG_MISO_PIN), \
.irq_priority = CONCAT_3(SPI, id, _CONFIG_IRQ_PRIORITY), \
.orc = 0xFF, \
.frequency = NRF_DRV_SPI_FREQ_4M, \
.mode = NRF_DRV_SPI_MODE_0, \
}

SPI master instance default configuration.

#define NRF_DRV_SPI_INSTANCE (   id)
Value:
{ \
.p_registers = NRF_DRV_SPI_PERIPHERAL(id), \
.irq = CONCAT_3(SPI, id, _IRQ), \
.drv_inst_idx = CONCAT_3(SPI, id, _INSTANCE_INDEX), \
.use_easy_dma = CONCAT_3(SPI, id, _USE_EASY_DMA) \
}

Macro for creating an SPI master driver instance.

Enumeration Type Documentation

SPI bit orders.

Enumerator
NRF_DRV_SPI_BIT_ORDER_MSB_FIRST 

Most significant bit shifted out first.

NRF_DRV_SPI_BIT_ORDER_LSB_FIRST 

Least significant bit shifted out first.

SPI master driver events, passed to the handler routine provided during initialization.

Enumerator
NRF_DRV_SPI_EVENT_DONE 

Transfer done.

SPI data rates.

Enumerator
NRF_DRV_SPI_FREQ_125K 

125 kbps.

NRF_DRV_SPI_FREQ_250K 

250 kbps.

NRF_DRV_SPI_FREQ_500K 

500 kbps.

NRF_DRV_SPI_FREQ_1M 

1 Mbps.

NRF_DRV_SPI_FREQ_2M 

2 Mbps.

NRF_DRV_SPI_FREQ_4M 

4 Mbps.

NRF_DRV_SPI_FREQ_8M 

8 Mbps.

SPI modes.

Enumerator
NRF_DRV_SPI_MODE_0 

SCK active high, sample on leading edge of clock.

NRF_DRV_SPI_MODE_1 

SCK active high, sample on trailing edge of clock.

NRF_DRV_SPI_MODE_2 

SCK active low, sample on leading edge of clock.

NRF_DRV_SPI_MODE_3 

SCK active low, sample on trailing edge of clock.

Function Documentation

ret_code_t nrf_drv_spi_init ( nrf_drv_spi_t const *const  p_instance,
nrf_drv_spi_config_t const *  p_config,
nrf_drv_spi_handler_t  handler 
)

Function for initializing the SPI master driver instance.

This function configures and enables the specified peripheral.

Parameters
[in]p_instancePointer to the instance structure.
[in]p_configPointer to the structure with the initial configuration. If NULL, the default configuration is used.
handlerEvent handler provided by the user. If NULL, transfers will be performed in blocking mode.
Return values
NRF_SUCCESSIf initialization was successful.
NRF_ERROR_INVALID_STATEIf the driver was already initialized.
ret_code_t nrf_drv_spi_transfer ( nrf_drv_spi_t const *const  p_instance,
uint8_t const *  p_tx_buffer,
uint8_t  tx_buffer_length,
uint8_t *  p_rx_buffer,
uint8_t  rx_buffer_length 
)

Function for starting the SPI data transfer.

If an event handler was provided in the nrf_drv_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.

Note
Peripherals using EasyDMA (for example, SPIM) require the transfer buffers to be placed in the data RAM region. If they are not and an SPIM instance is used, this function will fail with the error code NRF_ERROR_INVALID_ADDR.
Parameters
[in]p_instancePointer to the instance structure.
[in]p_tx_bufferPointer to the transmit buffer. Can be NULL if there is nothing to send.
tx_buffer_lengthLength of the transmit buffer.
[in]p_rx_bufferPointer to the receive buffer. Can be NULL if there is nothing to receive.
rx_buffer_lengthLength of the receive buffer.
Return values
NRF_SUCCESSIf the operation was successful.
NRF_ERROR_BUSYIf a previously started transfer has not finished yet.
NRF_ERROR_INVALID_ADDRIf the provided buffers are not placed in the data RAM region.
void nrf_drv_spi_uninit ( nrf_drv_spi_t const *const  p_instance)

Function for uninitializing the SPI master driver instance.

Parameters
[in]p_instancePointer to the instance structure.

This document was last updated on Mon Nov 9 2015.
Please send us your feedback about the documentation! For technical questions, visit the Nordic Developer Zone.