nRF51 SDK
|
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... | |
Software controlled SPI Master driver.
Supported features:
enum SPIFrequency_t |
SPI master operating frequency
enum SPIMode |
SPI mode
enum SPIModuleNumber |
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.
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. |
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.
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 |
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. |