I2S Master Clock Pin

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

I2S Master Clock Pin

Post by wonde05 » Thu May 12, 2022 4:30 pm

I was trying to use the esp32 for an audio output using micropython's I2s class and an external DAC. The dac needs a master clock so I initialized the I2S like this

Code: Select all

from machine import I2S, Pin
sck_pin = Pin(14)
ws_pin = Pin(13)
sd_pin = Pin(12)
mck_pin = Pin(0)
audio_out = I2S(2,
                sck=sck_pin, ws=ws_pin, sd=sd_pin, mck=mck_pin,
                mode=I2S.TX,
                bits=16,
                format=I2S.MONO,
                rate=44100,
                ibuf=20000)
In the documentation the I2S constructor is defined as

Code: Select all

class machine.I2S(id, *, sck, ws, sd, mck=None, mode, bits, format, rate, ibuf)
but when I add the master clock definition I get a Type Error that says "extra keyword arguments given" can any one give me a hint on why that is happening ?

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: I2S Master Clock Pin

Post by Mike Teachman » Thu May 12, 2022 10:42 pm

Master clock support is presently only available with the mimxrt port. It is possible to add master clock support to the esp32 and stm32 ports, but at the moment there is no timeline for this development.

As a workaround, you might be able to use the machine.PWM class to create a master clock signal that will work with the DAC. Or, sometimes the DAC can be programmed to create an internal master clock using the ws/sck signals combined with an internal PLL.

What DAC are you using?

wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

Re: I2S Master Clock Pin

Post by wonde05 » Sat May 14, 2022 10:32 am

this are the the chips at my disposal right now CS4344, PCM1771 and PCM1773 I haven't decided which on to use yet is there a specific chip you recommend from those three ?

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: I2S Master Clock Pin

Post by Mike Teachman » Mon May 16, 2022 4:00 am

It looks like all those devices need a master clock input. None include an internal PLL for creating the master clock internally. The ESP32 machine.PWM class should be able to create the master clock signal, which is typically 256*audio sampling rate.

wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

Re: I2S Master Clock Pin

Post by wonde05 » Mon May 16, 2022 6:09 am

@Mike thank you for your answer, generating the master clock using the PWM is a great idea because it has the advantage of having the clock output in any pin that can generate PWM signals rather than being limited to the three CLK_OUT pins of the esp32.

I was looking at the i2s.c code in the esp32 port and found out that the master clock pin wasn't defined so I changed the Pin definition to gipio_0 and I was able to get a clock output on that Pin.

Post Reply