19.8.4.1.3 Workflow

  1. Initialize system.
    system_init();
    
  2. Set-up the SPI.
    configure_spi_slave();
    
    1. Create configuration struct.
      struct spi_config config_spi_slave;
      
    2. Get default configuration to edit.
      spi_get_config_defaults(&config_spi_slave);
      
    3. Set the SPI in slave mode.
      config_spi_slave.mode = SPI_MODE_SLAVE;
      
    4. Enable preloading of shift register.
      config_spi_slave.mode_specific.slave.preload_enable = true;
      
    5. Set frame format to SPI frame.
      config_spi_slave.mode_specific.slave.frame_format = SPI_FRAME_FORMAT_SPI_FRAME;
      
    6. Set MUX setting E.
      config_spi_slave.mux_setting = EXT1_SPI_SERCOM_MUX_SETTING;
      
    7. Set pinmux for pad 0 (data in MOSI).
      config_spi_slave.pinmux_pad0 = EXT1_SPI_SERCOM_PINMUX_PAD0;
      
    8. Set pinmux for pad 1 (slave select).
      config_spi_slave.pinmux_pad1 = EXT1_SPI_SERCOM_PINMUX_PAD1;
      
    9. Set pinmux for pad 2 (data out MISO).
      config_spi_slave.pinmux_pad2 = EXT1_SPI_SERCOM_PINMUX_PAD2;
      
    10. Set pinmux for pad 3 (SCK).
      config_spi_slave.pinmux_pad3 = EXT1_SPI_SERCOM_PINMUX_PAD3;
      
    11. Initialize SPI module with configuration.
      spi_init(&spi_slave_instance, EXT1_SPI_MODULE, &config_spi_slave);
      
    12. Enable SPI module.
      spi_enable(&spi_slave_instance);
      
  3. Setup of the callback functionality.
    configure_spi_slave_callbacks();
    
    1. Register callback function for buffer transmitted.
      spi_register_callback(&spi_slave_instance, spi_slave_callback,
              SPI_CALLBACK_BUFFER_RECEIVED);
      
    2. Enable callback for buffer transmitted.
      spi_enable_callback(&spi_slave_instance, SPI_CALLBACK_BUFFER_RECEIVED);