Microchip® Advanced Software Framework

Quickstart guide for SAM SPI driver

This is the quick start guide for the SAM QSPI driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

This is the quickstart guide for the SAM SPI driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g.the main application function.

Basic use case of the QSPI driver

In this basic use case, the SPI module are configured for:

  • Master mode
  • Interrupt-based handling

Prerequisites

  1. System Clock Management (Sysclock)

Setup steps

Example code

Add to application C-file:

Workflow

  1. Initialize the SPI in master mode:
  2. Set up an SPI device:
    • void spi_master_setup_device(SPI_EXAMPLE, &SPI_DEVICE_EXAMPLE,
      SPI_MODE_0, SPI_EXAMPLE_BAUDRATE, 0);
    • Note
      The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.
  3. Enable SPI module:

This is the quick start guide for the SAM QSPI driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g.the main application function.

Basic use case of the QSPI driver

In this basic use case, the QSPI module are configured for:

  • SPI mode
  • Serial Memory Mode

Prerequisites

  1. System Clock Management (Sysclock)

Setup steps

Example code

Add to application C-file:

{
qspi_config->serial_memory = 1;
qspi_config->loopback_en = false;
qspi_config->wait_data_for_transfer = false;
qspi_config->csmode = 1;
qspi_config->bits_per_transfer = QSPI_MR_NBBITS_8_BIT;
qspi_config->min_delay_qcs = 0;
qspi_config->delay_between_ct = 0;
qspi_config->clock_polarity = 0;
qspi_config->clock_phase = 0;
qspi_config->baudrate = 1000000;
qspi_config->transfer_delay = 0x40;
qspi_config->scrambling_en = false;
qspi_config->scrambling_random_value_dis = false;
qspi_config->scrambling_user_key = 0;
}
void qspi_initialize(Qspi *qspi, struct qspi_config_t *qspi_config)
{
qspi_disable(qspi);
qspi_reset(qspi);
qspi_set_config(qspi, qspi_config);
qspi_enable(qspi);
}