Microchip® Advanced Software Framework

Quick Start Guide for SERCOM I2C Master - Basic

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, a sample buffer to read:
  • Slave address to access:
  • Number of times to try to send packet if it fails:
  • Globally accessible module structure:
  • Function for setting up the module:
  • 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. Create a variable to see when we should stop trying to send packet.
  3. Create a packet to send.

Implementation

Code

Add to user application main():

Workflow

  1. Write packet to slave.
    The module will try to send the packet TIMEOUT number of times or until it is successfully sent.
  2. Read packet from slave.
    The module will try to read the packet TIMEOUT number of times or until it is successfully read.