nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Software controlled SPI Master driver

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

Supported features:

Enumeration Type Documentation

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

SPI master module number

Enumerator
SPI0 

SPI module 0

SPI1 

SPI module 1

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

Function Documentation

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

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_numberSPI master number (SPIModuleNumber) to initialize.
modeSPI master mode (mode 0, 1, 2 or 3 from SPIMode)
lsb_firsttrue if lsb is first bit to shift in/out as serial data on MISO/MOSI pins.
Returns
Return values
pointerto direct physical address of the requested SPI module if init was successful
0,ifeither 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 
)

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_addressregister base address of the selected SPI master module
transfer_sizenumber of bytes to transmit/receive over SPI master
tx_datapointer to the data that needs to be transmitted
rx_datapointer to the data that needs to be received
Returns
Return values
trueif transmit/reveive of transfer_size were completed.
falseif transmit/reveive of transfer_size were not complete and tx_data/rx_data points to invalid data.