Microchip® Advanced Software Framework

Quick Start Guide for SERCOM I2C Master - Callback

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

  • Master mode
  • 100KHz operation speed
  • Not operational in standby
  • 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 write from, a reversed buffer to write from and length of buffers.

Address of slave:

Globally accessible module structure:

Globally accessible packet:

Function for setting up module:

Callback function for write complete:

Function for setting up the callback functionality of the driver:

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 callback functionality.
    1. Register write complete callback.
    2. Enable write complete callback.
  3. Create a packet to send to slave.

Implementation

Code

Add to user application main():

Workflow

  1. Write packet to slave.
  2. Infinite while loop, while waiting for interaction with slave.

Callback

Each time a packet is sent, the callback function will be called.

Workflow

  • Write complete callback:
    1. Send every other packet in reversed order.
    2. Write new packet to slave.