Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Anyone have the PCM1802/08 ADC working with this library? #162

Answered by pschatzmann
unltdsoul asked this question in Q&A
Discussion options

First, I got these boards a while back and I did find that on the older boards i have that there are solder jumps to set fmt0 (so the board works with std format, rather than left-justified) and the + pads are not connected to vcc, so, I soldiered a jumper wire to vcc to get that to work). And have the pwrdwn and Fsync tied to + to enable the chip. I checked all clocks (same connections to the PCM5102 DAC board, that works great for output) I also set the program to 24bits per sample (PCM1802/8 is only 24b bit as i understand from the data sheets), and as I said, the PCM5102 outputs generated sinewave perfectly with the same clocks and settings. But, I am getting NO output at all on the pcm1802 Dout pin - i am using with APLL off, so the ESP32 is generating the master clock (this chip has no pll), and all the clock inputs are working. But, i can get no output from this board. I have 2 boards, tried both of them. Any help will be appreciated.
(I would go with another ADC, but these seem to be the least expensive. And others i have looked are out of stock right now. Reason i am worried about cost is if i can get this to work, i want to incorporate into a nitch market project, also i would need 2 cards for 4 inputs (if need be i would use 2 esp32's as i need to add separate processing on each channel). On Aliexpress these boards are less then 2ドル each, 8ドル on Amazon)

You must be logged in to vote

The PCM1802 seems to be very difficult to use and Google did not provide any help either.

My gut feeling is that the issue is FSYNC which is not provided by I2S. If you use the ESP32 as Master (and the PCM1802 as slave) there is no way to generate this signal.

Maybe you can try to use the ESP32 as slave (and the PCM1802 as master) and ignore this signal ?

I suggest that you start with a sketch that outputs the signal from the ADC to Serial to verify the signal first.

Finally I also don't understand why you would need 2 ESP32. The ESP32 supports 2 I2S Ports where each has 2 separate channels where you can do input and output at the same time.

ps. I just found the following link which might...

Replies: 13 comments 24 replies

Comment options

The PCM1802 seems to be very difficult to use and Google did not provide any help either.

My gut feeling is that the issue is FSYNC which is not provided by I2S. If you use the ESP32 as Master (and the PCM1802 as slave) there is no way to generate this signal.

Maybe you can try to use the ESP32 as slave (and the PCM1802 as master) and ignore this signal ?

I suggest that you start with a sketch that outputs the signal from the ADC to Serial to verify the signal first.

Finally I also don't understand why you would need 2 ESP32. The ESP32 supports 2 I2S Ports where each has 2 separate channels where you can do input and output at the same time.

ps. I just found the following link which might be useful https://www.pjrc.com/pcm1802-breakout-board-needs-hack/
I remember that I failed to make this module work a year ago, but with this info and the new functionality of the ESP32 we should give it another try. Can you try with the following connections:

 PCM1802 ESP32
 +5V VIN
 3.3V -
 GND GND
 DOUT GPIO32 DIN
 BCK GPIO14 BCLK
 FSY 3.3V
 LRCK GPIO15 LRCLK
 POW 3.3V
 SCK GPIOO3 MCLK (RX0)

Even when if format is wrong you might get some data on DOUT and I hope your soldered VCC is 3V

You must be logged in to vote
4 replies
Comment options

Phil, thanks so much for your time, but, I have given up on the 1802 boards. I ruined one while soldering, you have to jump solder the fmt0 and mode 0 & 1 to set them, and I accidently pulled the copper off one of the pads. Anyway, the other board i had did, when I first connected it up in master mode it gave me clock and data outputs. I don't recall doing anything to it, but, after setting up the ESP32 with the i2s to serial sketch, the PCM1802 just stopped working. Disconnected it from the ESP32 and just supplied power, since is set to master mode, it should output clock and data, but the outputs are all free floating. So i gave up on it.
I did order a pcm1808 which will come tomorrow and I'll try with that, it has regular i2s with no Fsync, so i will try that in slave mode.

The only reason I was thinking i may need more that one ESP 32 for 4 channels is because i was wanting to do reverb and other effects on all 4 channels, i was just thinking that the processor may not have enough speed (or memory) for everything Even if i process 2 channels on one core and two on the other. If it can handle it, great, otherwise, once IK get one 2 channel setup working, 'if need be' I can jiust duplicate it to get another 2 channels, then analog mix their outputs.

I don't want to bother you too much, but, I do have 2 older ESP32 A1S audio kit boards that I gave up on several years ago with the ESP ADF library, It has the AC101 So, I installed a new clean arduino ide on a thumb drive and set it up with expressif esp32 for arduino, in the board manager i added eps32 expressive 2.02 And I installed your libraries both the main audio tools and the audio kit. And, in the audio kit library src/AudioKitSettings.h I selected #6 since this has the AC101

BUT, in arduino > tools > boards > I don't see the esp32 a12 audiokit when I go to select what board to use. The only a1s thinker board is the ESP32 a1s CAM not the audio board. What board do i select, or is there another step in the process that I missed?

Comment options

Hey, I just tried compiling with standard ESP32 dev and i got a sinewave output on the audio kit, so i will be working further with this for now. (but when the pcm1808 comes I will try that as well. Let me know if that is Not the right board to select

Comment options

I haven't got very far with the AudioKit yet as I said 'i have the AC101 version, whether I use AUDIO_HAL_ADC_INPUT_LINE1 or AUDIO_HAL_ADC_INPUT_LINE2 the input still comes from the Mics and not the line in jack. What files handle that, and what do i need to change?

Comment options

Hey, I just tried compiling with standard ESP32 dev and i got a sinewave output on the audio kit, so i will be working further with this for now. (but when the pcm1808 comes I will try that as well. Let me know if that is Not the right board to select

Hi -- were you ever able to get the PCM1808 to work? Thanks!

Answer selected by pschatzmann
Comment options

Oh, then this seems to be a generic problem on all the boards. See this issue.
AUDIO_HAL_ADC_INPUT_LINE2 is supposed to be Line in. I guess the only way would be to desolder the microphones...
I am mainly using these boards to output audio or with Tensorflow Lite for Microcontrollers with the microphone input.

ps. I confirm that I am using the "ESP32 Dev Module" selection in Arduino as well.

You must be logged in to vote
1 reply
Comment options

Its been 2 yrs ago that I fiddled with this board with ESP ADF and i was able to switch between mic and line inputs, both or individual channels, so far I traced this line in the code:
res |= WriteReg(ADC_SRC, 0x0408); // 0x2020 for mic input // 0x0408 for line input
If you want i can get the address of ADC_SRC, but, i found it on a data page on the AC101, i may still have the pdf?
Those values are for both channels, and I can't recall if you can enter 0x0420 or 0x2008 if that is how to select each channel, or it was a little more complicated than that, I only needed to flip both at once, but, this would flip between mic and line inputs on the board, Where in your code do you write to the registers of the ac101 if i knew which files, i could try it (although depends on my availability)

Comment options

Comment options

So far I modified the first file, the .c file in audio_driver/ac101 and it now defaults to line in on both channels

Comment options

on line 168 res |= ac101_write_reg(ADC_SRC, 0x0420); // 0x0408); // 0x2020); 0x2020 both channels mic in 0x0408 both channels line in
0x0420 gave right mic in left line in

Comment options

I just committed a correction.
Could you please review it and help me to test ?

You must be logged in to vote
0 replies
Comment options

For the reference here is the technical sheet for the PCM1802 https://www.ti.com/cn/lit/ds/symlink/pcm1802.pdf?ts=1671611414917&ref_url=https%253A%252F%252Fwww.google.com%252F

It might be worth to give "master mode" a trial.

You must be logged in to vote
0 replies
Comment options

Hello, i join your discussion because i will certainly buy one of these pcm1802,
i went on the teensy forum and it seems there are bad and good modules with wrong designing,
the user who complained about it succeeded to make it working after buying other ones from different sellers.

https://forum.pjrc.com/threads/69636-PCM1802-gt-Teensy4-x-gt-PCM5102

You must be logged in to vote
0 replies
Comment options

Looking at the technical sheet, I don't think that is is possible to use this with pure I2S because of the additional FSY signal required by the module. The only chance that I see is to set the module to master mode and the microcontroller to slave mode and just ignore the additional signals.

I am currently trying to make the WM8960 work with Arduino: this would be a very cool solution with a built in ADC, DAC and amplifier

You must be logged in to vote
0 replies
Comment options

The teensy hack seemed to work fine,is that the I2S of the teensy that provide FSYNC and the esp32 do not?
I somewhere red that you only needs a 12,...MHZ quartz to give the master clock on it
The WM8960 looks promising , i don't understand why they're developing such modules only limited
for raspberry,like the big 7" TFT's with low prices compared to the ones for arduino,esp32...
I hope you'll success to democratize the WM8960 for all of us :)

You must be logged in to vote
1 reply
Comment options

I had a hard time with the PCM1808 and the raspberry pi pico, but finally got it going. You can see my log of trouble here.

Comment options

I've got the pcm1802 working. Fsync is not an issue when the pcm1802 is configured in slave mode (fsync just needs to be pulled to 3.3V). The issue I'm having is that the esp32 does not seem to be outputting the correct clock signal for the pcm1802 system clock. If operating at 11.4khz, 256fs, then the pcm1802 needs an 11.2896 Mhz clock signal. I've been providing this via an external signal generator for now, but I would like to understand how to generate this from the esp32.

I can confirm that the streams-i2s-serial example works out of the box (while applying an external system clock signal). The only issue with this is that it is not necessarily lined up with the bck and ws signals coming from the esp32, so the output wave on the serial monitor appears chopped sometimes (this is just my theory as to why its chopped, maybe it's due to the padding byte?).

By the way, my board required the jumper mod described in the pjrc blog post already mentioned in this thread.

I am hoping to do DSP on the esp32 for IQ processing. It seems that I may need to find another library according to other discussion posts. But, this was the only library that actually reconstructed the waveform properly on the serial plotter. I tried with the standard esp32 driver/i2s.h library but I couldn't reliably convert the 24bits of data back into the original waveform... @pschatzmann could you point me to where this operation is done in your source code? Also, would it be feasible to do AM demodulation with your library? I see AM mod sketches but not for demod.

Edit: I think the esp32 was probably sourcing the correct clock signal all along, but the wroom version is outputting the clock on pin 1 (tx) despite specifying pin 3 in the code.

You must be logged in to vote
0 replies
Comment options

On the ESP32 I am using my Int24_5bytes_t.h to represent and convert to/from 24 bits.
I don't have any AM demodulation functionality...

You must be logged in to vote
0 replies
Comment options

I just found this code on github: https://github.com/jtomes123/ESP32_I2S_PCM1808_PMC5102
I'll try it soon, If it's working, I port the master clk solution to the audio tools.

You must be logged in to vote
3 replies
Comment options

Why would you need to port anything ?
As far as I can see it's just a question of configuration...
What processor and Arduino Core version are you using ?

Comment options

Maybe I misunderstood the situation. I didn't connected a pcm1808 yet, nor checked the code. Reading this thread I meant that this chip is not working with the audio tools, there is some problem with the clocks or wiring. So I searched for a working code, and found the above link. Maybe I'm wrong?
I succesfully tried some of your examples using the ESP32-A1S module, and have a pcm1808 chip as well, and about to try that one too.

Comment options

You need to define the masterclock pin with pin_mck. But be careful, on the ESP32 there are only 2 pins that work for this purpuse and usually the gpio0 is used for this. I am not sure how important it is to use 32 bits for this to work...

Comment options

The streams-i2s-serial example is properly working with the aliexpress pcm1808 board. It needs the mck clock, I used the following pinout:
auto cfg = i2sStream.defaultConfig(RX_MODE);
cfg.copyFrom(info);
cfg.i2s_format = I2S_PHILIPS_FORMAT;
cfg.is_master = true;
// this module nees a master clock if the ESP32 is master
cfg.use_apll = false; // try with yes
cfg.pin_mck = 0;
cfg.pin_bck = 2;
cfg.pin_ws = 15;
cfg.pin_data = 16;

i2sStream.begin(cfg);

Of course the serial speed is way too low even at 1000000bps, so the plot is a bit choppy, but seems that the adc is working very well. I used the internal DAC in cosine mode for test signal. The board needs clean 5V and 3.3V power supply. Using just the ESP board's pins as power supply the ADC is a bit noisy, the lower 10 bits are just noise.

Platformio default espressif32 platform sometimes drops missing WiFiClientSecure.h error, forcing a new version solves it:
[env:nodemcu-32s]
platform = espressif32@6.6.0

You must be logged in to vote
13 replies
Comment options

Just a small clarification because your usage of board is a bit confusing: when you set is_master = true then the ESP32 microcontroller is the "master" and the I2S breakout board is the "slave". I usually prefer to use this because then you can select the sampling rate in your code and it is not predefined by the hardware.

In this case the master clock is generated by the ESP32 and you can use either pins 0, 1, or 3. (However avoid 1 because this is also the serial TX pin)

The default clock value is 256 * audio sampling rate if not specified otherwise.

The ESP32 only supports the master clock as output (and not as input).

Comment options

Thanks for the clarification, I thought my writing would be understandable for everyone but maybe it's confusing.

The Problem is that I read only zeroes from the PCM1808's breakout board data_out. I suspect my board (an ESP32-Wrover-E, designed for a camera - a clone of the Freenove ESP32-WROVER Board) has a problem to generate the MCK. My approach is to replace the board as a next step.

In the rest of this reply I also wanted to clarify a bit from my end, hopefully better understandable than before:

Master Clock can only be used on pins 0, 1, or 3. (However avoid 1 because this is also the serial TX pin)

The (your) Audiologger also gives the warning and is known from the esp32 official source codes i2s.h: "Note that ESP32 supports setting MCK on GPIO0/GPIO1/GPIO3 only". Configuring the i2s port as master with pin 0 as mck should generate the master clock properly but it doesn't on my "fake" board. An esp32-s3 is capable of using any free GPIO pin for the MCK (indirect source), I will try that next.

The I2S PCM1808 breakout board is slave, and the ESP32 is master, with is_master = true**:

Good to clarify if that wasn't clear, to me it was. I understand that it's preferrable for more possibilities, and my new insight was that my I2S PCM1808 breakout board is also not capable by itself (without connecting a crystal osci) to generate a mck (see also), hence is_master = false does not work out of the box with this breakout board anyway - somehow I thought the breakout board would provide the master clock to itself if not provided, but that's not implemented in hardware on the/my board. Good to know that the ESP32 does not support master clock as input. So bascially the mck-pin is not used when is_master = false. Makes sence (we still have a sample rate), thanks.

The default clock value is 256 * audio sampling rate if not specified otherwise.

Now I also read the following: Please set the mclk_multiple to I2S_MCLK_MULTIPLE_384 while using 24 bits data width Otherwise the sample rate might be imprecise since the bclk division is not a integer(source). Since the PCM1808 is 24bits, I stick to 384fs now. I played around with the fixed_mclk a lot, and below a certain rate (something like 96fs) it doesn't even output zeroes anymore, which is at least a sign that the breakout board still responds. 384 always worked to at least output zeroes (512 and 256 too though, as they should).

I attached my code, which I suspect would run just fine on another board. Btw I can have some noise if I touch the data-pin, but it never seems to correlate to whatever is connected to the L_in / R_in pins (stereo cable) on the actual breakout board.
main.md

Thanks so much for your support again, I will report back asap whether it runs on a different board.

Comment options

I don't know if you read my post above, but I was using a Wroom board and despite specifying the MCK to output on pin3 within the code, the Wroom board was actually outputting it on pin 1 (tx).

I'm curious to see if you can get that purple ADC to work, because I have one but was not successful (didn't try that hard). I was successful with the PCM1802 with some "mods"

Comment options

GPIO 3 has always been the TX pin !

Comment options

Okay then. I was specifying gpio3 in the code but it was actually outputting the mck signal on gpio1 (for the wroom-32)

Comment options

Esp32,pcm1803,pcm5102 code

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /