Jump to main content
19.8.3.2 Workflow
Initialize system.
system_init();
Set-up the SPI.
configure_spi_master();
Create configuration struct.
struct
spi_config config_spi_master;
Create peripheral slave configuration struct.
struct
spi_slave_inst_config slave_dev_config;
Get default peripheral slave configuration.
spi_slave_inst_get_config_defaults(&slave_dev_config);
Set Slave Select pin.
slave_dev_config.ss_pin = SLAVE_SELECT_PIN;
Initialize peripheral slave software instance with configuration.
spi_attach_slave(&slave, &slave_dev_config);
Get default configuration to edit.
spi_get_config_defaults(&config_spi_master);
Set MUX setting E.
config_spi_master.mux_setting = EXT1_SPI_SERCOM_MUX_SETTING;
Set pinmux for pad 0 (data in MISO).
config_spi_master.pinmux_pad0 = EXT1_SPI_SERCOM_PINMUX_PAD0;
Set pinmux for pad 1 as unused, so the pin can be used for other purposes.
config_spi_master.pinmux_pad1 = PINMUX_UNUSED;
Set pinmux for pad 2 (data out MOSI).
config_spi_master.pinmux_pad2 = EXT1_SPI_SERCOM_PINMUX_PAD2;
Set pinmux for pad 3 (SCK).
config_spi_master.pinmux_pad3 = EXT1_SPI_SERCOM_PINMUX_PAD3;
Initialize SPI module with configuration.
spi_init(&spi_master_instance, EXT1_SPI_MODULE, &config_spi_master);
Enable SPI module.
spi_enable(&spi_master_instance);
Setup the callback functionality.
configure_spi_master_callbacks();
Register callback function for buffer transmitted.
spi_register_callback(&spi_master_instance, callback_spi_master,
SPI_CALLBACK_BUFFER_TRANSCEIVED);
Enable callback for buffer transmitted.
spi_enable_callback(&spi_master_instance, SPI_CALLBACK_BUFFER_TRANSCEIVED);
The online versions of the documents are provided as a courtesy. Verify all content and data in the device’s PDF documentation found on the device product page.