User avatar
Maash
Posts: 31
Joined: Tue Aug 23, 2016 10:18 am

Re: I2S Success (at last) !

Tue Aug 22, 2017 11:50 am

Interestingly also my portaudio problems went away with new Kernel.
More like a comfyman...

shivasiddharth
Posts: 11
Joined: Thu Aug 24, 2017 12:05 pm

Re: I2S Success (at last) !

Thu Aug 24, 2017 12:08 pm

I have used the Google voice hat's device tree overlay to get the I2S mic and amp working.. here is the detailed post. Hope someone finds it useful. https://www.hackster.io/shiva-siddharth ... hat-9f96ca

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: I2S Success (at last) !

Sat Sep 02, 2017 4:10 am

Hi,

I'm trying to write a driver for an audio board with a CS42448 codec that uses the PLLD clock on the RPi. I've been through all the posts I can find on this issue, and none seem to point to ways to accomplish this. Most of the posts I've found point to deprecated kernels that don't use the bcm2835_i2s.c file to set clocks. If anyone is out there still checking in on this post, here are a couple questions that I hope are somewhat basic:

1. On current kernels (4.9.y) my suspicion is that the bcm2708_i2s module is no longer available and that you have to use the 2835_i2s module now. Is this correct?
2. Is it possible to set the I2S clocks using the 2835_i2s module? If so, does anyone have a hint as to how?
3. It seems that most of the people who were successful with I2S have used some sort of "loader" module that creates a link between the CPU and codec DAI streams. However, all of the boards in the repository (/sound/soc/bcm/) just use device tree overlays. I've been able to compile an overlay for my board, but it doesn't seem to link the two streams. Is a "loader" module necessary to do this?

Eternal gratitude to anyone who can help with these issues.

Cheers,
Colin

Mazerunner
Posts: 1
Joined: Sun Mar 04, 2018 6:26 pm

Re: I2S Success (at last) !

Sun Mar 04, 2018 6:40 pm

@ LisaJK
Hii
I happened to see your post and I'm working with the Knowles Mic on raspberry pi 3 .I've followed the adafruit I2S mems mic guide to set it up with my pi 3 ...I've loaded and compiled the kernel module driver with the following link guide including the wiring but my VU meter doesn't move from 00 when I run arecord and my Knowles Mic doesn't record anything,Also im using a USB port to power up my raspberry pi 3 do you think could be a factor of less power?.Can you please guide me on how you set up and if the link I'm following is accurate for the Knowles Mic .
https://learn.adafruit.com/adafruit-i2s ... g-and-test
God Bless you for the help!

DiegoCabral
Posts: 3
Joined: Tue Mar 13, 2018 11:51 am

Re: I2S Success (at last) !

Tue Mar 13, 2018 1:40 pm

Mazerunner wrote:
Sun Mar 04, 2018 6:40 pm
@ LisaJK
Hii
I happened to see your post and I'm working with the Knowles Mic on raspberry pi 3 .I've followed the adafruit I2S mems mic guide to set it up with my pi 3 ...I've loaded and compiled the kernel module driver with the following link guide including the wiring but my VU meter doesn't move from 00 when I run arecord and my Knowles Mic doesn't record anything,Also im using a USB port to power up my raspberry pi 3 do you think could be a factor of less power?.Can you please guide me on how you set up and if the link I'm following is accurate for the Knowles Mic .
https://learn.adafruit.com/adafruit-i2s ... g-and-test
God Bless you for the help!
@Mazerunner, first get a good power supply 5V with at least 2A output to provide power via mini-usb, this is a main problem for many Pi communication. Have you checked if the module is installed and running? enabled I2S on the config.txt? All your setup following step by step the tutorial you've mentioned on adafruit should give you SCLK on pin 18, FS/WS on pin 19 and SD on pin 20, please check all the steps on terminal to see if ther is any error. Do you have an oscilloscope to check those pins?

Cronus99
Posts: 11
Joined: Wed Aug 15, 2018 9:15 pm
Location: India

Re: I2S Success (at last) !

Fri Sep 21, 2018 7:14 pm

Hi,

I have been trying to set up i2s on my raspberry pi 3 model B as well, with no luck. I followed this adafruit guide: https://learn.adafruit.com/adafruit-i2s ... g-and-test

Right now these are the waveforms im getting while running $ arecord -D plughw:1 -c2 -r 48000 -f S32_LE -t wav -V stereo -v file_stereo.wav

1. LRCLK (BCM 19, pin 35)



2. BCLK (BCM 18, pin 12):



LRCLK seems to look fine (oddly shaped though), but BCLK looks like a small signal triangle wave? I have tried changing power supplies as well, but it was the same everytime. Could anyone take a look and shed some light on this?
Attachments
lrclk.gif
lrclk.gif (96.49 KiB) Viewed 1053 times
bclk.gif
bclk.gif (78.04 KiB) Viewed 1053 times

HiassofT
Posts: 171
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: I2S Success (at last) !

Sat Sep 22, 2018 7:08 am

Are you maybe using a DSO 138 or a similar toy to check the signals? If yes the result is expected, bclk will be about 3MHz and the DSO 138 has a maximum bandwidth of 200kHz.

so long,

Hias

emnaa
Posts: 6
Joined: Tue Mar 12, 2019 2:58 pm

Re: I2S Success (at last) !

Tue Mar 12, 2019 3:08 pm

hello,
I need to extract two signals from a raspberry pi 3 which are bitclock and wordselect (I2S). In fact i will use the rpi3 as master and transfer the bitclock and wordselect to an other card called PCM1862. Is it possible to use this code (Ionly want the two clocks)?. Please any help!

Enabling I2S
............

The default ALSA sound devices supported by the Raspberry Pi 3 are PWM audio output jack and HDMI output. To run this demonstration I2S input and output needs to be enabled. The goal is to use a simple I2S interface.

To avoid recompilation of the Linux kernel a loadable kernel module is used. This enables the driver for the I2S peripheral inside the BCM2708 device to be loaded dynamically.

A full description of how to do this can be found in the link below [#]_, however a brief summary of the required steps, found to work on a clean copy of Debian Jessie shipped with ``Noobs``, is show below:

.. [#] http://www.raspberrypi.org/forums/viewt ... 44&t=91237

First, update the Raspbian Linux distribution to the latest version (version 4.4.13v7 tested). This may take a few hours::

sudo apt-get update
sudo apt-get dist-upgrade

Before proceeding with the next steps, ensure you have re-booted your Raspberry Pi so that it is running the latest version of Raspbian that you have just downloaded. This can be done using the following command::

sudo reboot

Next, we need to enable I2S in device tree. To do this, edit the file ``/boot/config.txt`` to remove the comment on line 47::

dtparam=i2s=on

The sound card driver depends on the I2S peripheral and Direct Memory Access Controller modules which need to be added to file. To do this, add the following lines to ``/etc/modules`` using your favorite text editor prefixed with ``sudo`` to ensure super user privileges::

snd_soc_bcm2708
snd_soc_bcm2708_i2s
bcm2708_dmaengine

Next, download the kernel source (this may also take a long time to download and extract). The source download script requires the installation of two helper applications that are not installed by default. The installation of these is included below::

sudo apt-get install bc
sudo apt-get install libncurses5-dev
git clone http://github.com/notro/rpi-source
cd rpi-source
python rpi-source
cd ..

Now we have the kernel source downloaded, we can modify the driver source and build the modules needed to enable I2S. We require two modules --- one called ``loader`` which instantiates the sound-card module and the other is ``asoc_simple_card`` which is the sound card driver itself.

For further information on building and loading modules under Linux the link below provides a useful reference [#]_.

.. [#] http://www.cyberciti.biz/tips/build-lin ... -tree.html

Next we need to build the simple sound card driver::

mkdir snd_driver
cd snd_driver
cp ../linux/sound/soc/generic/simple-card.c ./asoc_simple_card.c

Note that the directory ``linux`` will appended with a long hash. Please use this directory in the above copy command.
E.g. ``/linux-e88b69aa792dbe2b289ff528c0d07303068aa0aa/``.

The file needs a small modification to work around a bug (uninitialized BCLK ratio, causing the default of 100 bit clocks per I2S frame rather than the required 64 bit). To make this correction, at the end of function ``asoc_simple_card_dai_init`` around line number 213, add the following source lines::

ret = snd_soc_dai_set_bclk_ratio(cpu, 64);
pr_alert("BCLK ratio set to 64!\n");

Use this makefile to build the module.
i.e. copy the contents into ``Makefile``. Note that the last line must be indented using a tab character rather than using spaces to avoid a build error::

obj-m := asoc_simple_card.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

And finally build the module, insert it into the kernel, and prepare for the next step::

make
sudo insmod asoc_simple_card.ko
cd ..


You should see a console output similar to this::

[email protected]:~/snd_driver $ make
make -C /lib/modules/4.4.13-v7+/build SUBDIRS=/home/pi/snd_driver modules
make[1]: Entering directory '/home/pi/linux-e88b69aa792dbe2b289ff528c0d07303068aa0aa'
CC [M] /home/pi/snd_driver/asoc_simple_card.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/pi/snd_driver/asoc_simple_card.mod.o
LD [M] /home/pi/snd_driver/asoc_simple_card.ko
make[1]: Leaving directory '/home/pi/linux-e88b69aa792dbe2b289ff528c0d07303068aa0aa'

Next we build the loader which presents the device to the OS::

mkdir loader
cd loader

Copy the contents of the source from the forum post linked [#]_ below into a new file called ``loader.c``.

For reference, a copy of the relevant code from the post is included here::

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/platform_device.h>
#include <sound/simple_card.h>
#include <linux/delay.h>
/*
modified for linux 4.1.5
inspired by https://github.com/msperl/spi-config
with thanks for https://github.com/notro/rpi-source/wiki
as well as Florian Meier for the rpi i2s and dma drivers

to use a differant (simple-card compatible) codec
change the codec name string in two places and the
codec_dai name string. (see codec's source file)

fmt flags are set for vanilla i2s with rpi as clock slave

N.B. playback vs capture is determined by the codec choice
*/

void device_release_callback(struct device *dev) { /* do nothing */ };

static struct asoc_simple_card_info snd_rpi_simple_card_info = {
.card = "snd_rpi_simple_card", // -> snd_soc_card.name
.name = "simple-card_codec_link", // -> snd_soc_dai_link.name
.codec = "snd-soc-dummy", // -> snd_soc_dai_link.codec_name
.platform = "3f203000.i2s",
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFM,
.cpu_dai = {
.name = "3f203000.i2s", // -> snd_soc_dai_link.cpu_dai_name
.sysclk = 0
},
.codec_dai = {
.name = "snd-soc-dummy-dai", // -> snd_soc_dai_link.codec_dai_name
.sysclk = 0
},
};
static struct platform_device snd_rpi_simple_card_device = {
.name = "asoc-simple-card", //module alias
.id = 0,
.num_resources = 0,
.dev = {
.release = &device_release_callback,
.platform_data = &snd_rpi_simple_card_info, // *HACK ALERT*
},
};
int hello_init(void)
{
const char *dmaengine = "bcm2708-dmaengine"; //module name
int ret;

ret = request_module(dmaengine);
pr_alert("request module load '%s': %d\n",dmaengine, ret);
ret = platform_device_register(&snd_rpi_simple_card_device);
pr_alert("register platform device '%s': %d\n",snd_rpi_simple_card_device.name, ret);

pr_alert("Hello World :)\n");
return 0;
}
void hello_exit(void)
{// you'll have to sudo modprobe -r the card & codec drivers manually (first?)
platform_device_unregister(&snd_rpi_simple_card_device);
pr_alert("Goodbye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_DESCRIPTION("ASoC simple-card I2S setup");
MODULE_AUTHOR("Plugh Plover");
MODULE_LICENSE("GPL v2");


Make sure that line 21 is changes as shown below to ensure the Raspberry Pi 3 is the I2S master and the Microphone is the slave::

.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS,


.. [#] viewtopic.php?p=914713#p914713

Copy the below contents into ``Makefile`` again ensuring that the indent is a tab character rather than spaces::

obj-m := loader.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

And finally build the module and insert it into the kernel::

make
sudo insmod loader.ko
cd ..


To verify that the I2S audio device driver module has been loaded and is accessible, you run the following command::

arecord -l

This should generate a list of available ALSA captures devices something like this::

**** List of CAPTURE Hardware Devices ****
card 1: sndrpisimplecar [snd_rpi_simple_card], device 0: simple-card_codec_link snd-soc-dummy-dai-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0

The physical sound card device presents a stereo I2S device to Linux. However, some Voice Assistant software such as Amazon's Alexa, requires access to a mono capture device. To present the stereo sound card as a mono device it is necessary to create a virtual mono capture device connected to the physical stereo capture device in ALSA. The microphone audio sent from the Microphone is a mono signal repeated on both stereo channels and so either channel will provide the required signal. The virtual mono capture device then needs to be set as the default device so that the client software picks it first when searching for input devices.

To setup the virtual capture device, modify the file ``.asoundrc`` found in the home directory as follows::

pcm.monocard {
type plug
slave.pcm "plughw:1,0"
slave.channels 2
slave.rate 16000
}

ctl.monocard {
type hw
card 1
device 0
}

pcm.!default {
type asym
playback.pcm {
type hw
card 0
}
capture.pcm {
type plug
slave.pcm "monocard"
}
}

ctl.!default {
type asym
playback.pcm {
type hw
card 0
}
capture.pcm {
type plug
slave.pcm "monocard"
}
}

The above configuration keeps the default playback device as the 3.5mm jack on the Raspberry Pi however this can be changed to the I2S bus by changing the contents of for both ``pcm.!default {`` and ``ctl.!default {`` so that the ``playback.pcm {`` entries match ``capture.pcm``.

To apply the changes made in ``.asoundrc`` and enable the virtual capture device either reboot the Raspberry Pi or use the following command::

sudo /etc/init.d/alsa-utils restart

Following the instructions given so far will enable the I2S soundcard in the current session. To make it available after reach reboot, it is necessary to load the modules at boot time. You can do this by adding a boot-time cron job to run the following script. Save this script as ``load_i2s_driver.sh`` in your home directory::

cd ~
sudo insmod snd_driver/asoc_simple_card.ko
sudo insmod loader/loader.ko

The script can be auto-run at boot time by adding the following line in the editor window that appears after typing ``crontab -e``::

@reboot /home/pi/load_i2s_driver.sh

HiassofT
Posts: 171
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: I2S Success (at last) !

Tue Mar 12, 2019 5:59 pm

I'm not exactly sure what you are trying to achieve, but if you just want some generic driver simply use

Code: Select all

dtoverlay=hifiberry-dac
The overlay / card driver doesn't require any specific hardware to be present.

so long,

Hias

emnaa
Posts: 6
Joined: Tue Mar 12, 2019 2:58 pm

Re: I2S Success (at last) !

Tue Mar 12, 2019 7:14 pm

I want to extract two signals wordselect and bitclock from rpi3 and DAC es9023: and use them as input to an other card PCM 1862. this card is in fact a slave of rpi3+dac and i will generate also two other signal left and right to pcm1862 and create dout=data i2s. firstly, i need to generate the clocks. i have install the driver https://github.com/SatoruKawase/I-Sabre-K2M. and i'm searching how to extract clocks. pzz help if sone has an idea!

emnaa
Posts: 6
Joined: Tue Mar 12, 2019 2:58 pm

Re: I2S Success (at last) !

Wed Mar 13, 2019 9:20 am

Hi,
I want to extract two signals wordselect and bitclock from rpi3 and DAC es9023: and use them as input to an other card PCM 1862. this card is in fact a slave of rpi3+dac and i will generate also two other signal left and right to pcm1862 and create dout=data i2s. firstly, i need to generate the clocks. i have installed the driver https://github.com/SatoruKawase/I-Sabre-K2M. and i'm searching how to extract clocks. pzz help if sone has an idea!
I was trying with this code. Is it ok?
sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot
sudo nano /boot/config.txt
dtparam=i2s=on
sudo nano /etc/modules
snd_soc_bcm
snd_soc_bcm2708_i2s
bcm2708_dmaengine
Ismod | grep snd
sudo apt-get install bc
sudo apt-get install libncurses5-dev
git clone https://github.com/notro/rpi-source
cd rpi-source
python rpi-source
cd ..
sudo apt-get install gcc-4.9 g++-4.9
sudo apt-get install device-tree-compiler
cat /proc/version
cd ./I-Sabre-K2M
make
sudo make modules-install
make dtbs
sudo make install_dtbo
sudo nano /boot/config.txt
dtoverlay=i-sabre-k2m
dtparam=i2c-arm=on
sudo reboot
applay-l
sudo mount -t debugfs debugs /sys/kernel/debug //to compile i2s module
sudo cat /sys/kernel/debug/asoc/platforms
git clone https://github.com/thenaran/linux-rpi
cd /linux-rpi/sound/soc/bcm
sudo nano rpi-dac.c
sudo nano bcm2708-i2s.c
sudo nano bcm2708-i2s.h
i want to know how to use those files (activates) to make them working: I want to test the pins if they will send the clock.

Return to “Interfacing (DSI, CSI, I2C, etc.)”