nRF51 SDK: Software controlled SPI Master driver

| nRF51 SDK

- Home
- Related Pages
- API Reference
- Data Structures

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

Software controlled SPI Master driver. More...

## Enumerations

enum | SPIFrequency_t { Freq_125Kbps = 0, Freq_250Kbps, Freq_500Kbps, Freq_1Mbps, Freq_2Mbps, Freq_4Mbps, Freq_8Mbps }
enum | SPIModuleNumber { SPI0 = 0, SPI1 }
enum | SPIMode { SPI_MODE0 = 0, SPI_MODE1, SPI_MODE2, SPI_MODE3 }

## Functions

uint32_t * | spi_master_init (SPIModuleNumber module_number, SPIMode mode, bool lsb_first)
| Function for initializing given SPI master with given configuration. More...
bool | spi_master_tx_rx (uint32_t *spi_base_address, uint16_t transfer_size, const uint8_t *tx_data, uint8_t *rx_data)
| Function for transferring/receiving data over SPI bus. More...

## Detailed Description

Software controlled SPI Master driver.

Supported features:

- Operate two SPI masters independently or in parallel.
- Transmit and Receive given size of data through SPI.
- configure each SPI module separately through SPI Module Initialization and Configuration.

## Enumeration Type Documentation

enum SPIFrequency_t

SPI master operating frequency

Enumerator
Freq_125Kbps | drive SClk with frequency 125Kbps
Freq_250Kbps | drive SClk with frequency 250Kbps
Freq_500Kbps | drive SClk with frequency 500Kbps
Freq_1Mbps | drive SClk with frequency 1Mbps
Freq_2Mbps | drive SClk with frequency 2Mbps
Freq_4Mbps | drive SClk with frequency 4Mbps
Freq_8Mbps | drive SClk with frequency 8Mbps

enum SPIMode

SPI mode

Enumerator
SPI_MODE0 | Sample data at rising edge of clock and shift serial data at falling edge
SPI_MODE1 | sample data at falling edge of clock and shift serial data at rising edge
SPI_MODE2 | sample data at falling edge of clock and shift serial data at rising edge
SPI_MODE3 | Sample data at rising edge of clock and shift serial data at falling edge

enum SPIModuleNumber

SPI master module number

Enumerator
SPI0 | SPI module 0
SPI1 | SPI module 1

## Function Documentation

uint32_t* spi_master_init | ( | SPIModuleNumber | module_number,
|  | SPIMode | mode,
|  | bool | lsb_first
| ) |  |

Function for initializing given SPI master with given configuration.

After initializing the given SPI master with given configuration, this function also test if the SPI slave is responding with the configurations by transmitting few test bytes. If the slave did not respond then error is returned and contents of the rx_data are invalid.

Parameters

  module_number | SPI master number (SPIModuleNumber) to initialize.
  mode | SPI master mode (mode 0, 1, 2 or 3 from SPIMode)
  lsb_first | true if lsb is first bit to shift in/out as serial data on MISO/MOSI pins.

Returns

Return values

  pointer | to direct physical address of the requested SPI module if init was successful
  0,if | either init failed or slave did not respond to the test transfer

bool spi_master_tx_rx | ( | uint32_t * | spi_base_address,
|  | uint16_t | transfer_size,
|  | const uint8_t * | tx_data,
|  | uint8_t * | rx_data
| ) |  |

Function for transferring/receiving data over SPI bus.

If TWI master detects even one NACK from the slave or timeout occurs, STOP condition is issued and the function returns false.

Note
  Make sure at least transfer_size number of bytes is allocated in tx_data/rx_data.

Parameters

  spi_base_address | register base address of the selected SPI master module
  transfer_size | number of bytes to transmit/receive over SPI master
  tx_data | pointer to the data that needs to be transmitted
  rx_data | pointer to the data that needs to be received

Returns

Return values

  true | if transmit/reveive of transfer_size were completed.
  false | if transmit/reveive of transfer_size were not complete and tx_data/rx_data points to invalid data.