19.8.1.2 Workflow

  1. Initialize system.
    system_init();
    
  2. Set-up the SPI.
    configure_spi_master();
    
    1. Create configuration struct.
      struct spi_config config_spi_master;
      
    2. Create peripheral slave configuration struct.
      struct spi_slave_inst_config slave_dev_config;
      
    3. Create peripheral slave software device instance struct.
      struct spi_slave_inst slave;
      
    4. Get default peripheral slave configuration.
      spi_slave_inst_get_config_defaults(&slave_dev_config);
      
    5. Set Slave Select pin.
      slave_dev_config.ss_pin = SLAVE_SELECT_PIN;
      
    6. Initialize peripheral slave software instance with configuration.
      spi_attach_slave(&slave, &slave_dev_config);
      
    7. Get default configuration to edit.
      spi_get_config_defaults(&config_spi_master);
      
    8. Set MUX setting E.
      config_spi_master.mux_setting = EXT1_SPI_SERCOM_MUX_SETTING;
      
    9. Set pinmux for pad 0 (data in (MISO)).
      config_spi_master.pinmux_pad0 = EXT1_SPI_SERCOM_PINMUX_PAD0;
      
    10. Set pinmux for pad 1 as unused, so the pin can be used for other purposes.
      config_spi_master.pinmux_pad1 = PINMUX_UNUSED;
      
    11. Set pinmux for pad 2 (data out (MOSI)).
      config_spi_master.pinmux_pad2 = EXT1_SPI_SERCOM_PINMUX_PAD2;
      
    12. Set pinmux for pad 3 (SCK).
      config_spi_master.pinmux_pad3 = EXT1_SPI_SERCOM_PINMUX_PAD3;
      
    13. Initialize SPI module with configuration.
      spi_init(&spi_master_instance, EXT1_SPI_MODULE, &config_spi_master);
      
    14. Enable SPI module.
      spi_enable(&spi_master_instance);