0

Full duplex audio over i2s (Adafruit MEMS + DAC)
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Full duplex audio over i2s (Adafruit MEMS + DAC)

by learnvst on Wed Jan 03, 2018 6:54 am

I have setup a pi-zero with digital mems mics from Adafruit, and also the digital DAC. I can use arecord to record stereo audio, and then aplay to playback the audio over the DAC. I set up the mics first using the detailed instructions on the site, then went though the manual install version of the instructions for the DAC (trying not to trample over the settings for the mics using the cheat script).

My problem comes with full duplex operation. I wrote a C++ JUCE application to test some of the capabilities. If I initialise the inputs only, I can monitor the input device levels. If I initialise the outputs only, I can output synthesised audio. However, when I initialise both inputs an outputs, I cannot even hear synthesised audio playback (the device fails at initialisation with a resource-busy error).

Where should I begin looking into debugging this? I'm an i2s noob. Is full duplex even possible?

Just for reference, the ALSA device list looks like this . .

Code: Select all | TOGGLE FULL SIZE
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpisimplecar [snd_rpi_simple_card], device 0: simple-card_codec_link snd-soc-dummy-dai-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0


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


The tail of the output of alsa-conf might also be revealing. I set up the mems mics first, then followed the Adafruit instructions for setting up the DAC (hence the references to hifiberry_dac).

Code: Select all | TOGGLE FULL SIZE
!!ALSA/HDA dmesg
!!--------------

[    9.197591] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered - will retry
[    9.360780] asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 20203000.i2s mapping ok
[    9.661734] bcm2835-i2s 20203000.i2s: Trying to bind component to card "snd_rpi_hifiberry_dac" but is already bound to card "snd_rpi_simple_card"
[    9.661759] snd-hifiberry-dac soc:sound: ASoC: failed to instantiate card -19
[    9.661923] snd-hifiberry-dac soc:sound: snd_soc_register_card() failed: -19
[   15.728423] Adding 102396k swap on /var/swap.  Priority:-1 extents:1 across:102396k SSFS


After some searching, I see that there are other users who see this collision https://www.raspberrypi.org/forums/viewtopic.php?t=183617.

For further reference, I've wired the mics and DAC exactly as specified in the tutorials for these products.

Mics = https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-and-test
DAC = https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a/raspberry-pi-wiring

i.e.
#18 is shared BCLK for both MEMS and DAC
#19 is shared WSEL for both MEMS and DAC
#20 is MEMS data
#21 is DAC data


Image
Image
Last edited by learnvst on Wed Jan 03, 2018 9:09 am, edited 1 time in total.

learnvst
 
Posts: 5
Joined: Wed Jan 03, 2018 6:53 am

Re: Full duplex audio over i2s (Adafruit MEMS + DAC)

by learnvst on Wed Jan 03, 2018 10:58 am

Changing dtoverlays in /boot/config.txt, by commenting out the hifiberry overlay

Code: Select all | TOGGLE FULL SIZE
# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
#dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap


removes the collision in the dmesg output as one would expect . . .

Code: Select all | TOGGLE FULL SIZE
    5.894747] my_loader: loading out-of-tree module taints kernel.
[    5.930150] request module load 'bcm2708-dmaengine': 0
[    5.930555] register platform device 'asoc-simple-card': 0
[    5.930559] Hello World :)
[    6.027079] dwc2 20980000.usb: new device is high-speed
[    6.094201] dwc2 20980000.usb: new address 10
[    6.118443] g_ether gadget: high-speed config #1: CDC Ethernet (ECM)
[    7.145661] systemd-journald[84]: Received request to flush runtime journal from PID 1
[    8.461833] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered - will retry
[    9.104211] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered - will retry
[    9.105245] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered - will retry
[    9.425940] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000
[    9.426227] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered - will retry
[    9.535431] asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 20203000.i2s mapping ok


Everything still works fine in half-duplex, but initialising the soundcard to full-duplex gives the following error in the dmesg output

Code: Select all | TOGGLE FULL SIZE
[   87.306162] bcm2835-i2s 20203000.i2s: ASoC: can't set 20203000.i2s hw params: -16

learnvst
 
Posts: 5
Joined: Wed Jan 03, 2018 6:53 am

Re: Full duplex audio over i2s (Adafruit MEMS + DAC)

by adafruit_support_mike on Fri Jan 05, 2018 3:06 am

The RasPi's I2S system can only handle two devices. You can have two mics, two speakers, or one mic and one speaker, but that's the limit on options.

adafruit_support_mike
 
Posts: 59172
Joined: Thu Feb 11, 2010 2:51 pm

Re: Full duplex audio over i2s (Adafruit MEMS + DAC)

by learnvst on Fri Jan 05, 2018 1:29 pm

Thanks for the response, Mike. Do you know where the official documentation is on this? Based on your input, I tried operating the devices in full duplex using a single channel I/O, but still get "resource busy" errors even then. So, there's still something I'm not understanding, which troubles me.

Otherwise, in order to get full duplex stereo I/O with minimal latency, is there another audio DAC you can suggest that maybe works on a different protocol than I2S?

learnvst
 
Posts: 5
Joined: Wed Jan 03, 2018 6:53 am

Re: Full duplex audio over i2s (Adafruit MEMS + DAC)

by adafruit_support_mike on Sat Jan 06, 2018 2:28 am

It's baked into the protocol. An I2S interface has data, clock, and channel pins. An I2S frame is a 32-bit sequence of bits on the data pin, and the channel pin flips between high and low every 16 bits.

That gives you two channels, nominally left and right, but functionally just 'channel 1' and 'channel 2'. You can connect on speaker or mic to a channel, but there's no way to connect a speaker and a mic the same channel.

adafruit_support_mike
 
Posts: 59172
Joined: Thu Feb 11, 2010 2:51 pm

Re: Full duplex audio over i2s (Adafruit MEMS + DAC)

by learnvst on Sun Jan 07, 2018 5:01 pm

An I2S interface has data, clock, and channel pins.


But there are 2 data pins. 1 for in, 1 for out.

learnvst
 
Posts: 5
Joined: Wed Jan 03, 2018 6:53 am

Re: Full duplex audio over i2s (Adafruit MEMS + DAC)

by learnvst on Fri Jan 12, 2018 9:27 am

UPDATE: Turns out full duplex stereo is supported by the hardware. There is however, currently a driver bug that prevents this when the RPi is set to master clock. On a thread over at the Raspberry Pi forums, a user has allegedly identified the cause of this bug and is working on a solution. I'll update this thread when I know more.

learnvst
 
Posts: 5
Joined: Wed Jan 03, 2018 6:53 am

Please be positive and constructive with your questions and comments.