19.8.2.1.3 Workflow
- Initialize system.
system_init();
- Set-up the SPI.
configure_spi_slave();
- Create configuration struct.
struct
spi_config config_spi_slave;
- Get default configuration to edit.
spi_get_config_defaults(&config_spi_slave);
- Set the SPI in slave mode.
config_spi_slave.mode = SPI_MODE_SLAVE;
- Enable preloading of shift register.
config_spi_slave.mode_specific.slave.preload_enable =
true
;
- Set frame format to SPI frame.
config_spi_slave.mode_specific.slave.frame_format = SPI_FRAME_FORMAT_SPI_FRAME;
- Set MUX setting E.
config_spi_slave.mux_setting = EXT1_SPI_SERCOM_MUX_SETTING;
- Set pinmux for pad 0 (data in MOSI).
config_spi_slave.pinmux_pad0 = EXT1_SPI_SERCOM_PINMUX_PAD0;
- Set pinmux for pad 1 (slave select).
config_spi_slave.pinmux_pad1 = EXT1_SPI_SERCOM_PINMUX_PAD1;
- Set pinmux for pad 2 (data out MISO).
config_spi_slave.pinmux_pad2 = EXT1_SPI_SERCOM_PINMUX_PAD2;
- Set pinmux for pad 3 (SCK).
config_spi_slave.pinmux_pad3 = EXT1_SPI_SERCOM_PINMUX_PAD3;
- Initialize SPI module with configuration.
spi_init(&spi_slave_instance, EXT1_SPI_MODULE, &config_spi_slave);
- Enable SPI module.
spi_enable(&spi_slave_instance);