PCM1808 SCLK

plasmaphase
Posts: 4
Joined: Sun Jan 15, 2023 12:57 am

PCM1808 SCLK

Postby plasmaphase » Sun Jan 15, 2023 1:18 am

I'm currently using an ESP32-S3 to connect to a PCM1808 Audio ADC (https://www.ti.com/lit/gpn/pcm1808). The standard i2s example seems sufficient with one exception, the SCLK. The PCM1808 part requires a clock input which is it's sample clock:
PCM1808_Pinout.png
PCM1808_Pinout.png (138.84 KiB) Viewed 4454 times
SystemClock.png
SystemClock.png (149.81 KiB) Viewed 4454 times
In the i2s standard example (https://github.com/espressif/esp-idf/bl ... ple_main.c) there's the MCLK, BCLK, WS, and DOUT, but there is no SCLK:

i2s_pins.png
i2s_pins.png (26.81 KiB) Viewed 4454 times
So my question is, is there a way to create a "generic" clock output on a GPIO pin that's synchronous with other pins? Is there another more novel solution to this? The PCM1808 requires this clock to function, and surely there has to be a way to generate this clock, I'm just not familiar enough to know how.

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: PCM1808 SCLK

Postby ESP_Sprite » Mon Jan 16, 2023 2:38 am

Looks like 'system clock'/SCLK is TIs equivalent to MCLK.

plasmaphase
Posts: 4
Joined: Sun Jan 15, 2023 12:57 am

Re: PCM1808 SCLK

Postby plasmaphase » Mon Jan 23, 2023 12:27 pm

You may be right, I will try connecting as MCLK and try it out.

clearlynotstefan
Posts: 4
Joined: Sat Mar 14, 2020 4:55 pm

Re: PCM1808 SCLK

Postby clearlynotstefan » Fri Aug 18, 2023 4:16 pm

plasmaphase wrote:
Mon Jan 23, 2023 12:27 pm
You may be right, I will try connecting as MCLK and try it out.
Did it work? I'm looking at picking one of these up for a project and concerned about this issue as well.

jenschr
Posts: 7
Joined: Sun Sep 17, 2023 12:40 pm

Re: PCM1808 SCLK

Postby jenschr » Sun Sep 17, 2023 12:42 pm

@plasmaphase I'd also love to know if MCLK was the answer ;)

escalator
Posts: 5
Joined: Tue May 29, 2018 11:01 am

Re: PCM1808 SCLK

Postby escalator » Thu Sep 21, 2023 9:53 am

jenschr wrote:
Sun Sep 17, 2023 12:42 pm
@plasmaphase I'd also love to know if MCLK was the answer ;)
Hi, yes the GPIO0 pin carries out the MCLK signal from I2S by default in the ESP32, it can go directly to pin 6 of PCM1808 (SCKI) or, better, you can do it through a 10 to 49 ohm resistor. As an example for plain ESP32 chip:

Code: Select all

#define SAMPLERATE  48000
#define BITS	16
#define NUMCHANNELS 2
i2s_config_t i2s_config = {
	                .mode = I2S_MODE_MASTER | I2S_MODE_RX,
	                .sample_rate = SAMPLERATE,
	                .bits_per_sample = BITS,
	                .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
	                .communication_format = I2S_COMM_FORMAT_STAND_MSB,
	                .dma_buf_count = 4,
	                .dma_buf_len = 240,
	                .use_apll = true,
			.fixed_mclk = 256 * SAMPLERATE,
			.tx_desc_auto_clear = true,
	                .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1                                //Interrupt level 1
	};
In my example I fix the initial MCLK rate at 256 x sample rate, you can modify it to your needs or change it later in code.

Code: Select all

//I2S pinout example configuration
	i2s_pin_config_t pin_config = {
	                .bck_io_num = 5,//BIT CLOCK(TO PIN 8 BCK IN PCM1808)
	                .ws_io_num = 25,//LR CLOCK(TO PIN 7 LRCK IN PCM1808)
			.mck_io_num = 0,//MASTER CLOCK(TO PIN 6 SCKI IN PCM1808)
	                .data_out_num = -1,//(NOT USED)
	                .data_in_num = 35//DATA IN(FROM PIN 9 DOUT IN PCM1808)
	};
 	ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL));
 	//this optional line reconfigures the default I2S asignment pins:
  	ESP_ERROR_CHECK(i2s_set_pin(I2S_NUM_0, &pin_config));
  	//this optional line configures the default MCLK rate:
  	ESP_ERROR_CHECK( i2s_set_clk(I2S_NUM_0, SAMPLERATE, BITS, NUMCHANNELS) );
  	

jenschr
Posts: 7
Joined: Sun Sep 17, 2023 12:40 pm

Re: PCM1808 SCLK

Postby jenschr » Mon Oct 16, 2023 7:53 pm

Thanks! Got it running as well.

MariusD
Posts: 2
Joined: Mon Oct 23, 2023 10:11 pm

Re: PCM1808 SCLK

Postby MariusD » Mon Oct 23, 2023 10:13 pm

Hi guys,

I am using your sample code and I can see all of the clocks being sent to the PCM eval board. Unfortunately, it is not sending back any data when it is in slave mode, only when I use the onboard master oscillator.

Are there any other configs or timings missing from the sample code?

MariusD
Posts: 2
Joined: Mon Oct 23, 2023 10:11 pm

Re: PCM1808 SCLK

Postby MariusD » Tue Oct 24, 2023 12:37 am

jenschr wrote:
Mon Oct 16, 2023 7:53 pm
Thanks! Got it running as well.
Are you able to paste the working I2S read calls that decode the data? I am having trouble decoding the data stream.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 361 guests