Microchip® Advanced Software Framework

Quick Start Guide for the SAM4L IIS driver

This is the quickstart guide for the SAM4L Inter-IC Sound Controller 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

This use case will demonstrate how to initialize the IIS module to master in loopback mode.

Prerequisites

  1. System Clock Management (Sysclock)

Clock setup steps

Example code

Enable the following macro in the conf_clock.h:

#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
#define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K

Add the following code in the application C-file:

Workflow

  1. Set system clock source as DFLL:
    #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL
  2. Set DFLL source as OSC32K:
    #define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K
  3. Initialize the system clock.

Usage steps

Example code

Add to, e.g., main loop in application C-file:

struct iis_config config;
struct iis_dev_inst dev_inst;
config.data_format = IIS_DATE_16BIT_COMPACT;
config.slot_length = IIS_SLOT_LENGTH_16BIT;
config.fs_ratio = IIS_FS_RATE_256;
config.num_tx_channels = IIS_CHANNEL_STEREO;
config.num_rx_channels = IIS_CHANNEL_STEREO;
config.loopback = true;
config.master = true;
iis_init(&dev_inst, IISC, &config);
iis_enable(&dev_inst);

Workflow

  1. Initialize the module with given configuration
    struct iis_config config;
    struct iis_dev_inst dev_inst;
    config.data_format = IIS_DATE_16BIT_COMPACT;
    config.slot_length = IIS_SLOT_LENGTH_16BIT;
    config.fs_ratio = IIS_FS_RATE_256;
    config.num_tx_channels = IIS_CHANNEL_STEREO;
    config.num_rx_channels = IIS_CHANNEL_STEREO;
    config.loopback = true;
    config.master = true;
    iis_init(&dev_inst, IISC, &config);
  2. Enable the module
    iis_enable(&dev_inst);
  3. Enable transmission, reception and clocks
  4. Use write/read function to access the data
    iis_write(&dev_inst, data);
    iis_read(&dev_inst, &data);