19.8.4.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);
- Setup of the callback functionality.
configure_spi_slave_callbacks();
- Register callback function for buffer transmitted.
spi_register_callback(&spi_slave_instance, spi_slave_callback,
SPI_CALLBACK_BUFFER_RECEIVED);
- Enable callback for buffer transmitted.
spi_enable_callback(&spi_slave_instance, SPI_CALLBACK_BUFFER_RECEIVED);