nRF51 SDK - S130 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
SPI Master driver

SPI master driver. More...

Data Structures

struct  spi_master_config_t
 Struct containing configuration parameters of the SPI master. More...
 
struct  spi_master_evt_t
 Struct containing parameters of the SPI MASTER event. More...
 

Macros

#define SPI_PIN_DISCONNECTED   0xFFFFFFFF
 
#define SPI_DEFAULT_TX_BYTE   0x00
 
#define SPI_MASTER_INIT_DEFAULT
 Macro for initializing SPI master by default values. More...
 

Typedefs

typedef enum spi_master_evt_type_t spi_master_evt_type_t
 SPI master driver events types.
 
typedef void(* spi_master_event_handler_t )(spi_master_evt_t spi_master_evt)
 Type of generic callback function handler to be used by all SPI MASTER driver events. More...
 

Enumerations

enum  spi_master_evt_type_t {
  SPI_MASTER_EVT_TRANSFER_STARTED = 0,
  SPI_MASTER_EVT_TRANSFER_COMPLETED,
  SPI_MASTER_EVT_TRANSFER_ABORTED,
  SPI_MASTER_EVT_TRANSFER_RESTARTED,
  SPI_MASTER_EVT_FIRST_BYTE_RECEIVED,
  SPI_MASTER_EVT_TYPE_MAX,
  SPI_MASTER_EVT_TRANSFER_STARTED = 0,
  SPI_MASTER_EVT_TRANSFER_COMPLETED,
  SPI_MASTER_EVT_TYPE_MAX,
  SPI_MASTER_EVT_TRANSFER_STARTED = 0,
  SPI_MASTER_EVT_TRANSFER_COMPLETED,
  SPI_MASTER_EVT_TRANSFER_ABORTED,
  SPI_MASTER_EVT_TRANSFER_RESTARTED,
  SPI_MASTER_EVT_FIRST_BYTE_RECEIVED,
  SPI_MASTER_EVT_TYPE_MAX
}
 SPI master driver events types. More...
 
enum  spi_master_state_t {
  SPI_MASTER_STATE_DISABLED,
  SPI_MASTER_STATE_BUSY,
  SPI_MASTER_STATE_ABORTED,
  SPI_MASTER_STATE_IDLE,
  SPI_MASTER_STATE_DISABLED,
  SPI_MASTER_STATE_BUSY,
  SPI_MASTER_STATE_IDLE,
  SPI_MASTER_STATE_DISABLED,
  SPI_MASTER_STATE_BUSY,
  SPI_MASTER_STATE_ABORTED,
  SPI_MASTER_STATE_IDLE
}
 Types of the SPI master internal states. More...
 
enum  spi_master_hw_instance_t {
  SPI_MASTER_0,
  SPI_MASTER_1,
  SPI_MASTER_HW_ENABLED_COUNT,
  SPI_MASTER_0,
  SPI_MASTER_1,
  SPI_MASTER_HW_ENABLED_COUNT,
  SPI_MASTER_0,
  SPI_MASTER_1,
  SPI_MASTER_HW_ENABLED_COUNT
}
 Enum containing instances of the SPI master driver. More...
 

Functions

uint32_t spi_master_open (const spi_master_hw_instance_t spi_master_hw_instance, spi_master_config_t const *const p_spi_master_config)
 Function for opening and initializing a SPI master driver. More...
 
void spi_master_close (const spi_master_hw_instance_t spi_master_hw_instance)
 Function for closing a SPI MASTER driver. More...
 
uint32_t spi_master_send_recv (const spi_master_hw_instance_t spi_master_hw_instance, uint8_t *const p_tx_buf, const uint16_t tx_buf_len, uint8_t *const p_rx_buf, const uint16_t rx_buf_len)
 Function for transferring data between SPI master and SPI slave. More...
 
void spi_master_evt_handler_reg (const spi_master_hw_instance_t spi_master_hw_instance, spi_master_event_handler_t event_handler)
 Function for registration event handler. More...
 
spi_master_state_t spi_master_get_state (const spi_master_hw_instance_t spi_master_hw_instance)
 Function for getting current state of the SPI master driver. More...
 

Detailed Description

SPI master driver.

This file contains declarations of functions and typedefs used as API of the SPI master driver.

Macro Definition Documentation

#define SPI_DEFAULT_TX_BYTE   0x00

Default byte (used to clock transmission from slave to the master)

#define SPI_MASTER_INIT_DEFAULT
Value:
{ \
SPI_FREQUENCY_FREQUENCY_M1, /**< Serial clock frequency 1 Mbps. */ \
SPI_PIN_DISCONNECTED, /**< SCK pin DISCONNECTED. */ \
SPI_PIN_DISCONNECTED, /**< MISO pin DISCONNECTED. */ \
SPI_PIN_DISCONNECTED, /**< MOSI pin DISCONNECTED. */ \
SPI_PIN_DISCONNECTED, /**< Slave select pin DISCONNECTED. */ \
APP_IRQ_PRIORITY_LOW, /**< Interrupt priority LOW. */ \
SPI_CONFIG_ORDER_LsbFirst, /**< Bits order LSB. */ \
SPI_CONFIG_CPOL_ActiveHigh, /**< Serial clock polarity ACTIVEHIGH. */ \
SPI_CONFIG_CPHA_Leading, /**< Serial clock phase LEADING. */ \
0 /**< Don't disable all IRQs. */ \
};

Macro for initializing SPI master by default values.

#define SPI_PIN_DISCONNECTED   0xFFFFFFFF

A value used to the PIN deinitialization.

Typedef Documentation

typedef void(* spi_master_event_handler_t)(spi_master_evt_t spi_master_evt)

Type of generic callback function handler to be used by all SPI MASTER driver events.

Parameters
[in]spi_master_evtSPI MASTER driver event.

Enumeration Type Documentation

enum spi_master_evt_type_t

SPI master driver events types.

Enumerator
SPI_MASTER_EVT_TRANSFER_STARTED 

An event indicating that transfer has been started

SPI_MASTER_EVT_TRANSFER_COMPLETED 

An event indicating that transfer has been completed

SPI_MASTER_EVT_TRANSFER_ABORTED 

An event indicating that transfer has been aborted

SPI_MASTER_EVT_TRANSFER_RESTARTED 

An event indicating that transfer has been resumed

SPI_MASTER_EVT_FIRST_BYTE_RECEIVED 

An event indicating end of one byte transfer

SPI_MASTER_EVT_TYPE_MAX 

Enumeration upper bound.

SPI_MASTER_EVT_TRANSFER_STARTED 

An event indicating that transfer has been started.

SPI_MASTER_EVT_TRANSFER_COMPLETED 

An event indicating that transfer has been completed.

SPI_MASTER_EVT_TYPE_MAX 

Enumeration upper bound.

SPI_MASTER_EVT_TRANSFER_STARTED 

An event indicating that transfer has been started

SPI_MASTER_EVT_TRANSFER_COMPLETED 

An event indicating that transfer has been completed

SPI_MASTER_EVT_TRANSFER_ABORTED 

An event indicating that transfer has been aborted

SPI_MASTER_EVT_TRANSFER_RESTARTED 

An event indicating that transfer has been resumed

SPI_MASTER_EVT_FIRST_BYTE_RECEIVED 

An event indicating end of one byte transfer

SPI_MASTER_EVT_TYPE_MAX 

Enumeration upper bound.

enum spi_master_hw_instance_t

Enum containing instances of the SPI master driver.

Enumerator
SPI_MASTER_0 

A instance of SPI master 0.

SPI_MASTER_1 

A instance of SPI master 1.

SPI_MASTER_HW_ENABLED_COUNT 

A number of enabled instances of SPI master.

SPI_MASTER_0 

A instance of NRF_SPI0.

SPI_MASTER_1 

A instance of NRF_SPI1.

SPI_MASTER_HW_ENABLED_COUNT 

A number of enabled instances of the SPI master.

SPI_MASTER_0 

A instance of SPI master 0.

SPI_MASTER_1 

A instance of SPI master 1.

SPI_MASTER_HW_ENABLED_COUNT 

A number of enabled instances of SPI master.

enum spi_master_state_t

Types of the SPI master internal states.

Enumerator
SPI_MASTER_STATE_DISABLED 

A state indicating that SPI master is disabled.

SPI_MASTER_STATE_BUSY 

A state indicating that SPI master is sending now.

SPI_MASTER_STATE_IDLE 

A state indicating that SPI master is idle now.

SPI_MASTER_STATE_DISABLED 

A state indicating that SPI master is disabled.

SPI_MASTER_STATE_BUSY 

A state indicating that SPI master is sending now.

SPI_MASTER_STATE_IDLE 

A state indicating that SPI master is idle now.

SPI_MASTER_STATE_DISABLED 

A state indicating that SPI master is disabled.

SPI_MASTER_STATE_BUSY 

A state indicating that SPI master is sending now.

SPI_MASTER_STATE_IDLE 

A state indicating that SPI master is idle now.

Function Documentation

void spi_master_close ( const spi_master_hw_instance_t  spi_master_hw_instance)

Function for closing a SPI MASTER driver.

Note
Function disable hardware, reset internal module states and unregister events callback function.
Parameters
[in]spi_master_hw_instanceA instance of SPI master.
void spi_master_evt_handler_reg ( const spi_master_hw_instance_t  spi_master_hw_instance,
spi_master_event_handler_t  event_handler 
)

Function for registration event handler.

Note
Function registers a event handler to be used by SPI MASTER driver for sending events. SPI_MASTER_EVT_TRANSFER_STARTED and SPI_MASTER_EVT_TRANSFER_COMPLETED.
Parameters
[in]spi_master_hw_instanceInstance of SPI master module.
[in]event_handlerGeneric callback function handler to be used by all SPI master driver events.
spi_master_state_t spi_master_get_state ( const spi_master_hw_instance_t  spi_master_hw_instance)

Function for getting current state of the SPI master driver.

Note
Function gets current state of the SPI master driver.
Parameters
[in]spi_master_hw_instanceInstance of SPI master module.
Return values
SPI_MASTER_STATE_DISABLEDSPI MASTER is disabled.
SPI_MASTER_STATE_BUSYSPI_MASTER is sending now.
SPI_MASTER_STATE_IDLESPI_MASTER is idle now.
uint32_t spi_master_open ( const spi_master_hw_instance_t  spi_master_hw_instance,
spi_master_config_t const *const  p_spi_master_config 
)

Function for opening and initializing a SPI master driver.

Note
Function initializes SPI master hardware and internal module states, unregister events callback.
Warning
If the function has been already called, the function spi_master_close has to be called before spi_master_open can be called again.
Parameters
[in]spi_master_hw_instanceInstance of SPI master module.
[in]p_spi_master_configPointer to configuration structure which will be used to initialize SPI MASTER hardware.
Return values
NRF_SUCCESSOperation success.
NRF_ERROR_INVALID_STATEOperation failure. The function has been already called. To call it again the function spi_master_close has to be called previously.
NRF_ERROR_NULLOperation failure. NULL pointer supplied.
uint32_t spi_master_send_recv ( const spi_master_hw_instance_t  spi_master_hw_instance,
uint8_t *const  p_tx_buf,
const uint16_t  tx_buf_len,
uint8_t *const  p_rx_buf,
const uint16_t  rx_buf_len 
)

Function for transferring data between SPI master and SPI slave.

Note
Function registers buffers pointed by p_tx_buf and p_rx_buf parameters, after that starts transmission. Function generates an event of type SPI_MASTER_EVT_TRANSFER_STARTED when transfer has been started and SPI_MASTER_EVT_TRANSFER_COMPLETED when transfer has been completed.
Parameters
[in]spi_master_hw_instanceInstance of SPI master module.
[in]p_tx_bufPointer to a transmit buffer.
[in]tx_buf_lenNumber of octets to the transfer.
[out]p_rx_bufPointer to a receive buffer.
[in]rx_buf_lenNumber of octets to be received.
Return values
NRF_SUCCESSOperation success. Packet was registered to the transmission and event will be send upon transmission completion.
NRF_ERROR_BUSYOperation failure. Transmitting of a data is in progress.