fgatin
Posts: 2
Joined: Mon Jan 13, 2014 3:22 pm

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

Tue Jan 14, 2014 9:27 am

koalo wrote:Should be possible, but you have to write a i2c driver for controlling the IC.
Thank you. After reading the thread I get that writing a I2C driver is not an easy task ? Is there any literature out there that could help me get started ?

koalo
Posts: 121
Joined: Mon Feb 04, 2013 4:02 pm

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

Tue Jan 14, 2014 9:32 am

fgatin wrote:
koalo wrote:Should be possible, but you have to write a i2c driver for controlling the IC.
Thank you. After reading the thread I get that writing a I2C driver is not an easy task ? Is there any literature out there that could help me get started ?
Unfortunately I can not provide you more information. Have a look into the existing drivers in sound/soc/codecs/

cv007
Posts: 2
Joined: Thu Jan 02, 2014 4:23 pm

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

Sun Jan 19, 2014 5:08 pm

This may be off topic just a little, but I would like to be able to simply 'pipe' my mpg123 output to a s/pdif (toslink) module. I had been experimenting with a pic32mx250 to output a bmc signal via a toslink connector, and it works. The pic32mx2 has i2s capability, which I don't really need except for the ability to generate an spi clock that can work at 44100/48000hz (x64bits bmc x2ch). I only use/need the spi data out pin, and I use the internal clock.

My plan had been to 'pipe' the mpg123 decoded pcm data to my pic32 via the Pi spi device, but there is the matter of flow control- I would have to signal back to the Pi when my pic32 buffer is full or ready. With the pic32mx250, I think I can buffer ~40ms of data in 8K (has 32K total ram, and DMA capability), but I don't know Linux well enough to know if that is enough.

BUT, I have been reading this thread and have been wondering why I'm not using the Pi to do my work. I have a Model A (with P5 header, although I don't think it matters since I only need PCM_DOUT) running the latest Arch Linux Arm simply playing a few internet radio mp3 streams via mpg123 (usb wifi, terminal/ssh access only), My pic32 bmc code is quite simple/fast, and the Pi should be able to easily do this, also.

Question - without getting into kernel compiling, modules, etc,, can I write a program that directly accesses a peripheral like the PCM module? I imagine something like this-
my_spdif_pipe program -
setup PCM module
read stdin (pcm 16bit data)
convert to bcm
send bcm data to pcm device (direct to FIFO, or use DMA)
PCM_DOUT connected to toslink, outputs bcm data
receiver plays music
Pi user (me) happy

then use as such-
#mpg123 -all_my_options_here | my_spdif_pipe

Appreciate anyone who can point me in the right direction.
Thanks.

koalo
Posts: 121
Joined: Mon Feb 04, 2013 4:02 pm

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

Sun Jan 19, 2014 5:29 pm

For piping to SPI it might be possible to do just
mpg123 -all_my_options_here > /dev/spidev0.0

For more information about the spi interface of the Raspberry Pi, have a look e.g. here:
http://elinux.org/RPi_SPI

If your goal is to just have S/PDIF/TOSLINK output for your Raspberry Pi, have a look here:
http://www.hifiberry.com/hbdigi

cv007
Posts: 2
Joined: Thu Jan 02, 2014 4:23 pm

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

Mon Jan 20, 2014 12:20 am

Thanks.

I know there are many add on cards that can do what I want, but thats no fun, and I really don't want to spend more for an accessory board than I did for the Pi. That would be the smart thing to do, though.

Although it looks like a simple redirect to the spi device would work, I think some form of flow control is needed. The pic32 would need to be 'fed' at a greater rate than the playback rate so it would never be starved for data. It would also need to tell the Pi when it cannot handle any more data. Which I think means a program on the Pi would still need to be written to send data to the spi device (same idea as before, pipe mpg123 output through it).

I think I will have more control using the pic32, so I guess I'll focus on getting data transferred to it over spi for now.

birca1987
Posts: 1
Joined: Tue Jan 21, 2014 7:57 pm

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

Wed Jan 22, 2014 10:21 am

by 0xFF » Thu May 09, 2013 3:46 pm
Hi,
Thanks to all contributors, finally my RPi starts to play music ;-)

I still have
CODE: SELECT ALL
bcm2708-i2s bcm2708-i2s.0: I2S SYNC error!

errors, but sound seems to be good.

For RPi revision 1 owners I made small hack in bcm2708-i2s.c file:
CODE: SELECT ALL
INP_GPIO(18); /* s
et mode to GPIO input first */
SET_GPIO_ALT(18, 0); /* set mode to ALT 0 */
INP_GPIO(21); /* set mode to GPIO input first */
SET_GPIO_ALT(21, 0); /* set mode to ALT 0 */
INP_GPIO(29); /* set mode to GPIO input first */
SET_GPIO_ALT(29, 2); /* set mode to ALT 2 */


So you have to solder only one wire - PCM_FS. PCM_CLK, PCM_OUT output remains on P1 header.

Best regards
Piotr
Hi can you please tell us more about i2s connection on rev 1 boards, and if you have any pictures will be great. I mean where to solder the wire and on which gpio pin are the rest connections. I thinks a lot of people need it and will say thanks.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13014
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Wed Jan 22, 2014 11:09 am

You can compare the schematics (here: http://www.raspberrypi.org/technical-he ... -documents ).
They are GPIO 28 to 31, on a rev 1 board they are connected to respectively R8, R7, R4 and R5 (the side not connected to 3V3).

maybe someone else can provide pictures.

User avatar
jojopi
Posts: 3237
Joined: Tue Oct 11, 2011 8:38 pm

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

Wed Jan 22, 2014 12:18 pm

On Rev1 boards, each GPIO is connected to two pads. One pad could have a resistor fitted to pull to 3.3V, or the other to pull to ground. The resistors actually fitted are R3 R6 R9 R8, so GPIO28 is pulled high (originally meaning Model B), and the others low.

The resistors are 10kΩ, so you may not need to remove them. You can solder to either or both of the yellow pads for each GPIO. Obviously you need to use fine wire and ideally you should hot-glue the wires to some nearby flat part of the board to reduce the risk of them getting pulled off in future.

Be careful not to short to the nearby red and black pads of the resistors. Not a recommended modification unless you are very confident at soldering; use a Rev2 board where these GPIOs are officially accessible.

Image

ceteras
Posts: 239
Joined: Fri Jan 27, 2012 1:42 pm
Location: Romania

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

Wed Jan 22, 2014 12:50 pm

I would use wires from an old 80-wire ATA100 cable.
You can cut a strip of 4 thin wires from it, they are easier to solder as they are held together and equally spaced.
These wires are single solid core, not multiple twisted strands, they stay as you put them, so you can handle them much easier.
First remove 3-4mm of isolation from one end of each wire, then apply solder to the copper wires.
Next, align the wires to the pads and you can solder them in a few seconds.
After you are 100% sure that your soldering job is correct, you can use a heat glue gun to secure the wires in place.

wpfundstein
Posts: 2
Joined: Tue May 28, 2013 10:36 am

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

Wed Jan 22, 2014 4:06 pm

Hi,

does anybody know how to connect the Audio Codec Shield form Open Music Labs to the raspi?

http://www.openmusiclabs.com/projects/codec-shield/

Thanks, Werner

ceteras
Posts: 239
Joined: Fri Jan 27, 2012 1:42 pm
Location: Romania

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

Wed Jan 22, 2014 5:48 pm

wpfundstein wrote:Hi,

does anybody know how to connect the Audio Codec Shield form Open Music Labs to the raspi?

http://www.openmusiclabs.com/projects/codec-shield/

Thanks, Werner
You can see the schematic for the shield on their wiki page.
The WM831 on the shield is configured to use 2-wire interface, that is I2C.
You need to hook the 2-wire interface (pins 1,2 from J2 on the shield) to the GPIO I2C on the Pi.
Then pins 3,4,5,6 from J3 on the shield need to go to the I2S header on the Pi.
WM831 is powered at 3.3V, so you can get power from either GPIO or I2S headers on the Pi to pin 5 from J1 on the shield.
You need to leave the EN jumper on the shield open.
I don't know about the drivers, though, perhaps someone else can fill in?

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

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

Wed Jan 22, 2014 7:29 pm

birca1987 wrote:
by 0xFF » Thu May 09, 2013 3:46 pm
Hi,
Thanks to all contributors, finally my RPi starts to play music ;-)

I still have
CODE: SELECT ALL
bcm2708-i2s bcm2708-i2s.0: I2S SYNC error!

errors, but sound seems to be good.

For RPi revision 1 owners I made small hack in bcm2708-i2s.c file:
CODE: SELECT ALL
INP_GPIO(18); /* s
et mode to GPIO input first */
SET_GPIO_ALT(18, 0); /* set mode to ALT 0 */
INP_GPIO(21); /* set mode to GPIO input first */
SET_GPIO_ALT(21, 0); /* set mode to ALT 0 */
INP_GPIO(29); /* set mode to GPIO input first */
SET_GPIO_ALT(29, 2); /* set mode to ALT 2 */


So you have to solder only one wire - PCM_FS. PCM_CLK, PCM_OUT output remains on P1 header.

Best regards
Piotr
Hi can you please tell us more about i2s connection on rev 1 boards, and if you have any pictures will be great. I mean where to solder the wire and on which gpio pin are the rest connections. I thinks a lot of people need it and will say thanks.
Hi,

if you take a look at GPIO alternative function http://elinux.org/RPi_BCM2835_GPIOs, you can easy get PCM_FS. PCM_CLK, PCM_OUT outputs on P1 header.
So, for PCB revision 1.0 you have to solder just one wire to have full i2s output.
That's you can win just by software tweaking ;-)

Best regards
Piotr

wpfundstein
Posts: 2
Joined: Tue May 28, 2013 10:36 am

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

Wed Jan 22, 2014 11:26 pm

ceteras wrote:
wpfundstein wrote:Hi,

does anybody know how to connect the Audio Codec Shield form Open Music Labs to the raspi?

http://www.openmusiclabs.com/projects/codec-shield/

Thanks, Werner
You can see the schematic for the shield on their wiki page.
The WM831 on the shield is configured to use 2-wire interface, that is I2C.
You need to hook the 2-wire interface (pins 1,2 from J2 on the shield) to the GPIO I2C on the Pi.
Then pins 3,4,5,6 from J3 on the shield need to go to the I2S header on the Pi.
WM831 is powered at 3.3V, so you can get power from either GPIO or I2S headers on the Pi to pin 5 from J1 on the shield.
You need to leave the EN jumper on the shield open.
I don't know about the drivers, though, perhaps someone else can fill in?
Hi ceteras, thanks for the informations, but i am not shure exactly what pin from the WM8731 to the raspi must be connected.

WM8731 <-> Raspi

J2 (1) <-> P5 (4)
J2 (2) <-> P5 (3)

i think this is okay. But on the WM8731 Board on J3 there are the pins SCK, MOSI, MISO and SS. On the Raspi P1 Header i found MOSI, MISO and SCKL. Pin SS from the WM8731 Board to GND.

J3 (3) <-> P1 (23)
J3 (4) <-> P1 (21)
J3 (5) <-> P1 (19)
J3 (6) <-> GND

is this so ok?

Thanks, Werner

ceteras
Posts: 239
Joined: Fri Jan 27, 2012 1:42 pm
Location: Romania

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

Thu Jan 23, 2014 12:01 am

Negative!

If you look at the shield schematic the SPI-named signals at J3 are buffered towards WM831, so let's look at the trace names after the buffers:
- SPI SCK -> BCLK
- SPI MOSI -> DACDAT
- SPI MISO -> ADCDAT
- SPI SS -> LRC
On the arduino, WM831 is configured to work wit an SPI interface (WM accepts several different formats). Forget that.
On the RPi, the same pins of the WM831 need to be connected to the I2S interface so these should go to RPi P5 header (the smaller, 10 pin). The pins on P5 take the ALT2 functions.
- J3(3) SPI SCK -> BCLK -> P5-03 PCM_CLK
- J3(5) SPI MOSI -> DACDAT -> P5-06 PCM_DOUT
- J3(4) SPI MISO -> ADCDAT -> P5-05 PCM_DIN
- J3(6) SPI SS -> LRC -> P5-04 PCM_FS

Now, J2 signals need to go to the I2C interface on the big GPIO connector, P1:
- J2 (1) SCL -> P1-05 SCL
- J2 (2) SDA -> P1-03 SDA

I hope this is clearer.

I saw that there are drivers for this board, based on WM831, but runs with a 12.288 MHz XTAL, instead of you shield's 11.2896MHz (X1 on the schematic). You can either modify and recompile the driver for your xtal, or replace the xtal.
Schematic here.
Also, some info here.

Perhaps I could have just given some urls, but I think it's better to explain the "thinking".
This way you can verify if I did any mistakes ;) .


jotun
Posts: 4
Joined: Thu Oct 10, 2013 7:25 pm

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

Mon Mar 10, 2014 8:19 pm

We're trying to get a board we have to work as a generic I2S slave for both input and output.

We are using Raspbian from 2013-12-20.

Code: Select all

pi@rpi ~ $ uname -a
Linux buckleyrpi 3.10.24+ #614 PREEMPT Thu Dec 19 20:38:42 GMT 2013 armv6l GNU/Linux
We're including these modules in /etc/modules:

Code: Select all

snd-bcm2835
snd_soc_bcm2708
snd_soc_bcm2708_i2s
bcm2708_dmaengine
snd-soc-pcm1794a
snd_soc_rpi_dac
It gives us a playback device, which works with aplay and mplayer:

Code: Select all

pi@rpi ~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  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
  Subdevice #7: subdevice #7
card 1: sndrpirpidac [snd_rpi_rpi_dac], device 0: HifiBerry Mini HiFi pcm1794a-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
But there is no capture device

Code: Select all

pi@rpi ~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
pi@rpi ~ $
I was able to get capture working before, when we had to use Koalo's modified kernel, but we would prefer if we could make it work with a stock image instead, with no compiling needed.

Is there a way to get a generic I2S capture device running?

vadim
Posts: 129
Joined: Wed Sep 18, 2013 1:47 pm
Location: Nottingham

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

Mon Mar 10, 2014 11:06 pm

Not sure why rpi-mbed is not in the stock kernel, I think it was generic enough.
Unfortunately, the only driver with capture link in the official kernel is "snd-hifiberry-digi" with wm8804 codec. But that is SPDIF.

jotun
Posts: 4
Joined: Thu Oct 10, 2013 7:25 pm

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

Tue Mar 11, 2014 9:20 pm

vadim wrote:Not sure why rpi-mbed is not in the stock kernel, I think it was generic enough.
I have rpi-mbed.c from the koalo kernel source that I was using before. I am also able to build and load modules against 3.10.24+ and run them in my Raspbian image. I'm just not sure how to take this and actually build a module out of it, if that's even possible.

Also, looking at these source files in sound/soc/bcm (sound/soc/bcm2708 in the koalo source) I don't see anything obvious for determining whether a driver registers for playback or capture. bcm2708-i2s.c seems to support both, but I really don't understand what's going on in the smaller codec-specific files (hifiberry_dac.c, rpi-dac.c, rpi-mbed.c, etc)

vadim
Posts: 129
Joined: Wed Sep 18, 2013 1:47 pm
Location: Nottingham

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

Wed Mar 12, 2014 12:00 am

jotun, building the modules is the easy bit. The problem is that no generic platform devices are defined in bcm2708.c
you can take a shortcut and define the platform devices for your card and codec in their drivers but that is a very bad style. alternatively, add generic devices ("sound card" and codec) to bcm2708.c and kernel configs and after testing submit patches on github.

gnozzi
Posts: 2
Joined: Tue Mar 11, 2014 1:57 pm

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

Wed Mar 12, 2014 9:12 am

Hello ,

i'm interested in sampling an analog audio signal , and acquire it with i2s bus on raspberry . I saw the c code posted by dariush
( http://www.raspberrypi.org/phpBB3/viewtopic.php?t=8496 )
but that was written before the RPi included the P5 connector. Is there a working example of a communication between the RPi
and an ADC with I2s interface ? I mean an example that uses the pin PCM_FS , PCM_CLK, PCM_DIN ( see here http://elinux.org/RPi_Low-level_peripherals#P5_header) .

If someone has a link to a tutorial or working example , please let me know.

thanks in advance.

mhelin
Posts: 127
Joined: Wed Oct 17, 2012 7:18 pm

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

Wed Mar 12, 2014 7:52 pm

Anyone got the Wolfson Audio Card yet?
http://www.element14.com/community/comm ... wolfson_pi

The drivers seem to be heavily patched, see http://downloads.element14.com/wolfson/ ... nAudioCard

vadim
Posts: 129
Joined: Wed Sep 18, 2013 1:47 pm
Location: Nottingham

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

Wed Mar 12, 2014 10:37 pm

gnozzi wrote:Hello ,

i'm interested in sampling an analog audio signal , and acquire it with i2s bus on raspberry . I saw the c code posted by dariush
( http://www.raspberrypi.org/phpBB3/viewtopic.php?t=8496 )
but that was written before the RPi included the P5 connector. Is there a working example of a communication between the RPi
and an ADC with I2s interface ? I mean an example that uses the pin PCM_FS , PCM_CLK, PCM_DIN ( see here http://elinux.org/RPi_Low-level_peripherals#P5_header) .

If someone has a link to a tutorial or working example , please let me know.

thanks in advance.
Unfortunately, the official kernel does not include a working generic ADC driver, just DACs.
Take a look at http://www.noiseisgood.co.nz

koalo
Posts: 121
Joined: Mon Feb 04, 2013 4:02 pm

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

Mon Apr 28, 2014 6:21 pm

@gnozzi, @jotun: Which audio codec do you want to use?
Especially for audio input, it is not so easy to provide a generic driver since the audio codecs usually need some configuration via I2C, but it would not be difficult to provide a driver for a specific audio codec (at least when there is already an associated codec driver https://github.com/raspberrypi/linux/tr ... soc/codecs).

The only thing that stops the mbed and proto drivers from being included into the official kernel is the lack of pull requests that respect the quality standards (e.g. proper indention, separation into well formatted commits). I there is a high demand for these drivers I will see if I can find some time for doing this.

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

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

Mon May 12, 2014 6:36 pm

Is there a "HOWTO get started with i2S" anywhere ? I can't see the point of reading 22 pages, most of which is many months old and probably contains of out of date information.

PeterO
G0DZB
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

koalo
Posts: 121
Joined: Mon Feb 04, 2013 4:02 pm

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

Tue May 13, 2014 6:27 am

PeterO wrote:Is there a "HOWTO get started with i2S" anywhere ?
Depends on what you want to do.
You can buy existing hardware, e.g.
http://www.tjaekel.com/T-DAC/
http://www.hifiberry.com/
http://www.element14.com/community/comm ... wolfson_pi
http://iqaudio.com/
They will also give you support when you want to use their hardware.

Or you can read my somehow outdated blog post
http://blog.koalo.de/2013/05/i2s-suppor ... ry-pi.html
(I should really update that, since there is now a new version of the driver included in the raspberry pi kernel....)

Or you just ask what you are planning to do and I will try to help you with the first steps.

Greetings,
Florian

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