Before starting to use SPI master, the appropriate module or both modules need to be enabled.
- Features supported
-
- Two SPI modules, SPI0 and SP01 are currently supported.
- The driver can used to use only one or both of the SPI modules.
- Configuration of each SPI module.
- Interface to transmit and receive data on each of the modules.
SPI Module Initialization and Configuration
The SPI modules need to be initialized and configured before they can be used for data exchange. All configuration options need to be configure in structure spi_master_config_t .
Before the configure SPI master, appropriate module (or both modules) need to be enabled by defined:
- PINs configuration (PIN numbers from 0 to 31):
- Serial clock polarity configuration
See spi_master_config_t::SPI_CONFIG_CPOL .
Supported serial clock polarities:
- Serial clock phase configuration
See spi_master_config_t::SPI_CONFIG_CPHA .
Supported serial clock phases:
- Data endian-ness configuration.
See spi_master_config_t::SPI_CONFIG_ORDER .
Supported data endian-ness:
- SPI master frequency configuration.
See spi_master_config_t::SPI_Freq .
Supported SPI master frequencies:
- Interrupt priority configuration.
See spi_master_config_t::SPI_PriorityIRQ .
If SoftDevice is enabled available interrupt priorities (values 3 and 1):
If SoftDevice isn't enabled available interrupt priorities (values from 0 to 3):
- Disable all IRQs during realization critical region inside the driver.
See spi_master_config_t::SPI_DisableAllIRQ .
- Quick start
- Create and initialize structure spi_master_config_t . Macro SPI_MASTER_INIT_DEFAULT can be used to initialize this structure by default values.
- Configure SPI master PINs.
- Invoke spi_master_open() with parameters spi_master_hw_instance_t and pointer to the spi_master_config_t . On successful initialization spi_master_open() should return NRF_SUCCESS .
- Invoke spi_master_evt_handler_reg() with parameters spi_master_hw_instance_t and the event handler name to register a event handler.
- Invoke spi_master_send_recv() with parameters spi_master_hw_instance_t and buffers to start transfer.
- Following sample snippet initializes SPI_MASTER_0 with default values.
SPI Master Data Exchange API
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.