STM32 Audio Codec Interfacing

by Pratik (A PCBArtist)

STM32 audio codec interfacing is made easy with the chips often being armed with several I2S peripherals multiplexed with the SPI peripheral on board.

The STM32F411 chip in LQFP-100 package, for example, sports five I2S interface blocks that can be used to interface with an audio ADC, DAC or codec. In this article, we look at our options for connecting an I2S audio codec with STM32 chips. The codec used in the examples that follow is the PCB Artists ES8388 audio codec module.

Selecting an STM32 for Audio Codec Applications

Not all STM32 chips are capable of interfacing with an audio codec that uses an I2S interface. To be able to connect to an audio codec, you will need the STM32 to have:

  • An I2C port
    I2C port is used to configure the audio codec. The I2C bus can be used to interface to other I2C devices as well, it does not need to be exclusive.
  • An I2S or SAI port
    I2S ports are usually multiplexed with SPI ports on STM32 devices. You can use an I2S port (at the expense of losing that SPI block), or you can use an SAI port if available.
  • Master clock output
    Not all codecs need this clock source, but most of them do. The master clock often needs to be a multiple of the I2S bus sampling rate.

You can read a detailed explanation of which audio codec pins are used for what purpose in a related article on audio codec interfacing.

I am going to use an STM32F411-Discovery board for illustrating any audio related examples on this website.

Assign I2S Pins for Audio Codec

I personally very much prefer the STM32 CubeMX Utility for at least selecting the pin functions on STM32 devices. It makes life a lot easier than going through several pages of datasheet pin multiplexer tables. Whether you use it to generate code or not is your decision to make.

In the case of STM32F411-Discovery kit, I2S3 is already being used for connecting to the audio DAC that the board already has. So I picked I2S2 for using with the ES8388 codec module.

Having checked that all the pins are available for using with ES8388 codec module and there are no Discovery board peripheral conflicts, here is the result.

STM32 audio codec I2S pins
STM32 I2S Pins for Interfacing with Audio Codec

For the control bus (I2C), I2C3 is available on the Discovery board:

  • PA8: I2C3_SCL
  • PC9: I2C3_SDA

As for the MCLK output, the only optional available for I2S2 clock output was

  • PA3: I2S2_MCLK
Here is a summary of connections between any STM32 and ES8388 audio codec module, for example.
ES8388 STM32 audio codec pinout connections
STM32 Audio Codec Interface Connections

STM32 Codec Driver Firmware

The ES8388 module is a new product and we are working on the codec driver library. The generic library will be available on GitHub and you can use the library to play audio back or record audio using the module. If you are interested in updates on this module and follow-up tutorials, please make sure you are enrolled in the notification list in the sidebar!

You may also like

Leave a Comment

2 × one =