cancel
Showing results for 
Search instead for 
Did you mean: 

How can I interface an electret microphone (condenser) to STM32F4?

DElec.1
Associate II

I want to interface two electret microphones (stereo sound) to STM32F446 chip. I don't know how to connect it or what protocol or pins I have to use. I have found a lot of information about digital microphones but nothing on this topic.

Thanks.

24 REPLIES 24

Thanks so much for your time. When I say stereo I mean I want to record you channels (Right and Left) from natural environments' background audio. I have never worked with audio in hardware design. I have to use an electret microphone, so I guess I have to connect the mic to a preamp and then to the ADC, or use any kind of chip that gives me any protocol output to communicate with the STM32F4 in stereo or in mono.

If I don't use any IC, according to you, it would be enought to just connect the output of the mic to the ADC input and then set the "stereo" (not exactly, for example, nanoseconds difference) in the firmware, is that right?

For connecting the mic to the preamp (¿?) I have to use something like this:0693W00000NqXv6QAF.png

Thanks @MasterT​ I need to design my own hardware.

@DElec.1​  " I have never worked with audio in hardware design"

it sounds like you also don't have much (any?) experience with microcontrollers?

Perhaps it would be better to step back a bit and cover some basics first?

"I have to use an electret microphone"

Specifically electret? If so, why?

"I guess I have to connect the mic to a preamp"

Yes - each mic to its own preamp.

The preamp needs to give a suitable output for the ADC's input range.

"and then to the ADC "

Yes. Either one ADC per channel, or you'll have to switch a single ADC between channels.

"or use any kind of chip that gives me any protocol output to communicate with the STM32F4"

Yes - see my earlier reply.

This may be a better option - the STM32F4's ADC(s) are not particularly optimised for audio.

"If I don't use any IC, according to you, it would be enough to just connect the output of the mic to the ADC input"

I think it's highly unlikely that the output of the mic will be suitable to directly derive the ADC's input.

You need to read the specs of both the mic and the ADC.

(you don't necessarily need an IC as the preamp - discrete components can be used)

You still haven't said what you're actually trying to achieve here.

Or what sampling rate, dynamic range, number of bits, etc, you require.

You might want to define "natural sounds" a bit better. I had trouble with many electret microphones picking up the lowest note of a bass guitar (~41Hz). 25 KHz is well above human hearing. If you just want to hear what you can hear with your own ears, then electret will be a good start - but if you want to extend to the very low or very high frequencies you will have to consider getting very high quality microphones or perhaps go digital.

gregstm
Senior III

Hint: if you are serious about recording stuff. Get yourself a high-quality commercial audio recorder (eg. Olympus). I only realised my multiple electret elements I tried were crap when I compared the output I was getting with the downloaded recording from the commercial recorder. My electrets could barely pick up the lowest bass notes, whereas the digital recorder picked them up easily and cleanly.

@DElec.1​ "natural sounds" is very vague.

Very few (if any?) natural sounds cover such a wide band.

see, eg,

0693W00000NqYWqQAN.pnghttps://www.reddit.com/r/AverageJoeAudiophile/comments/2rgjl6/the_frequency_spectrum_instrument_ranges_and_eq/

Then again, some natural sounds are beyond that range; eg, bats.

https://en.wikipedia.org/wiki/Hearing_range

Still noting on sampling rate, dynamic range, number of bits, etc?

Having "captured" them, what will you then do with them?

"with an analog microphone (it is a specificiation)"

Why does the type of microphone matter to the specification?

Surely, you choose a type of microphone that meets the performance requirements?

Or is this a school assignment?

@DElec.1​  "from 20 Hz to 25KHz"

What electret microphone(s) are you using?

Do they actually meet that frequency specification?

0693W00000NqYefQAF.png 

some of those only go down to 100Hz; none go below 50Hz.

Yes... I don't have experience with MCU in hardware design, I have ir with some programming.

I have to use electret because of stock and disponibility, it is not a technical requirement.

I have read about audio codecs (stereo input and I2S protocol to the MCU), would they solve my problem? This would solve the thing of recording both mics "at the same time"/the problem of reading both ADC at the same time.

My goal: record an stereo input (two mics) (recording environmetal sound; birds, water, etc) and save it in a memory card, save the tracks. The range would be from 20 Hz to 20-25 kHz. I don't have any other specification, I have thought about 44.1 KHz sampling rate (like MP3's).

Thanks for your time again.

Regards.

P.D.: Is it interesting to use the SAI ports? are they stereo?

"I have read about audio codecs"

Strictly, "CoDec" just means "Coder/Decoder" - so may not necessarily include ADC.

You will have to look at some datasheets of specific components to see if they meet your needs.

eg, https://www.maximintegrated.com/en/products/analog/audio/audio-codecs-and-audio-data-converter-ics.html

"44.1 kHz sampling rate (like MP3's)"

MP3 can have many different bit rates - depending on the level of compression.

44.1kHz is what CDs used: https://en.wikipedia.org/wiki/Compact_Disc_Digital_Audio#Audio_format

"The range would be from 20 Hz to 20-25 kHz"

Again, do you actually have mics which can meet that spec?

Note that the minimum sampling rate to avoid aliasing is 2x the highest frequency of interest - so, for 25kHz, you'd need at least 50kHz sampling ...

Today the term "codec" is used also as an ADC+DAC chips. Probably the idea comes from "encoding" and "decoding" from analog to digital and digital to analog.

And, guys, don't confuse sample rate (Hz) with data rate (bps).