nRF51 SDK
|
The SPI modules need to be initialized and configured before they can be used for data exchange. An SPI module can be configured to exchange data in four configurations of clock.
See enumeration SPIMode that defines these modes.
Also, the application can indicate the endian-ness of data to be transmitted serially, either LSB first or MSB first.
SPI Module frequency is configured at compile time using the define SPI_OPERATING_FREQUENCY spi_master_config.h. Supported frequencies are defined in the enumeration SPIFrequency_t. Supported frequencies include:
SDK Sample examples operate the SPI module at 250 kbps.
On successful initialization of the requested configuration for the SPI module, the physical address of the requested SPI module is provided as reference for all future data exchanges.
Following sample snippet initializes SPI0 in mode 3 with data transmission in little endian order.
Once successfully initialized, data can be exchanged serially on the module. Data transmission is synchronous and any data that the slave wants to transmit is fetched during the master transmission. The application is expected to provide a receive buffer when calling the Data Exchange API of size TX_RX_MSG_LENGTH. TX_RX_MSG_LENGTH is defined in spi_master_config.h.