nRF51 SDK: Software controlled SPI Slave driver.

| nRF51 SDK

- Home
- Related Pages
- API Reference
- Data Structures

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Typedefs | Enumerations | Functions
Software controlled SPI Slave driver.
Peripheral Drivers

Software controlled SPI Slave driver. More...

## Data Structures

struct | spi_slave_config_t
| SPI peripheral device configuration data. More...
struct | spi_slave_evt_t
| Struct containing event context from the SPI slave driver. More...

## Typedefs

typedef void(* | spi_slave_event_handler_t )(spi_slave_evt_t event)
| SPI slave event callback function type. More...

## Enumerations

enum | spi_slave_endian_t { SPIM_LSB_FIRST, SPIM_MSB_FIRST }
| SPI transaction bit order definitions. More...
enum | spi_slave_mode_t { SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3 }
| SPI mode definitions for clock polarity and phase. More...
enum | spi_slave_evt_type_t { SPI_SLAVE_BUFFERS_SET_DONE, SPI_SLAVE_XFER_DONE, SPI_SLAVE_EVT_TYPE_MAX }
| Event callback function event definitions. More...

## Functions

uint32_t | spi_slave_evt_handler_register (spi_slave_event_handler_t event_handler)
| Function for registering a handler for SPI slave driver event. More...
uint32_t | spi_slave_init (const spi_slave_config_t *p_spi_slave_config)
| Function for initializing the SPI slave device. More...
uint32_t | spi_slave_buffers_set (uint8_t *p_tx_buf, uint8_t *p_rx_buf, uint8_t tx_buf_length, uint8_t rx_buf_length)
| Function for preparing the SPI slave device ready for a single SPI transaction. More...

## Detailed Description

Software controlled SPI Slave driver.

## Typedef Documentation

typedef void(* spi_slave_event_handler_t)(spi_slave_evt_t event)

SPI slave event callback function type.

Parameters

  [in] | event | SPI slave driver event.

## Enumeration Type Documentation

enum spi_slave_endian_t

SPI transaction bit order definitions.

Enumerator
SPIM_LSB_FIRST | Least significant bit shifted out first.
SPIM_MSB_FIRST | Most significant bit shifted out first.

enum spi_slave_evt_type_t

Event callback function event definitions.

Enumerator
SPI_SLAVE_BUFFERS_SET_DONE | Memory buffer set event. Memory buffers have been set successfully to the SPI slave device and SPI transactions can be done.
SPI_SLAVE_XFER_DONE | SPI transaction event. SPI transaction has been completed.
SPI_SLAVE_EVT_TYPE_MAX | Enumeration upper bound.

enum spi_slave_mode_t

SPI mode definitions for clock polarity and phase.

Enumerator
SPI_MODE_0 | (CPOL = 0, CPHA = 0).
SPI_MODE_1 | (CPOL = 0, CPHA = 1).
SPI_MODE_2 | (CPOL = 1, CPHA = 0).
SPI_MODE_3 | (CPOL = 1, CPHA = 1).

## Function Documentation

uint32_t spi_slave_buffers_set | ( | uint8_t * | p_tx_buf,
|  | uint8_t * | p_rx_buf,
|  | uint8_t | tx_buf_length,
|  | uint8_t | rx_buf_length
| ) |  |

Function for preparing the SPI slave device ready for a single SPI transaction.

Function prepares the SPI slave device to be ready for a single SPI transaction. It configures the SPI slave device to use the memory, supplied with the function call, in SPI transactions.

The spi_slave_event_handler_t will be called with appropriate event spi_slave_evt_type_t when either the memory buffer configuration or SPI transaction has been completed.

Note
  The callback function spi_slave_event_handler_t can be called before returning from this function, since it is called from the SPI slave interrupt context.
  This function can be called from the callback function spi_slave_event_handler_t context.
  Client application must call this function after every SPI_SLAVE_XFER_DONE event if it wants the SPI slave driver to be ready for possible new SPI transaction.

Parameters

  [in] | p_tx_buf | Pointer to the TX buffer.
  [in] | p_rx_buf | Pointer to the RX buffer.
  [in] | tx_buf_length | Length of the TX buffer in bytes.
  [in] | rx_buf_length | Length of the RX buffer in bytes.

Return values

  NRF_SUCCESS | Operation success.
  NRF_ERROR_NULL | Operation failure. NULL pointer supplied.
  NRF_ERROR_INVALID_STATE | Operation failure. SPI slave device in incorrect state.
  NRF_ERROR_INTERNAL | Operation failure. Internal error ocurred.

uint32_t spi_slave_evt_handler_register | ( | spi_slave_event_handler_t | event_handler | ) |

Function for registering a handler for SPI slave driver event.

Note
  Multiple registration requests will overwrite any possible existing registration.

Parameters

  [in] | event_handler | The function to be called by the SPI slave driver upon event.

Return values

  NRF_SUCCESS | Operation success.
  NRF_ERROR_NULL | Operation success. NULL handler registered.

uint32_t spi_slave_init | ( | const spi_slave_config_t * | p_spi_slave_config | ) |

Function for initializing the SPI slave device.

Parameters

  [in] | p_spi_slave_config | SPI peripheral device configuration data.

Return values

  NRF_SUCCESS | Operation success.
  NRF_ERROR_NULL | Operation failure. NULL pointer supplied.
  NRF_ERROR_INVALID_PARAM | Operation failure. Invalid parameter supplied.