19.8.1.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;
- Create peripheral slave software device instance struct.
struct
spi_slave_inst slave;
- 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);