Creating an audio input/output board for Raspberry Pi, Jetson Nano (PCM5102A+PCM1808)

Kentaro Mitsuyasu
6 min readAug 15, 2020

--

Trigger

I often see DACs, but there are not many so-called codec boards that also carry ADCs.
Microe’s Audio Codec Board-Proto seems to be one of the few products.

Specifications are:
On-board modules

WM8731 Audio Codec, stereo 24-bit multi-bit sigma delta ADCs and DACs, Headphone and Microphone audio connectors
Key Features

Hi-Quality Audio Performance.Selectable ADC High Pass Filter. ADC and DAC Sampling Frequency: 8kHz — 96kHz
Interface I2C or SPI

It is said that.

According to the circuit diagram, it corresponds to the I2S standard supported by Raspberry pi and Jetson Nano, and it seems that some setting is done with I2C connection.

The Raspberry pi seems to have a case of running with the Linux embedded driver WM8731, but Jetson Nano did not find the case easily even after examining it.

First, Jetson Nano couldn’t recognize it as an I2C device.
Raspberry pi could be recognized by I2C address 0x1a as follows.

pi@pi3:~ $ sudo i2cdetect -r -y 1
0 1 2 3 4 5 6 7 8 9 abcdef
00: ---- - - - - - - - - - - -
10: ---- ---- ---- ---- ---- UU ---- ---- -
20: ---- ---- ---- ---- ---- ---- ---- ----
30: ---- ---- ---- ---- ---- ---- ---- ----
40: ---- ---- ---- ---- ---- ---- ---- ----
50: ---- ---- ---- ---- ---- ---- ---- ----
60: ---- ---- ---- ---- ---- ---- ---- ----
70: ---- ---- ---- ----

Even if you clear this, it seems that you need to rebuild the device tree, install the driver, and set ALSA in order to recognize it on Jetson Nano. The hurdle is high.

I bought about three, but it ended in vain.

There is no I2S compatible audio board that can be used for both boards, so I’d like to make one.

What is I2S

What is the basic configuration of I2S in the first place?

https://hifiduino.wordpress.com/2014/11/13/raspberry-pi-b-digital-audio/
and according to the above, it seems to consist of four PCM_CLK, PCM_FS, PCM_DIN and PCM_DOUT on the right side of the box labeled Serializer. The corresponding Raspberry pi 40 pin header is

In other words, it seems that it should be connected to
PCM_CLK ⇔ BITCLOCK (12pin)
PCM_FS ⇔ LRCLOCK (35pin)
PCM_DIN ⇔ DATA OUT (40pin )

PCM_DOUT ⇔ DATA IN (38pin)
.

The I2S DAC, which was popular a while ago, had a very simple configuration using the PCM5102A without I2C settings.

Looking around, I found a circuit diagram combining the PCM1808 with an ADC for BeagleBone Black.
http://www.tij.co.jp/jp/lit/df/tidrim5/tidrim5.pdf

According to this, the crystal output of 25MHz is branched by SI5351A, and MCLK, BCLK, and WCLK are made.
It is input to PCM5101, PCM1808.
It is a circuit that can be used for
PCM5102 , PCM1808 DIP kit is about 2$,
PCM5102A DIP kit is about 4$
Si5351A-B itself costs about 1$ in the market. not expensive.
MCLK (Master Clock) is a basic clock that determines the audio format by the chip.
There are 22.5792MHz and 24.576MHz.
LRCLK is a clock that sends L when the signal level is 0 and sends R when it is 1. Generally, it has the same value as the sampling frequency.
BCLK is a bit clock, which is a reference clock for reading 32 bits. 32 bits x 2 (L+R) will be 64 bits.
For example, 24.5760MHz/8 = 3.072MHz /32/2 =
48KHz 24.576MHz is divided by 8, 3.072Mhz is BCLK, and it is LRCLK (48KHz) when divided by 64.

It is necessary to generate a master clock on the board, but the Si5351A seems to be set by I2C itself.
I want to escape from the I2C settings.

The PCM1808 data sheet has the following description.
7.3.5.1 Interface Mode
MD1 (Pin 11) and MD0 (Pin 10) select the Master or Slave mode as the interface mode.
Table 2 shows the interface mode selections. MD1 and MD0 must be set before powering up.
In master mode, the PCM1808 device provides the timing for serial audio data communication between the PCM1808 device and the digital audio processor or external circuitry.

After reading the above, the master mode seems to output BCK(BITCLOCK) LRCK(LRCLOCK) when the master clock is input to the SCKI pin.
I don’t need to use Si5351A. let’s try it.

Considering the circuit below, I made a barracks.

https://drive.google.com/file/d/1VhuJZdqONm3bajzbnmwvDSBBOA8Lf6MG/view?usp=sharing

Embedding the driver on the Raspberry pi

Basically, a driver is installed according to the link of Old Kernel Install Method(adafruit) ,

This time, make BCK and LRCK on the codec side and set them to be sent to the Raspberry pi side, so
rewrite the following 44 lines of my_loader.c.
https://github.com/PaulCreaser/rpi-i2s-audio/blob/master/my_loader.c

.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS,

.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM,

edit: if you have Raspberry Pi 4B, you should also modify 43, and 46 lines:

.platform = "fe203000.i2s", // modified for Raspberry Pi 4B

.name = "fe203000.i2s", // modified for Raspberry Pi 4B

Other than that, if you follow the above procedure,
it can be recognized as a recording and playback device as snd_rpi_simple_card as follows.

pi@pi3:~/rpi-i2s-audio $ aplay -l
**** List of hardware devices PLAYBACK ****
Card 0: ALSA [bcm2835 ALSA], Device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevice: 7/7
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Card 0: ALSA [bcm2835 ALSA], Device 1: bcm2835 IEC958/HDMI [bcm2835 IEC958/HDMI]
Sub device: 1/1
Subdevice #0: subdevice #0
Card 0: ALSA [bcm2835 ALSA], Device 2: bcm2835 IEC958/HDMI1 [bcm2835 IEC958/HDMI1]
Sub device: 1/1
Subdevice #0: subdevice #0
Card 1: sndrpisimplecar [snd_rpi_simple_card], Device 0: simple-card_codec_link snd-soc-dummy-dai-0 [simple-card_codec_link snd-soc-dummy-dai-0]
Sub device: 1/1
Subdevice #0: subdevice #0
pi@pi3:~/rpi-i2s-audio $ arecord -l
**** List of hardware device CAPTUREs ****
Card 1: sndrpisimplecar [snd_rpi_simple_card], Device 0: simple-card_codec_link snd-soc-dummy-dai-0 [simple-card_codec_link snd-soc-dummy-dai-0]
Sub device: 1/1
Subdevice #0: subdevice #0

Furthermore, make it recognized by Audacity (installed with sudo apt install audacity) on Raspberry pi.

Now you can record and play back without any problems.
As shown in the circuit diagram above,
high: 96khz
low: 48khz
can be set by switching the MD1 pin with the jumper pin .

Since the base has become cheap and easy to make with elecrow, I will try to create the base.
An additional chip for server authentication is added.

Update: Upload Kicad project file.

We will verify this board.

--

--

Kentaro Mitsuyasu
Kentaro Mitsuyasu

Written by Kentaro Mitsuyasu

I work for a security and Linux company, and this blog summarizes some of the technologies I’ve been interested in recently. I like music, trivia, travel.etc.

Responses (2)