Microchip® Advanced Software Framework

Quick Start Guide for Using DMA with SERCOM I2C Master

The supported board list:

  • SAMD21 Xplained Pro
  • SAMR21 Xplained Pro
  • SAML21 Xplained Pro
  • SAML22 Xplained Pro
  • SAMDA1 Xplained Pro
  • SAMC21 Xplained Pro
  • SAMHA1G16A Xplained Pro

In this use case, the I2C will used and set up as follows:

  • Master mode
  • 100KHz operation speed
  • Not operational in standby
  • 10000 packet timeout value
  • 65535 unknown bus state timeout value

Prerequisites

The device must be connected to an I2C slave.

Setup

Code

The following must be added to the user application:

  • A sample buffer to send, number of entries to send and address of slave:
    Number of times to try to send packet if it fails:
  • Globally accessible module structure:
  • Function for setting up the module:
  • Globally accessible DMA module structure:
  • Globally transfer done flag:
  • Globally accessible DMA transfer descriptor:
  • Function for transfer done callback:
  • Function for setting up the DMA resource:
  • Function for setting up the DMA transfer descriptor:
  • Add to user application main():

Workflow

  1. Configure and enable module:
    1. Create and initialize configuration structure.
    2. Change settings in the configuration.
    3. Initialize the module with the set configurations.
    4. Enable the module.
  2. Configure DMA
    1. Create a DMA resource configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
    2. Initialize the DMA resource configuration struct with the module's default values.
      Note
      This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. Set extra configurations for the DMA resource. It is using peripheral trigger. SERCOM TX trigger causes a transaction transfer in this example.
    4. Allocate a DMA resource with the configurations.
    5. Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
    6. Initialize the DMA transfer descriptor configuration struct with the module's default values.
      Note
      This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    7. Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
    8. Create the DMA transfer descriptor.

Implementation

Code

Add to user application main():

Workflow

  1. Start the DMA transfer job.
  2. Set the auto address length and enable flag.
  3. Waiting for transfer complete.
  4. Enter an infinite loop once transfer complete.