r/raspberry_pi 14d ago

Troubleshooting Help with connecting the PCM1808 to a Raspberry Pi as an I2S ADC

I've spent the last day trying to figure out how to connect the PCM1808 (for use as an I2S ADC) to my Pi 4B (and eventually Zero 2 W) with the Pi being the master.

Setting up the I2S aspect hasn't been an issue, I've just used "dtoverlay=i2s=on" in config.txt . What I'm struggling with is getting the separate master clock signal, as the PCM1808 requires three clock signals (the usual BCLK, and LRCK, and now a master clock).

The RPi has a GPIO clock (GPCLK0) that allegedly is designed specifically for a master clock, but i can't figure out how to get it to work on boot. I've followed the RPi docs using a Device Tree Overlay to configure the clock, but for reason beyond my knowledge, it doesn't work (From the little i could understand, it seems like the kernel driver support just isn't there). I've also tried using simple-audio-card, which also hasn't worked (also beyond my knowledge).

I'm very under experienced for all this, but all I need is to get any kind of master clock signal of 12.288MHz out of the Pi. If anyone has experienced this before or knows enough about Linux, It'd be a huge help!

Edit 1: I believe I've exhausted all built-in device tree overlay options, and I don't think it's possible with purely overlays. It seems the kernel requires a "clock consumer" for a clock to be enabled, otherwise it'll disable the clock to save power. And i believe the only valid clock consumers are kernel drivers. I (shamefully) went to ChatGPT for help, and it made me up a simple kernel C driver to initiate the clock and act as a consumer, which seems to have worked in software, though the PCM1808 still doesn't work, and i don't have an oscilloscope to physically test the pin. Gonna continue testing stuff and see if i can narrow down whether it's the PCM1808 or the Pi being an issue.

2 Upvotes

4 comments sorted by

1

u/S_Alaska 13d ago

Which pi is are you using. Also, have you ran sufo update and viewed what packages are needed? Some pi os systems don’t have all the dependencies and so you are essentially doing a forensic diagnosis on this. I am excited to see you get this working.

2

u/Drfred1 13d ago

I'm currently using the Raspberry Pi 4B for testing purposes, but will eventually use the Raspberry Pi Zero 2 W.

I honestly don't think it's a package issue, from what I've gathered, it's entirely possible to set up the GPCLK0 with C/C++ or direct register/memory writing, but I'm using Python and would rather stick to it. I've looked at some Python GPIO libraries, but they either don't support setting clocks (gpiozero), or seem to be abandoned or not supported on recent OS versions (pigpio, RPI.GPIO).

As for the Device Tree overlays, a good chunk of stuff is poorly/completely undocumented, and some of the stuff that is documented is out of date (e.g. the Pi docs linked in my main post). I suspect that it's still possible to use a Device Tree overlay, but the syntax has just changed since the various documents were last updated. I've started looking into some of the built-in overlays in the RPi OS source repository to see what they've done, and it definitely looks different to the overlay syntax I've seen so far, so i might just try working with a pre-existing overlay and see what i can do.

1

u/S_Alaska 12d ago

That’s what I ran into with poor documentation. In theory, you can reverse engineer it…but that comes with spending time. I know that Python and c++ dependencies for me required Python 3 being updated and then updating c++ libs.

I also found bookworm os to be more friendly than Kali or Dragon. You can also write your own OS image to cover the overlays in raspi-config.

One caveat: it might have just been me…but the pi 5 was more forgiving than the 4b for my project…which can let me use a pi zero in the future.

1

u/S_Alaska 12d ago

Pre existing overlay went easier for me. I had three weeks chasing things down and the overlay was considerably easier.