I2S/MEMS microphone example

Hi there,

I want to connect an I2S audio source (48kHz, 24 Bit, Mono) to the Seed, and I already understood that I have to configure SAI2 to be I2S master it.

But I can not find any examples out there how to do this. The STM32 doc is really complex. What is the value of the master clock on the Seed? Do I need MCLK for a MEMS microphone or not? (INMP441).

And how do I set this I2S as the audio source for the AudioCallback() handler?

I could use DaisyDuino or simple Makefile.

A simple “loop station” hello world from line-in to audio out was so easy to program, but I get stuck getting any microphone input to the seed. It’s a pitty that there is no mic level input for dynamic mic.

I read the thread

But I can’t find any customer source for those max 4061/4062.

Nobody seems to connect any kind of mic to Daisy Seed, strange.

Any help is welcome, even the good old RTFM with the right links (but please not the full HAL of STM32).


Welcome Marco!

I think a team member has used MEMS microphone for a project, so I will ask when I get a chance.
Thank you for the wait.

Thanks! I see snippets here and there, but I don’t get it together. Especially setting SAI2 as audio source for AudioCallback().

Sorry for the major hold up! Here’s the code for adding an external audio codec. Since your device is a microphone and doesn’t use the transmit side, I’ve commented that out.

/** Daisy Seed Initialization */

/** secondary audio */
/** Configure the SAI2 peripheral for our secondary codec. */
SaiHandle::Config external_sai_cfg;
external_sai_cfg.periph = SaiHandle::Config::Peripheral::SAI_2;
external_sai_cfg.sr = SaiHandle::Config::SampleRate::SAI_48KHZ;
external_sai_cfg.bit_depth = SaiHandle::Config::BitDepth::SAI_24BIT;
// external_sai_cfg.a_sync = SaiHandle::Config::Sync::SLAVE;
external_sai_cfg.b_sync = SaiHandle::Config::Sync::MASTER;// external_sai_cfg.a_dir = SaiHandle::Config::Direction::TRANSMIT;
external_sai_cfg.b_dir = SaiHandle::Config::Direction::RECEIVE;
external_sai_cfg.pin_config.fs = seed::D27;
external_sai_cfg.pin_config.mclk = seed::D24;
external_sai_cfg.pin_config.sck = seed::D28;
external_sai_cfg.pin_config.sb = seed::D25;
// external_sai_cfg.pin_config.sa = seed::D26;

/** Initialize the SAI new handle */

AudioHandle::Config audio_cfg;
audio_cfg.blocksize = 24;
audio_cfg.samplerate = SaiHandle::Config::SampleRate::SAI_48KHZ;
audio_cfg.postgain = 1.0f;

seed.audio_handle.Init(audio_cfg, seed.AudioSaiHandle(), external_sai_handle);

Your audio callback should have two new samples for the mic in, so it’ll be:

in[0][i] // on board codec L in, as usual
in[1][i] // on board codec R in, as usual
in[2][i] // mic L in. (I looked at the datasheet, and the mic claims to have L and R, which is a bit weird!)
in[3][i] // mic R in

out[0][i] // on board codec L out, as usual
out[1][i] // on board codec R out, as usual

Let me know how that works or if you have any other questions!

Actually, this isn’t weird. From the datasheet, it’s simple to use two of these mics as a single stereo I2S device. Very cool.

I’ll try it out this week. Thanks a lot for this help!

I could find no clue how to handle an extra audio I2S source in the docs.

The Daisy documentation is thin, but the libDaisy code for Daisy Patch can be examined as an example.


Also looking to hook up an external I2S source. Did this example work? I tried running it to an ESP32 I2S Master streaming A2DP bluetooth to the I2S port. No response from the Daisy… I need a master clock?

ESP32 Daisy Seed
FS D27

Also changed

external_sai_cfg.b_sync = SaiHandle::Config::Sync::SLAVE