Page 31 of 40

### Re: The I2S sound thread.

Posted: Mon Jun 19, 2017 2:34 pm
Hi y'all,

It's a post I made about using PLLD to generate i2s clock. Does any one has advices? I made a new post since I was thinking that this could help someone even if it wasn't I2S related.

YCN-

### Re: The I2S sound thread.

Posted: Tue Jun 27, 2017 6:17 pm
I set MASH 1 , DIVI = 177 , DIVF = 158
This is for 44100 @ 32 bit stereo?
You have the correct DIVI, but the DIVF is not correct. How are you working DIVF out?

By my calc, DIVF should be 681 ( although it falls on an edge case so 682 could also be preferable ).

This gives the value 0x5A0B1277 for the PCMDIV register.

n.b. I have not verified this as I work @ 48K.

### Re: The I2S sound thread.

Posted: Wed Jun 28, 2017 7:48 am
Thanks for the answer but if I fooled myself that way I will not even have a close frequency from the frequency I expect which I do have. I think you calculated with 19.2 MHz osc when I used 500MHz osc.

I calculate that way :

I need to have bck = 44100*32*2 = 2822400 Hz = 2.8224 MHz
I used PLLD = 500MHz since the 19.2MHz would give a higher jitter.
Then I did 500 / 2.8224 = 177,154195011
So DIVI = 177 and DIVF = 0.1541195011 * 1024 = 157.8183... I "rounded" it at 158.
That should give me : average_frequency = 500 / ( 177 + 158/1024) = 2,822398377 MHz
But I have BCK = 2.8242MHz which is not that bad but when it came to LRCK I got : 43.4503kHz instead of 44.1kHz
I don't think that this is really crucial since it give me a jitter of 20 uS for LRCK ( 1 / 44100 - 1/43450,3 = 20 uS) but I don't know if that will disturb the audio even if I don't think so.

You wont face this problem with 48kHz since you have a neat DIVI and DIVF with 19.2 MHz. I think it 6.25 so that is DIVI = 6 and DIVF = 256 which gives the (almost) perfect result.

YCN-

### Re: The I2S sound thread.

Posted: Wed Jun 28, 2017 2:48 pm
So DIVI = 177 and DIVF = 0.1541195011 * 1024 = 157.8183... I "rounded" it at 158.
This is incorrect. This should be 4096. Although it says 1024 in the PCMCLK datasheet, it has been corrected
in the forums and is mentioned in the example source code.

### Re: The I2S sound thread.

Posted: Thu Jul 06, 2017 7:16 pm
Hi

my homebrew CS5361 audio ADC board is working fine via an I2S to USB converter. I'd prefer using the onboard I2S on my rpi 3 instead of USB, however. I have read quite some postings here and elsewhere but I still do not know how to connect an I2S ADC (ADC is master, ADC settings done with DIP switches) to my rpi. Can someone here please provide guidance suitable for a beginner?

Peter

### Re: STICKY: The I2S sound thread.

Posted: Thu Jul 27, 2017 4:45 am
Hi ,How to write a code for communication between raspberry pi and codec via pcm.?so now i need to write a pcm code by choice clk as a slave,need to generate fsync ,so on..so anybody please help me out ..

### Re: STICKY: The I2S sound thread.

Posted: Mon Aug 28, 2017 1:59 am
Hi, (@stefan_o and YCN-)

Stefan, thanks for posting your drivers for the 4202! they've made a lot of things much clearer. I'm still confused though how you're using the gpio's - in particular, what you're doing with the FMT pins. Also, I'm not too clear on how you're setting your clocks - I see that you're using the FS0-2 pins to choose a sample rate, but it don't see how you're choosing the clock source. Does this happen in the BCM_I2S.c driver??? And if so, where in your code do you communicate with the clocks? In particular, if I wanted something from the 44.1 sample rate, how do I tell this to the BCM driver?

YCN-, I see that you've worked out the calculations for the sample rates, but where in my driver would I give these rates to the I2S driver?

I hope you guys are still around and watching this thread. It's been an immense help so far.

Thanks!

### Re: STICKY: The I2S sound thread.

Posted: Fri Sep 08, 2017 5:04 am
Hi ,

Can anybody help me with interfacing tlv320aic3254 or tlv320aic3120 with raspberry pi...?

the rpi Linux kernel main line doesn't have an entry for these IC's.

Thanks,
Shrikant

### Re: STICKY: The I2S sound thread.

Posted: Fri Sep 08, 2017 7:54 am
Can Rf Daughter board such as [url] https://www.ettus.com/product/details/DBSRX2[/url ]from Ettus research with Raspbery pi GPIO for Receiving/Transmitting RF signals.

### Re: STICKY: The I2S sound thread.

Posted: Thu Sep 28, 2017 8:18 am
New Stretch OS

Does anybody know how this new version affect I2S issues. e.g. do I still need to include my-loader.ko to enable capture, or does it come with built in drivers for both in and out I2S

### Re: STICKY: The I2S sound thread.

Posted: Thu Sep 28, 2017 11:00 am
With the current Raspbian Stretch and Jessie kernels you just need to use a devicetree overlay like this one:

Code: Select all

``````/dts-v1/;
/plugin/;

/ {
compatible = "brcm,bcm2708";

fragment@0 {
target = <&sound>;
__overlay__ {
compatible = "simple-audio-card";
simple-audio-card,name = "Dual";

status="okay";

format = "i2s";

r_cpu_dai: cpu {
sound-dai = <&i2s>;

/* example TDM slot configuration
dai-tdm-slot-num = <2>;
dai-tdm-slot-width = <32>;
*/
};

r_codec_dai: codec {
sound-dai = <&codec_in>;
};
};

format = "i2s";

p_cpu_dai: cpu {
sound-dai = <&i2s>;

/* example TDM slot configuration
dai-tdm-slot-num = <2>;
dai-tdm-slot-width = <32>;
*/
};

p_codec_dai: codec {
sound-dai = <&codec_out>;
};
};
};
};

fragment@1 {
target-path = "/";
__overlay__ {
codec_out: spdif-transmitter {
#size-cells = <0>;
#sound-dai-cells = <0>;
compatible = "linux,spdif-dit";
status = "okay";
};
#size-cells = <0>;
#sound-dai-cells = <0>;
compatible = "linux,spdif-dir";
status = "okay";
};
};
};

fragment@2 {
target = <&i2s>;
__overlay__ {
#sound-dai-cells = <0>;
status = "okay";
};
};
};

/* compile with:
dtc -@ -H epapr -O dtb -o dual.dtbo -Wno-unit_address_vs_reg dual.dts
*/``````
This overlay instantiates a generic I2S sound card with playback device hw:Dual,0 and capture device hw:Dual,1 using the upstream linux simple-audio-card, spdif-receiver and spdif-transmitter drivers. Despite their name the spdif drivers can also be used for 16 and 24 bit audio output.

Replace the generic spdif codecs with real ones (eg pcm5122) if needed.

If you need some fixed bclk ratio use the the tdm slot settings (the commented-out example in the overlay would set a fixed bclk ratio of 64 - 2 slots of 32 cycles each).

In addition to I2S left and right justified and DSP A and DSP B modes are available as well.

so long,

Hias

### Re: STICKY: The I2S sound thread.

Posted: Sun Oct 01, 2017 6:57 am
Thanks for that, but forgive my ignorance about device trees as I can't get it to work. I have done the following;

* saved your text as dual.dtb
* compiled with the dtb line you suggested
* this generated 'dual.dtbo'
* which I saved in /boot/overlays/dual.dtbo
* then I edited /boot/config.txt to include:
dtoverlay=dual
dtoverlay=i2s-mmap
dtoverlay=rpi-dac
dtoverlay=snd-soc-rpi-dac
dtoverlay=snd-soc-core
dtoverlay=pcm1794a
dtoverlay=snd-soc-pcm1794a
dtoverlay=snd-soc-bcm2708-i2s
dtoverlay=bcm2708-i2s
dtoverlay=bcm2708-dmaengine

* when reboot no hw 'Dual' port was created. What am I doing wrong?

### Re: STICKY: The I2S sound thread.

Posted: Mon Oct 02, 2017 7:43 am
mjubes wrote:
Sun Oct 01, 2017 6:57 am
* then I edited /boot/config.txt to include:
dtoverlay=dual
dtoverlay=i2s-mmap
dtoverlay=rpi-dac
dtoverlay=snd-soc-rpi-dac
dtoverlay=snd-soc-core
dtoverlay=pcm1794a
dtoverlay=snd-soc-pcm1794a
dtoverlay=snd-soc-bcm2708-i2s
dtoverlay=bcm2708-i2s
dtoverlay=bcm2708-dmaengine

Remove all dtoverlay lines except for dtoverlay=dual

so long,

Hias

### Re: STICKY: The I2S sound thread.

Posted: Tue Oct 03, 2017 7:08 am
>Remove all dtoverlay lines except for dtoverlay=dual

Thanks. That worked !!

Well, it worked for Fletch, not for Jessie, which still seems to need my-loader.ko

### Re: STICKY: The I2S sound thread.

Posted: Tue Oct 03, 2017 9:58 pm
mjubes wrote:
Tue Oct 03, 2017 7:08 am
Well, it worked for Fletch, not for Jessie, which still seems to need my-loader.ko
Ah, you're right, the kernel in Raspbian Jessie is too old - I had thought it had been updated as well.

In this case you can use "rpi-update" to get the latest kernel version - then the DT overlay will work on Jessie as well.

so long,

Hias

### Re: STICKY: The I2S sound thread.

Posted: Thu Oct 05, 2017 9:13 am
>Ah, you're right, the kernel in Raspbian Jessie is too old

Thanks. Just for information, it (sort of works) with Jessie and 4.9.28, but still needs my-loader.ko to be present!

### Re: STICKY: The I2S sound thread.

Posted: Tue Oct 31, 2017 10:09 am
Hello,

I have been working on getting I2S up and running on my rPi3B for quite a while now, and was just about 75% of the way through the instructions I found on this thread (Thank you so much!). But, then we transitioned from Jessie to Stretch and I am wondering if I am still on the right path. I am also wondering if perhaps somebody has already done what I am trying to do and I am making it much more difficult than it is. Here is what I am attempting to do:

Long Term: Pass generic I2S data to/from a connected TI evaluation board (provides a header for Bit Clock, L/R Clock, Serial Data In, Serial Data Out). Also want to pass generical I2C commands to the same board to control various IC's on the board. rPi3B will be master for both I2S and I2C. Ideally, I would like to directly set all I2S parameters easily from a GUI.

Short Term: I would be elated if I could just pass 44.1/16bit audio to/from rPi3B connected to a PSIA header on a TI evaluation board.

Should I simply step through the same procedure outlined in this thread or is there:

a) something about Raspbian Stretch that would make this process unecessary?
b) someone who has already made a generic overlay I could just "copy-n-paste" into the rPi3B to get up and running?

Cody

### Re: STICKY: The I2S sound thread.

Posted: Mon Nov 06, 2017 5:41 pm
HiassofT wrote:
Thu Sep 28, 2017 11:00 am
With the current Raspbian Stretch and Jessie kernels you just need to use a devicetree overlay like this one:

Code: Select all

``````/dts-v1/;
/plugin/;

/ {
compatible = "brcm,bcm2708";

fragment@0 {
target = <&sound>;
__overlay__ {
compatible = "simple-audio-card";
simple-audio-card,name = "Dual";

status="okay";

format = "i2s";

r_cpu_dai: cpu {
sound-dai = <&i2s>;

/* example TDM slot configuration
dai-tdm-slot-num = <2>;
dai-tdm-slot-width = <32>;
*/
};

r_codec_dai: codec {
sound-dai = <&codec_in>;
};
};

format = "i2s";

p_cpu_dai: cpu {
sound-dai = <&i2s>;

/* example TDM slot configuration
dai-tdm-slot-num = <2>;
dai-tdm-slot-width = <32>;
*/
};

p_codec_dai: codec {
sound-dai = <&codec_out>;
};
};
};
};

fragment@1 {
target-path = "/";
__overlay__ {
codec_out: spdif-transmitter {
#size-cells = <0>;
#sound-dai-cells = <0>;
compatible = "linux,spdif-dit";
status = "okay";
};
#size-cells = <0>;
#sound-dai-cells = <0>;
compatible = "linux,spdif-dir";
status = "okay";
};
};
};

fragment@2 {
target = <&i2s>;
__overlay__ {
#sound-dai-cells = <0>;
status = "okay";
};
};
};

/* compile with:
dtc -@ -H epapr -O dtb -o dual.dtbo -Wno-unit_address_vs_reg dual.dts
*/``````
This overlay instantiates a generic I2S sound card with playback device hw:Dual,0 and capture device hw:Dual,1 using the upstream linux simple-audio-card, spdif-receiver and spdif-transmitter drivers. Despite their name the spdif drivers can also be used for 16 and 24 bit audio output.

Replace the generic spdif codecs with real ones (eg pcm5122) if needed.

If you need some fixed bclk ratio use the the tdm slot settings (the commented-out example in the overlay would set a fixed bclk ratio of 64 - 2 slots of 32 cycles each).

In addition to I2S left and right justified and DSP A and DSP B modes are available as well.

so long,

Hias

How do I modify this overlay to use the PCM1794A codec instead of the standard spdif one?

### Re: STICKY: The I2S sound thread.

Posted: Mon Nov 13, 2017 5:41 am
Hello,

Currently i'm working on reading I2S output from raspberry pi 3 using STM32F4 series.
I want the STM32F4 act as master to generate the BCK and LRCK to raspberry pi which is act as slave (as shown image below) for clocking synchronize purpose.
I2S image.PNG (6.24 KiB) Viewed 14100 times
May I know how to configure the raspberry pi 3 slave mode i2s? Is it thru /boot/config.txt or others method?
Sorry I am new to the raspberry pi.

Thanks.

Regards,
rpifans

### Re: STICKY: The I2S sound thread.

Posted: Mon Nov 13, 2017 1:22 pm
When using the "simple-card " driver you can use the frame-master and bitclock-master properties in DT. See https://github.com/raspberrypi/linux/bl ... e-card.txt

so long,

Hias

### Re: STICKY: The I2S sound thread.

Posted: Thu Dec 14, 2017 2:01 am
Heya all

Is it possible to run 4 digital Mems mics off any Pi board ?

as i understand it's 2 mics to an I2S channel so you would need 2x i2s required, if thats correct :/

thanks !!!

### Re: STICKY: The I2S sound thread.

Posted: Wed Dec 20, 2017 4:03 pm
Hi all,
I want to achieve something similar, forgive me my ignorance, I read it all, but I'm not deep enough into coding I fear.

I have a USB Sound Card and an I2S capture/play device (basically a mobile broadband network board, which has an I2S interface), one shall play the capture of another (use case: phone call on the USB device)

I copied above dt overlay, "Dual" device appears in aplay and arecord -L. On i2s I can't even play out a sound file. I2s accepts S16_LE and S24_LE while the actual device connected to the i2s accept S16_BE I understand (terminology is a bit different: master, short sync, PCMA, 2048k BCLK, 8k Sample, 16 Bit Linear, MSB).

I understand arecord | aplay would be able to convert, but I need to able to actually PLAY out S16_BE or whatever on i2s which is currently not possible.

Obviously (?) I need to change something in the dt_overlay. but I'm totally lost here. Can someone translate LE/BE, sampling rates, etc. into what I need to put into the overlay ?

How do I become clock slave? Leave out frame-master/bitclock-master?

How do I enable 8k sampling rate?

How do I enable MSB/Big Endian ?

Thank you SO MUCH!

### Re: STICKY: The I2S sound thread.

Posted: Wed Jan 03, 2018 9:48 pm
Is full duplex audio possible over I2S on the pi? I successfully got a pair of Digital MEMS microphones up and running using Paul Creaser's my_loader module. This allow me to record sound and access input audio via an application I'm writing that uses a thin wrapper around ALSA.

I then connected a simple DAC to the other data line (sharing clock and word select lines). I was then (to my surprise) able to playback audio via the device described by the my_loader module no problem. Only when I tried operating i2s in full duplex did I get problems. DMESG reveals this cryptic error . .

Code: Select all

``[   87.306162] bcm2835-i2s 20203000.i2s: ASoC: can't set 20203000.i2s hw params: -16``
I then came here and discovered dt-overlays and tried using the "dual" overlay from a few posts up (which I have saved as a gist). This dual overlay works for sound output, but not for input. Strangely, I noticed the only audible input happens when I pull the jack in and out of the DAC module!? I get the same error described above if I try and open the device as full-duplex.

1) Is full duplex possible over i2s using the simple devices I have purchased?
2) Is it possible atall?
3) If it is, can someone give me a clue where to look to get this working?
4) If it is impossible, what is a good full-duplex solution that doesn't involve USB?

### Re: STICKY: The I2S sound thread.

Posted: Thu Jan 04, 2018 9:18 am
I tend to say yes, at least theoretically I was able to do full duplex. (will update during the day, I hope).
Did you you the same parameter for play/capture (sampling rate, endian,...).
I yesterday started aplay|arecord and aplay|arecord simultaneously and in the opposite direction, but with no sound signal attached yet.
But I patched the i2s module (4.9.67) so that it would support the needed sound format.
Are you on stretch ? You woulnd't need "my_loader" in that case and I think the overlay is also for the new setup.

### Re: STICKY: The I2S sound thread.

Posted: Thu Jan 04, 2018 12:23 pm
Thanks for the response @targa. I'm on ..

Code: Select all

``````Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 9.1 (stretch)
Release:	9.1
Codename:	stretch``````
Re sampling rate/endian, I used JUCE to give me a thin wrapper around ALSA, so definitely sample rate, and almost definitely endian.

Note using the dt-overlay in this gist, I couldn't get mic data in using arecord at all.