1.1.6.3 SPI-I2S Peripheral Library Help

This section provides an interface to use the Inter-IC Sound (I2S) peripheral.

Introduction

This library provides a brief overview of the I2S peripheral. On PIC32MX/MZ processors, this peripheral is shared with the SPI (Serial Peripheral Interface) hardware.

Description

The I2S module implements an I2S (Inter-IC Sound) interface, for connection between an MCU and an audio peripheral such as a codec or Bluetooth module.

The I2S module provides support to the audio protocol functionality via four standard I/O pins. The four pins that make up the audio protocol interface modes are:

  • SDI: Serial Data Input for receiving sample digital audio data (ADCDAT as output from the codec)

  • SDO: Serial Data Output for transmitting digital audio data (DACDAT as input to the codec)

  • SCK: Serial Clock, also known as bit clock (BCLK)

  • FS: Frame Select, also known as Word Select or Left/Right Channel Clock (LRCK)

In addition, there is a fifth line, called REFCLKO (Reference CLock Output, or Host Clock), which can be used to drive the codec.

The SCK provides the clock required to drive the data out or into the module, while FS provides the synchronization of the frame based on the protocol mode selected. In I2S mode, the leading edge of audio data is driven out one SCK period of starting the frame.

In Host mode, the module generates both the SCK and FS.

In Client mode, the peripheral generates the BCLK and LRCLK signals, driving the SCK and FS pins of the I2S module.

Host Mode

Host Generating its Own Clock – Output BCLK and LRCK

Client Mode

Codec Device as Host Derives MCLK from MCU Reference Clock Out

Configuring the Library

This section describes how to configure the peripheral library using the MHC.

Description

The library is configured for the supported processor when the processor is chosen in MPLAB X IDE, using the Microchip

Harmony Configurator (MHC)

Choose the I2S peripheral by clicking on the appropriate instance under Peripherals->I2S in the Available Components section of MHC. (The I2S component may also be added automatically as a result of using a BSP Template, such as one for a codec or Bluetooth module).

When the I2S peripheral is clicked on in the Project Graph, the following menu is displayed in the Configurations Options:

Note: DMA and Interrupt Mode are always enabled.

Host Mode Enable Bit -- only Host Mode is currently supported.

Clock Polarity Select Bit -- determines whether idle state of clock is high (default) or vice versa.

SPI Clock Edge Select Bit -- selects whether output chamges on transistion from active to idle (default) or vice versa.

32/16 Bit Communication Select Bits -- selects the data, FIFO, channel, and frame sizes.

Host CLock Enable Bit -- always selects REFCLK to be used by the baud rate generator.

Audio Protocol Mode -- I2S, left or right justified, or PCM.

Transmit Audio Data Format -- stereo or mono.

Frame Select Pin -- specifies which pin is used for the frame select (aka L/R clock or word select) Invert -- indicates whether the output of the LRCLK_Get function is inverted or not

Using the Library

This section explains how to use the peripheral library.

Description

Library Source Files: The I2S Peripheral Library library source files are provided in the

audio/peripheral/i2s_xxxx/src or audio/peripheral/i2s_xxxx/templates directory. This folder may contain optional files and alternate implementations. Please refer to Configuring the Library for instructions on how to select optional features.

Usage Model The only usage model for the I2S Peripheral Library is to use a Interrupt/DMA model. Therefore the remaining functions normally associated with a PLIB like this (handling write or read requests, or returning transfer status), will be accomplished by the I2S driver directly communicating with the appropriate DMA functions, which is why they are not provided here. The one function provided besides initialization is one for synchronizing with the left/right clock (LRCLK) for the I2S stream.

Example Applications:

This library is used by the following applications, among others:

  • audio/apps/audio_tone

  • audio/apps/microphone_loopback

Library Interface

This section describes the Application Programming Interface (API) functions of the Peripheral Library.

Refer to each section for a detailed description.

  • Initialization Function

NameDescription
I2Sx_InitializeInitializes I2S x module of the device
  • Status Functions

NameDescription
I2Sx_LRCLK_GetGet LRCLK state