Orbital6
Posts: 138
Joined: Sat Aug 08, 2015 6:32 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Sun Feb 21, 2016 1:39 pm

Is there a way to change the BCLK per LRCK value on the pi? It seems the pi only likes 32 BCLK / LRCK when the PCM1803A ADC IC i'm working with features 64 BCLK / LRCK as a minimum.

I think i need to change the bclk_ratio value to one that fits the bclk/LRCK value of the device and one that is an integer division (such as 80(?) or 100). Using plugh's glue code, would i need to change this value in bcm2708-i2c.c in ~/linux... before making the new kernel module, or would i change it in my OS's copy of bcm27.. (I think this lives in usr/src/linux...).

May or may not be interesting, but the PCM1803A is a 24-bit device though makes an almost perfect capture with S16_LE.

I can't seem to get a non-fuzzy recording at S24_LE and my logic analyser keeps showing the bclk/lrck as 50 (the default value), which means none of my changes pre-compilation are working. Which means i'm being a n00b and can do with a little hand : p

I'll be grateful for any help that comes my way!

jstsch
Posts: 4
Joined: Fri May 30, 2014 1:19 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Sat Mar 19, 2016 7:36 pm

I want to connect a SGTL5000 ADC/DAC, which is mounted on a Teensy Audio Adapter board (http://www.pjrc.com/store/teensy3_audio.html). Right now I'm experimenting with the R-PI 3, but I want to eventually use a Zero.

Image

Can anyone give me any pointers where to get started? I read that the R-Pi is not able to generate a MCLK. But the SGTL5000 can also use its PLL to run on a 12MHz USB clock, or on the R-Pi 19.2MHz clock.

I also saw that there is a kernel module available: https://github.com/raspberrypi/linux/bl ... sgtl5000.h So, should be easy, right? ;) How do I wire things up?

boga
Posts: 1
Joined: Mon Mar 21, 2016 8:39 am

Re: I2S sound: Anyone got it running? (answer is yes!)

Mon Mar 21, 2016 9:47 am

Hi! I am trying to get Texas Instruments TLV320AIC3007 working with RPi (specifically with RPi2 or RPi3. I think it shouldn't matter).

Here's the thing. I am an electronics engineer and I have created 4-layer PCB for a project containing TLV320AIC3007. The connections are as follows:

codec ----- RPi

BCLK ------- BLCK
DIN ------- DOUT
DOUT ------- DIN
WCLK ------- LRCLK
MCLK ------- 0 Resistor ------- GND

I also know that the chip is supported by ALSA driver. It is listed here.

As I was in a hurry I was unable to make too much research. Therefore I was reading here and there about getting RPi to interface with audio Codecs. I know for example the Koalo's blog etc.

After reading different sources it is still unclear to me how to correctly clock / synchronize the I2S system regarding to Raspberry Pi.

Do I understand correctly that codecs which can generate their own clock are usually recommended for using with RPi?
I can see that WM8731, TLV320AIC23 and TDAA1541a for example can generate their own clock.

If I need to create external clock source for TLV320AIC3007 as a workaround then it is not a problem. I can create something.

Are the Codecs usually configured to be I2S masters to get them to work with RPi (the ones that are working nicely)? Or are they slaves?

I will also continue to make my own research and read the datasheet carefully. But I thought that there are many people here who have been down this road and understand I2S interfacing Codecs with RPi better than me. Can somebody help me?
Attachments
RPi2_Header_Connections2.png
RPi Connections Schematic
RPi2_Header_Connections2.png (48.65 KiB) Viewed 9734 times
TLV320AIC3007_Connections.png
Codec Schematic
TLV320AIC3007_Connections.png (60.04 KiB) Viewed 9734 times

vjvarada
Posts: 14
Joined: Wed Mar 16, 2016 7:12 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Sat Mar 26, 2016 6:05 pm

@LisaJK How did you get your Knowles microphone running?
did you have to compile bcm2708-i2s.c to have bclk_ratio as 64 like the datasheet?
using the default configurations, im seeing sane activity on the BCLK and WS lines supplied from the raspberry pi, yet the DOUT doesn't give out anything, when trying to record using S24

When I try S32, I get white noise, and some activity on DOUT.

I used the loader from https://github.com/skakri/asoc-i2s-loader and changed to slave mode.

Any clue what i'm doing wrong?

Orbital6
Posts: 138
Joined: Sat Aug 08, 2015 6:32 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Mon Mar 28, 2016 7:54 pm

vjvarada wrote:@LisaJK How did you get your Knowles microphone running?
did you have to compile bcm2708-i2s.c to have bclk_ratio as 64 like the datasheet?
using the default configurations, im seeing sane activity on the BCLK and WS lines supplied from the raspberry pi, yet the DOUT doesn't give out anything, when trying to record using S24

When I try S32, I get white noise, and some activity on DOUT.

I used the loader from https://github.com/skakri/asoc-i2s-loader and changed to slave mode.

Any clue what i'm doing wrong?
This is the exact same issue i'm having. If anyone can help then i'd be very grateful!

vjvarada
Posts: 14
Joined: Wed Mar 16, 2016 7:12 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Tue Mar 29, 2016 5:26 pm

Orbital6 wrote:
vjvarada wrote:@LisaJK How did you get your Knowles microphone running?
did you have to compile bcm2708-i2s.c to have bclk_ratio as 64 like the datasheet?
using the default configurations, im seeing sane activity on the BCLK and WS lines supplied from the raspberry pi, yet the DOUT doesn't give out anything, when trying to record using S24

When I try S32, I get white noise, and some activity on DOUT.

I used the loader from https://github.com/skakri/asoc-i2s-loader and changed to slave mode.

Any clue what i'm doing wrong?
This is the exact same issue i'm having. If anyone can help then i'd be very grateful!

I connected a 100Kohm resistor from the DATA pin to gnd because im using a single microphone according to the knowles microphone datasheet.

Initially my SELECT line was connected to gnd, which didnt work at all, once I connected it to VDD, it now records!!

Only problem is that the quality is really bad, and my voice sounds like Darth Vader. it might also be because I hand soldered the mic, and damaged it, I cant be sure.

I used everything else default (as mentioned on previous posts) and the loader code mentioned in my previous post BTW

Orbital6
Posts: 138
Joined: Sat Aug 08, 2015 6:32 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Wed Mar 30, 2016 7:02 pm

vjvarada wrote:
Orbital6 wrote:
vjvarada wrote:@LisaJK How did you get your Knowles microphone running?
did you have to compile bcm2708-i2s.c to have bclk_ratio as 64 like the datasheet?
using the default configurations, im seeing sane activity on the BCLK and WS lines supplied from the raspberry pi, yet the DOUT doesn't give out anything, when trying to record using S24

When I try S32, I get white noise, and some activity on DOUT.

I used the loader from https://github.com/skakri/asoc-i2s-loader and changed to slave mode.

Any clue what i'm doing wrong?
This is the exact same issue i'm having. If anyone can help then i'd be very grateful!

I connected a 100Kohm resistor from the DATA pin to gnd because im using a single microphone according to the knowles microphone datasheet.

Initially my SELECT line was connected to gnd, which didnt work at all, once I connected it to VDD, it now records!!

Only problem is that the quality is really bad, and my voice sounds like Darth Vader. it might also be because I hand soldered the mic, and damaged it, I cant be sure.

I used everything else default (as mentioned on previous posts) and the loader code mentioned in my previous post BTW
Thank you for getting back to me, and well done on figuring your issue out. I'm working from the PCM1803A (24-bit) and i don't recall it having any pull downs necessary. My issue is how you got the 64 BCLK / LRCK bclk ratio working (doesn't sound like you have - that darth vadar sound is a bclk issue - try inverting your bclk polarity). I'm not sure if i wrote before, but before my hardware went kaput, i was able to make decent recordings capturing at 16-bit (not 24 bit). This was truncating 8 bits of data though. Let me know how you get on!

tagadac
Posts: 1
Joined: Wed Apr 06, 2016 3:26 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Wed Apr 06, 2016 3:30 pm

Hi !

I want to use the SGTL5000, I successfully managed to recompile the kernel to add the codecs. But the Raspberry Pi still can't detect it...
Here is my question on StackEchange : http://raspberrypi.stackexchange.com/qu ... 0-with-i2s

Thank you very much !

monica2
Posts: 3
Joined: Sat Apr 16, 2016 10:49 pm

Re: The I2S sound thread.

Sat Apr 16, 2016 10:59 pm

Hi all,
I'm completely new to Raspberrypi2, and therefore know nothing about the coding, etc. All I want is to use it as a music streamer. I keep reading online that this is a cheap and very good alternative to the obscenely price streamers out there. I want to connect the board via i2s to a dac chip. However, I would like that all time and frequency are derived from an external low jitter clock for both the DAC and the reaspberry board. There should be no re-clocking, just one (external) clock for the dac and raspberry.
Can someone help? Is the learning curve for doing this steep?
Thanks in advance,
Monica

User avatar
0xFF
Posts: 202
Joined: Tue Nov 20, 2012 7:52 pm
Location: Poland

Re: The I2S sound thread.

Sun Apr 17, 2016 1:16 pm

There is no master clock input for RPi I2S interface.

monica2
Posts: 3
Joined: Sat Apr 16, 2016 10:49 pm

Re: The I2S sound thread.

Sun Apr 17, 2016 4:51 pm

0xFF wrote:There is no master clock input for RPi I2S interface.

As far as I know, the lack of a dedicated input for a Masterclock should not be a problem if one knows how to do it.

User avatar
0xFF
Posts: 202
Joined: Tue Nov 20, 2012 7:52 pm
Location: Poland

Re: The I2S sound thread.

Sun Apr 17, 2016 5:15 pm

monica2 wrote:
0xFF wrote:There is no master clock input for RPi I2S interface.

As far as I know, the lack of a dedicated input for a Masterclock should not be a problem if one knows how to do it.
monica2 wrote:
0xFF wrote:There is no master clock input for RPi I2S interface.
Yes, I successfully connected I2S DAC'es:
Philips (NXP) TDA1543T
ESS ES9023
Burr-Brown PCM5102A
But none with external master clock.

In my opinion, the easiest way is to get HifiBerry DAC (https://www.hifiberry.com). It's almost plug&play solution with good documentation and support..

monica2
Posts: 3
Joined: Sat Apr 16, 2016 10:49 pm

Re: The I2S sound thread.

Sun Apr 17, 2016 5:21 pm

Do you know for a fact that a masterclock cannot in any circumstance be used? Or was it just in your experience?

User avatar
0xFF
Posts: 202
Joined: Tue Nov 20, 2012 7:52 pm
Location: Poland

Re: The I2S sound thread.

Sun Apr 17, 2016 6:11 pm

AFAIK there is no route for RPi master clock input , so there is no way to connect mater clock even with soldering iron help.
But on the other hand there seems to be many misunderstanding about master clock meaning.

Here's some explanation (in comments) from DAC developer about RPi I2S interface
http://www.dimdim.gr/2014/12/the-rasber ... rough-i2s/

or here:
https://hifiduino.wordpress.com/2014/11 ... tal-audio/

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: I2S sound: Anyone got it running? (answer is yes!)

Mon Apr 18, 2016 12:01 pm

plugh wrote:This may be of interest to a variety of people...

As I mentioned above I have successfully mated the simple-card driver with the dmic codec driver. I did it without having to rebuild the kernel and effectively* no source code changes. The 'glue' is a separate loadable kernel module, tweakable to allow use of other existing simple codec drivers for either capture or playback with the simple-card driver.
......
I may check back here in case there are questions, but I'm going to mostly be focused on my hardware project now. Hopefully this will be useful or give people some ideas...
Thank you very much! This is what I needed! I read almost the entire datasheet for my SGTL5000 and can more or less understand it, but the complexity of getting Linux to acknowledge it was about to make me give up. I feel like I could program the chip better with 2 telegraph clickers than with ALSA. The process itself would be more difficult, but at least telegraph clickers are documented!
I completely understand if you don't want to think about software anymore, but that won't stop me from asking. I get errors trying to load my hello module, but I'll address that later. You've given me lots of ideas, thank you!

-Chuckk

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: I2S sound: Anyone got it running? (answer is yes!)

Tue Apr 19, 2016 8:55 am

plugh wrote:This may be of interest to a variety of people...
Please help!
I'm following Pugh's guide and trying to adapt it to the SGTL5000 codec on a 4.4 kernel on RPi3.
The patch mentioned in Pugh's post appears to no longer be necessary, but a few other things are complaining.
I had to comment out the lines in my_loader.c with ".fmt". This is no longer part of the asoc_simple_dai struct. It's kind of misty to me just what it was needed for, so for now I just took it out, and nothing broke.

What did seem to break, however, was:
.platform = "bcm2708-i2s.0" (as cpu DAI name)

It seems to make sense to have bcm2708, as I'm on RPi 3, but I could find nothing in my kernel source tree regarding bcm2708-i2s. I found bcm2835-i2s, and tried changing the lines in my_loader.c, but it still complains when I insmod the my_loader kernel:
asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI bcm2708-i2s.0 not registered
or
asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI bcm2835-i2s.0 not registered

I have the snd-soc-bcm2835-i2s module loaded and get this error. Is this bcm2708-i2s.0 something that's supposed to be defined somewhere in another file, and has perhaps changed since Pugh wrote about it?

I believe this solution of linking the generic simple card module with arbitrary codecs deserves its own thread, if not its own page somewhere. It ought to be enough for people who buy a codec and just want it to work, without polishing it up. I am not looking to make drivers for hardware I sell, for other people to use my product, I just want to have sound on my Pi, which I intend to use for my own (professional music) purposes. The instructions for the codec itself are straightforward and very well documented; I could use it myself with Arduino, but with Raspbian, I have to deal with the entire history of ALSA, and ASoC, which is not nearly so well documented.
I would cut down Pugh's guide, though; the part about downloading kernel source, preparing to make it, menuconfig, building the modules from the main tree, those have all been written up pretty extensively around the net, but holding ASoC down and forcing it to acknowledge my hardware is way too hard and the second half of Pugh's guide addresses that. I can't yet get it to actually work, but if I can, I believe the information in it should be pinned, copied, publicized, made available to everyone who needs it without reading 28 pages of other people asking the same questions.

Any idea about the "bcm2708-i2s.0 not registered" thing?
-Chuckk

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: The I2S sound thread.

Tue Apr 19, 2016 9:09 am

monica2 wrote:Hi all,
I'm completely new to Raspberrypi2, and therefore know nothing about the coding, etc. All I want is to use it as a music streamer. I keep reading online that this is a cheap and very good alternative to the obscenely price streamers out there. I want to connect the board via i2s to a dac chip. However, I would like that all time and frequency are derived from an external low jitter clock for both the DAC and the reaspberry board. There should be no re-clocking, just one (external) clock for the dac and raspberry.
Can someone help? Is the learning curve for doing this steep?
Thanks in advance,
Monica
I haven't succeeded yet, but plenty of DAC/ codec chips are capable of taking a master clock and outputting BCLK and LRCLK based on it; I believe - I hope - you should be able to use RPi's BCLK and LRCLK as input and have it send the data in response. The RPi has no use for the master clock signal; it only needs bit clock and l/r clock to sync its data. Most DACs need master clock, but that doesn't mean the master clock has to be processed by the SoC, too. Again, I haven't actually managed to make this work, despite understanding what's supposed to happen.

-Chuckk

jstsch
Posts: 4
Joined: Fri May 30, 2014 1:19 pm

Re: The I2S sound thread.

Tue Apr 19, 2016 9:53 am

Thanks a lot Chuckk for sharing... good info. I'm very curious to your progress.

I don't know too much about kernel modules I'm afraid. But I believe there should be a module called snd-soc-bcm2708-i2s. Is it loaded? What's the output when you modprobe -v snd-soc-bcm2708-i2s and then lsmod?

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: The I2S sound thread.

Thu Apr 21, 2016 4:44 am

jstsch wrote:Thanks a lot Chuckk for sharing... good info. I'm very curious to your progress.

I don't know too much about kernel modules I'm afraid. But I believe there should be a module called snd-soc-bcm2708-i2s. Is it loaded? What's the output when you modprobe -v snd-soc-bcm2708-i2s and then lsmod?
Thanks, jstsch. I've gone with snd-soc-bcm2835-i2s. The output is "modprobe: FATAL: Module snd-soc-bcm2708-i2s is not found." But snd-soc-bcm2835-i2s is loaded. I'm running kernel 4.4.7, with the rt preempt patch.

So, regarding using a Teensy Audio Adapter with Raspberry Pi 3:

I have now:
set GPIO 4 to send a 9.6 MHz clock on startup;
created a dummy card with Carla's version of Plugh's loader;
sent my SGTL5000 through its startup / configuration procedure as mentioned in the datasheet, and as the Teensy driver does, although I changed a few values

I can see the dummy card, and I can run aplay using it, but after 10 seconds or so it returns an error and I see dmesg output like I see when the codec isn't connected at all, i.e. "I2S SYNC error!" and "DMA transfer could not be terminated".

Here is my wiring:
RPi Ground <-> G pin on TAA, the pin closest to the headphone jack
RPi 3.3 V <-> 3.3 V on TAA
For the rest I'll use the RPi physical header numbers, as in:
1 | 2
3 | 4
5 | 6
....
39 | 40
- pins 39 and 40 being the closest to the USB ports. And the numbers printed on the TAA.
RPI 12 <-> TAA 9
RPI 7 <-> TAA 11 (master clock from GPIO 4)
RPI 38 <-> TAA 13
RPI 3 <-> TAA 18
RPI 5 <-> TAA 19
RPI 40 <-> TAA 22
RPI 35 <-> TAA 23
I had some doubts as to which is TX and which is RX, but the Teensy itself has its DOUT on pin 22, so I went with that.


Here are my scripts:

gpio-clock.py: This should send a 9.6 MHz clock on GPIO 4, which I have connected to the MCLK input of the Teensy adapter.

Code: Select all

import wiringpi as wpi
wpi.wiringPiSetupGpio()
wpi.pinMode(4,3) # this should set GPIO 4, i.e. pin 7 on the header, to clock mode
wpi.gpioClockSet(4,9600000)
/etc/rc.local: to start the GPIO clock on startup

Code: Select all

............. (whatever was there before)
python /home/pi/gpio-clock.py
exit 0
Plugh / Carla's loader: (I think Plugh first shared it with a typical GPL warning, but it fell by the wayside during someone's copying... I took it from this forum in this form. It works for me, when inserted using Plugh's instructions here: viewtopic.php?p=604231#p604231 to create a dummy sound card that I THINK is supposed to send I2S data when told to, ignoring the fact that it doesn't know what chip is receiving the data.)

Code: Select all

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/platform_device.h>
#include <sound/simple_card.h>
 
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", // "dmic-codec", // -> snd_soc_dai_link.codec_name
// .platform = "bcm2708-i2s.0", // -> snd_soc_dai_link.platform_name
.platform = "3f203000.i2s",
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_CBM_CFM,
.cpu_dai = {
//   .name = "bcm2708-i2s.0", // -> snd_soc_dai_link.cpu_dai_name
.name = "3f203000.i2s", // -> snd_soc_dai_link.cpu_dai_name
//.fmt =
.sysclk = 0 },
.codec_dai = {
.name = "snd-soc-dummy-dai", //"dmic-codec", // -> snd_soc_dai_link.codec_dai_name
//.fmt = 0,
.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*
},
};
static struct platform_device snd_rpi_codec_device = {
.name = "sgtl5000-codec", // "dmic-codec", //module alias
.id = -1,
.num_resources = 0,
.dev = { .release = &device_release_callback,
},
};
 
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_codec_device);
//  pr_alert("register platform device '%s': %d\n",snd_rpi_codec_device.name, 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);
platform_device_unregister(&snd_rpi_codec_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");
I am using pigpio through Python to send I2C. I installed pigpio from here: http://abyz.co.uk/rpi/pigpio/download.html and run

Code: Select all

sudo pigpiod
to start it. I do this manually. Then I run my script that I THINK should configure my SGTL5000, a mix of the default driver configuration from the Teensy Audio Library, the startup mentioned in the datasheet, and my own parameters for using sgtl5000's PLL to calculate its master clock from the 9.6 MHz input. I used the Teensy Audio startup configs because I don't know the exact power levels it has when run through this board, but many people use it successfully with these settings, albeit on a Teensy board and not RPi.

sgtl5000-config.py:

Code: Select all

import pigpio as pig
import time
pi = pig.pi()
h = pi.i2c_open(1,0x0a,0)
 
time.sleep(0.5)
 
CHIP_ANA_POWER = 0x0030
CHIP_LINREG_CTRL = 0x0026
CHIP_REF_CTRL = 0x0028
CHIP_LINE_OUT_CTRL = 0x002C
CHIP_SHORT_CTRL = 0x003C
CHIP_ANA_CTRL = 0x0024
CHIP_PLL_CTRL = 0x0032
CHIP_DIG_POWER = 0x0002
CHIP_LINE_OUT_VOL = 0x002E
CHIP_CLK_CTRL = 0x0004
CHIP_I2S_CTRL = 0x0006
CHIP_SSS_CTRL = 0x000A
CHIP_ADCDAC_CTRL = 0x000E
CHIP_DAC_VOL = 0x0010
CHIP_ANA_HP_CTRL = 0x0022
 
pi.i2c_write_word_data(h,CHIP_ANA_POWER, 0x4060)  # VDDD is externally driven with 1.8V
pi.i2c_write_word_data(h,CHIP_LINREG_CTRL, 0x006C)  # VDDA & VDDIO both over 3.1V
pi.i2c_write_word_data(h,CHIP_REF_CTRL, 0x01F2) # VAG=1.575, normal ramp, +12.5% bias current
pi.i2c_write_word_data(h,CHIP_LINE_OUT_CTRL, 0x0F22) # LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA
pi.i2c_write_word_data(h,CHIP_SHORT_CTRL, 0x4446)  # allow up to 125mA
pi.i2c_write_word_data(h,CHIP_ANA_CTRL, 0x0137)  # enable zero cross detectors
pi.i2c_write_word_data(h,CHIP_ANA_POWER, 0x40FF) # power up: lineout, hp, adc, dac
pi.i2c_write_word_data(h,CHIP_DIG_POWER, 0x0073) # power up all digital stuff
 
#    delay(400)
time.sleep(0.4)
 
pi.i2c_write_word_data(h,CHIP_LINE_OUT_VOL, 0x1D1D) # default approx 1.3 volts peak-to-peak
#pi.i2c_write_word_data(h,CHIP_CLK_CTRL, 0x0004)  # 44.1 kHz, 256*Fs
#pi.i2c_write_word_data(h,CHIP_I2S_CTRL, 0x0130) # SCLK=32*Fs, 16bit, I2S format
#i2s = pi.i2c_read_word_data(h,CHIP_I2S_CTRL)
#anap = pi.i2c_read_word_data(h,CHIP_ANA_POWER)
#clk = pi.i2c_read_word_data(h,CHIP_CLK_CTRL)
#mi2s = i2s & 0b1111111000000000
#i2s = mi2s | 0b0000000110110000
#manap = anap & 0b1111101011111111
anap = 0x40FF | 0b0000010100000000
#mclk = clk & 0b1111111111000000
#clk = mclk | 0b0000000000000111
#pi.i2c_write_word_data(h,CHIP_PLL_CTRL,0xa3d7)
pi.i2c_write_word_data(h,CHIP_PLL_CTRL,0x9687)
pi.i2c_write_word_data(h,CHIP_CLK_CTRL,0x0007)  # 44.1 kHz, 256*Fs
pi.i2c_write_word_data(h,CHIP_I2S_CTRL,0x01b0) # SCLK=32*Fs, 16bit, I2S format
pi.i2c_write_word_data(h,CHIP_ANA_POWER,anap)
     # default signal routing is ok?
pi.i2c_write_word_data(h,CHIP_SSS_CTRL, 0x0010) # ADC->I2S, I2S->DAC
pi.i2c_write_word_data(h,CHIP_ADCDAC_CTRL, 0x0000) # disable dac mute
pi.i2c_write_word_data(h,CHIP_DAC_VOL, 0x3C3C) # digital gain, 0dB
pi.i2c_write_word_data(h,CHIP_ANA_HP_CTRL, 0x1818) # set volume (lowest level)
pi.i2c_write_word_data(h,CHIP_ANA_CTRL, 0x0036)  # enable zero cross detectors
Can you try these, jstsch? I will be away all next week at a camp, and won't be able to do more until the end. After I run my sgtl5000-config.py script, if I then run

Code: Select all

i2cdump -y 1 0x0a w
I see all zeros for all registers except register 0x0000, which should be chip ID, which has the value 1700. Can you try these steps and see if you get the same? I do not have any audio output, and I see I2S SYNC and DMA errors in dmesg if I try to aplay something.

I have to admit that, if I could go back a couple of weeks, I'd probably just fork out the Euros for a premade RPi DAC, even though it would still leave me without ADC. I could have made that money back and then some working instead of doing this!

-Chuckk


EDIT: WARNING! I've figured out a major problem - the SGTL5000 uses 16-bit register addresses (NOT the device address) for I2C configuration, and all of the standard functions I've seen assumed 8-bit addresses. It seems to be possible to send arbitrary lists of bytes using i2cWriteDevice in pigpio, for example, which should allow one to send the register address MSB; register address LSB; value MSB; and value LSB. Reading would be more complicated, as a read call starts with a write call. I still wasn't able to get sound knowing this, but I2C seems to behave.

Orbital6
Posts: 138
Joined: Sat Aug 08, 2015 6:32 pm

Re: The I2S sound thread.

Thu Apr 21, 2016 10:50 am

chuckkh wrote: I am using pigpio through Python to send I2C.
You may run into a big problem using pigpio in your intended application, and it'll be very clear once you read the documentation for pigpiod.

EDIT: Another hint, see what pigpiod uses for its timing controller.

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: The I2S sound thread.

Mon May 02, 2016 4:05 pm

Orbital6 wrote:
chuckkh wrote: I am using pigpio through Python to send I2C.
You may run into a big problem using pigpio in your intended application, and it'll be very clear once you read the documentation for pigpiod.

EDIT: Another hint, see what pigpiod uses for its timing controller.
I haven't yet had any problems with the I2C since Joan straightened me out on 16-bit register addresses.

On the other hand, I've set and reset and reset all of the PLL and I2S settings on the SGTL5000 I'm using and it consistently plays too fast, about 1.5x. Its master clock is received from the RPi3's GPIO clock, set to 9.6 MHz. I realize the RPi is not a perfect timing source, but it's hard to believe its 19.2 MHz crystal is oscillating at close to 30 MHz. I will try using an external 12.288 MHz oscillator, but I'd like to know how I can set, or at least know, the RPi's I2S and sample rate settings.
I'm using the famous generic simple card loader described in this thread. I've posted my question on the other threads referencing it. I see NB and NF, OK, fine, and I have set CBM and CFM, but that doesn't tell me everything. And a 44100 / 48000 mix-up would not explain the difference I have. Once again, ALSA documentation and lack thereof gets in the way.

-Chuckk

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: I2S sound: Anyone got it running? (answer is yes!)

Tue May 03, 2016 10:37 am

Orbital6 wrote:Is there a way to change the BCLK per LRCK value on the pi? It seems the pi only likes 32 BCLK / LRCK when the PCM1803A ADC IC i'm working with features 64 BCLK / LRCK as a minimum.

I think i need to change the bclk_ratio value to one that fits the bclk/LRCK value of the device and one that is an integer division (such as 80(?) or 100). Using plugh's glue code, would i need to change this value in bcm2708-i2c.c in ~/linux... before making the new kernel module, or would i change it in my OS's copy of bcm27.. (I think this lives in usr/src/linux...).

May or may not be interesting, but the PCM1803A is a 24-bit device though makes an almost perfect capture with S16_LE.

I can't seem to get a non-fuzzy recording at S24_LE and my logic analyser keeps showing the bclk/lrck as 50 (the default value), which means none of my changes pre-compilation are working. Which means i'm being a n00b and can do with a little hand : p

I'll be grateful for any help that comes my way!
Hi, Orbital, did you get this worked out? I have come around to this as a possible cause for my problem, that I2S playback happens at the wrong speed. I see that this was discussed and changed some time back at:
https://github.com/raspberrypi/linux/issues/681

But I'm not convinced that the 50/50/100 decision is ideal; I also suspect that having less than the codec's needed 64 may be messing with something. I am thinking of recompiling with 80 for S24, just to see what happens. Have you come to any conclusions?
I could be wrong, but I believe we need to first recompile bcm2835-i2s.c, then the loader. I haven't come across anything else that references or depends on bcm2835-i2s.

-Chuckk

Orbital6
Posts: 138
Joined: Sat Aug 08, 2015 6:32 pm

Re: I2S sound: Anyone got it running? (answer is yes!)

Tue May 03, 2016 11:00 am

chuckkh wrote:
Orbital6 wrote:Is there a way to change the BCLK per LRCK value on the pi? It seems the pi only likes 32 BCLK / LRCK when the PCM1803A ADC IC i'm working with features 64 BCLK / LRCK as a minimum.

I think i need to change the bclk_ratio value to one that fits the bclk/LRCK value of the device and one that is an integer division (such as 80(?) or 100). Using plugh's glue code, would i need to change this value in bcm2708-i2c.c in ~/linux... before making the new kernel module, or would i change it in my OS's copy of bcm27.. (I think this lives in usr/src/linux...).

May or may not be interesting, but the PCM1803A is a 24-bit device though makes an almost perfect capture with S16_LE.

I can't seem to get a non-fuzzy recording at S24_LE and my logic analyser keeps showing the bclk/lrck as 50 (the default value), which means none of my changes pre-compilation are working. Which means i'm being a n00b and can do with a little hand : p

I'll be grateful for any help that comes my way!
Hi, Orbital, did you get this worked out? I have come around to this as a possible cause for my problem, that I2S playback happens at the wrong speed. I see that this was discussed and changed some time back at:
https://github.com/raspberrypi/linux/issues/681

But I'm not convinced that the 50/50/100 decision is ideal; I also suspect that having less than the codec's needed 64 may be messing with something. I am thinking of recompiling with 80 for S24, just to see what happens. Have you come to any conclusions?
I could be wrong, but I believe we need to first recompile bcm2835-i2s.c, then the loader. I haven't come across anything else that references or depends on bcm2835-i2s.

-Chuckk
Hi Chuck, I tried various values and came to the conclusion that it 'should' work - i couldn't figure it out. I had momentary success playing the s24/64 source on the pi at at s16 for some reason. ?I'm not sure if i was losing 'detail'. My hardware setup went to heaven after and i couldn't diagnose the problem even with a second build. I will return to it soon, please let me know if you figure it out!

chuckkh
Posts: 54
Joined: Fri Apr 01, 2016 8:03 am

Re: The I2S sound thread.

Wed May 04, 2016 9:44 am

Hello again. I think I have an idea where my problem is coming from. So I have a sgtl5000, but getting ALSA to load its driver and recognize it hasn't worked, and using the simple card/my_loader combination elucidated on this forum does work. However, while I'm 100% certain that I'm configuring the codec correctly (since it is clearly documented), I always have playback at the wrong speed, about 130%. I've tried all possible I2S configurations on the codec.

I do not want to watch videos, play games or listen to my favorite songs, I'm only trying to make an instrument and I just need soft synths and/or samplers, and I can manually configure all the ones I'm interested in. Could it be that ALSA is resampling my sound arbitrarily, given that it thinks my codec supports who knows how many rates, but has no way to actually tell the codec? It must be either this or that RPi's 9.6 MHz gpio clock is too fast. But it seems strange that Pure Data, for instance, plays the wrong frequency without breaks. It's not like a finite set of data is being played faster.
So I want to try confining ALSA soc to one sample rate and bit depth at compilation, at least until I get something to work. In which driver can I declare which rates and formats are supported??? Codec, platform or machine???

Thank you. Any other ideas are welcome, too.

Chuckk

Orbital6
Posts: 138
Joined: Sat Aug 08, 2015 6:32 pm

Re: The I2S sound thread.

Wed May 04, 2016 11:31 am

chuckkh wrote:Hello again. I think I have an idea where my problem is coming from. So I have a sgtl5000, but getting ALSA to load its driver and recognize it hasn't worked, and using the simple card/my_loader combination elucidated on this forum does work. However, while I'm 100% certain that I'm configuring the codec correctly (since it is clearly documented), I always have playback at the wrong speed, about 130%. I've tried all possible I2S configurations on the codec.

I do not want to watch videos, play games or listen to my favorite songs, I'm only trying to make an instrument and I just need soft synths and/or samplers, and I can manually configure all the ones I'm interested in. Could it be that ALSA is resampling my sound arbitrarily, given that it thinks my codec supports who knows how many rates, but has no way to actually tell the codec? It must be either this or that RPi's 9.6 MHz gpio clock is too fast. But it seems strange that Pure Data, for instance, plays the wrong frequency without breaks. It's not like a finite set of data is being played faster.
So I want to try confining ALSA soc to one sample rate and bit depth at compilation, at least until I get something to work. In which driver can I declare which rates and formats are supported??? Codec, platform or machine???

Thank you. Any other ideas are welcome, too.

Chuckk
How are you certain it's playing it too fast? If you feed it ten seconds of data, how many seconds does it play? OR is it 10 seconds but higher pitched?

If you play back audio via the i2s 'sound card' at a sample rate that's different to the source, then you will get a lower or higher frequency playback, it may or may not be your issue.

I'd also find a way of being certain of your BCLK frequency - look at the datasheet for your chip (same chip as the teensy audio right?) and make sure you're following it's recommendations. Are you just using the teensy audio board? Or your own sgtl5000 setup?

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

Who is online

Users browsing this forum: No registered users and 16 guests