Microchip® Advanced Software Framework

Quick Start Guide for SERCOM I2C Slave - Callback

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

  • Slave mode
  • 100KHz operation speed
  • Not operational in standby
  • 10000 packet timeout value

Prerequisites

The device must be connected to an I2C master.

Setup

Code

The following must be added to the user application:

A sample buffer to write from, a sample buffer to read to and length of buffers:

Address to respond to:

Globally accessible module structure:

Globally accessible packet:

Function for setting up the module:

Callback function for read request from a master:

Callback function for write request from a master:

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 address and address mode settings in the configuration.
    3. Initialize the module with the set configurations.
    4. Enable the module.
  2. Register and enable callback functions.
    1. Register and enable callbacks for read and write requests from master.

Implementation

Code

Add to user application main():

Workflow

  1. Infinite while loop, while waiting for interaction from master.

Callback

When an address packet is received, one of the callback functions will be called, depending on the DIR bit in the received packet.

Workflow

  • Read request callback:
    1. Length of buffer and buffer to be sent to master is initialized.
    2. Write packet to master.
  • Write request callback:
    1. Length of buffer and buffer to be read from master is initialized.
    2. Read packet from master.