2024-12-01 09:38 AM - edited 2024-12-01 09:39 AM
I am having an STM32F411E board and I am trying to read values of MAX4466 analog mic using the onboard ADC interface(12 bit resolution). I get values starting from around 1000(0.8 V) and whenever I make sounds it slightly increases and that's it. I've checked with my logic analyzer and whenever I make sounds the output momentarily goes up and down until it goes off as expected (I know that the results of a logic analyzer are not relevant for an analog signal yet I just wanted to know if the mic reacts at all). By the way I'm using my own GPIO driver which is tested and has no issues. So what might be the problem?
#include "STM32F411xx.h"
void ADC_conversion(void);
void ADC_init(void);
float ADC_to_Voltage(uint16_t ADC_value, float Vref);
__vo uint16_t ADC_read(void);
__vo uint16_t ADC_data;
float voltage;
extern void initialise_monitor_handles(void);
int main()
{
ADC_init();
while(1)
{
ADC_conversion();
ADC_data = ADC_read();
voltage = ADC_to_Voltage(ADC_data, 3); // Vref = 3V
initialise_monitor_handles();
printf("The voltage level is %0.2f V\n", voltage);
}
return 0;
}
void ADC_init(void)
{
GPIO_Handle_t ADC_ch1;
ADC_ch1.pGPIOx = GPIOC;
ADC_ch1.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_ANALOG;
ADC_ch1.GPIO_PinConfig.GPIO_PinPuPdControl = GPIO_PIN_PD;
ADC_ch1.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_FAST;
ADC_ch1.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_5;
GPIO_Init(&ADC_ch1);
RCC->APB2ENR |= (1 << 8); //Enables the clock of the bus that ADC1 is hanging on
ADC1->CR1 &= ~(0x3 << 24); //Sets 12 bit ADC resolution (15 clock cycles)
ADC1->CR2 &= ~(1 << 0); //AD converter is off
ADC1->SQR3 |= (0x0F << 0); //15th ADC1 channel is enabled
ADC1->CR2 |= (1 << 0); //AD converter is on
}
void ADC_conversion(void)
{
ADC1->SMPR2 |= (1 << 0); //Sets channel sample rate to 15 clock cycles per sample
ADC1->CR2 |= (1 << 30); //Starts regular channel conversion
}
__vo uint16_t ADC_read(void)
{
while(!(ADC1->SR & (1 << 1)));
return (ADC1->DR);
}
float ADC_to_Voltage(uint16_t ADC_value, float Vref) {
return (ADC_value / 4095.0) * Vref;
}
2024-12-04 06:39 AM - edited 2024-12-04 07:22 AM
@user_01 wrote:MAX4466 analog mic
This: https://www.analog.com/en/products/max4466.html ?
If so, that's just a preamp - not a mic - so have you also added a suitable mic (and suitable bias, if required)?
This is all analogue stuff - so have you first verified that you're getting a decent analogue signal from it?
If you're not getting a decent analogue signal from it, then there's no way you'll get anything useful after feeding it to any ADC!
2024-12-11 01:01 AM
I apologize for the late reply, so is it only a pre-amp without a mic? There are only 3 pins Vout, Vcc and Gnd. Isn't Vout the analog output?
2024-12-11 01:13 AM - edited 2024-12-11 01:14 AM
@user_01 wrote:so is it only a pre-amp without a mic?
Yes, the MAX4466 is just a preamp - it has no microphone.
Again, its full specifications are here:
https://www.analog.com/en/products/max4466.html
@user_01 wrote:There are only 3 pins Vout, Vcc and Gnd.
No, the MAX4466 has five pins:
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX4465-MAX4469.pdf
So, presumably, you are not talking about just a MAX4466 - but some board or module which contains a MAX4466 (and, presumably, also a microphone and other components) ?
Something like this, perhaps:
https://www.adafruit.com/product/1063
Please give a link to what you actually have, plus a link to whatever "STM32F411E board" you have, and a schematic of how you have then connected-up.
Some good, clear photos of your setup would also help.
Please see the Posting Tips:
2024-12-11 01:23 AM - edited 2024-12-11 01:27 AM
Yeah, it's a module with mic like the adafruit one you've mentioned. The picture and the link is as below.
The connections are very simple :
PC6 - OUT
GND - GND
5V - VCC
PC6 can be used as ADC1's 15th channel as mentioned in alternate function table in the datasheet .
I could also describe about the project I'm trying to do, if you could give me more clarity on whether I'm going in the right direction or not
2024-12-11 01:34 AM
Most likely, that will be just a copy of the Adafruit module.
The trouble with buying cheap copies like this from the likes of Amazon is that you get no documentation and no support - you gets what you pays for!
But the Adafruit documentation will probably apply - so start by studying that:
https://www.adafruit.com/product/1063
You didn't link to whatever "STM32F411E board" you have.
@user_01 wrote:The connections are very simple
Even so, text is a particular poor way to describe circuits. Please get into the habit of providing a schematic. It can be hand-drawn.
2024-12-11 01:47 AM - edited 2024-12-11 01:47 AM
I just have the original STM32F411E discovery board (blue color) and STM32F411E is the link to the site I bought my board from.
Actually I bought the MAX4466 module in a local shop nearby which was obviously brandless but not in amazon. I just want to do name specific word wake up (Edge impusle) using a mic with STM32F411E as the MCU. It's really insane like I can't even get the voice input to process the data in the first place.
2024-12-11 02:43 AM
@user_01 wrote:I just have the original STM32F411E discovery board (blue color)
So full documentation here: https://www.st.com/en/evaluation-tools/32f411ediscovery.html
@user_01 wrote:It's really insane like I can't even get the voice input to process the data in the first place.
Actually, capturing voice data is quite involved.
Before getting onto that, get the ADC to just read a steady voltage from a potentiometer.
As mentioned earlier, you need to ensure that the output level from the module is suitable for the ADC input.
Have you checked that? eg, on an oscilloscope?
The Adafruit module has a gain control - does yours?
2024-12-11 03:02 AM - edited 2024-12-11 04:49 AM
When I plug the ADC pin to 3V it measures 2.8V approx from the calculation function in my code and close to 0V when plugging to ground. Yes my module does have a pot adjustable gain. Actually I tried changing the gain when I was stuck with totally random values in ADC no matter what because I did not configure the right channel for the particular pin I was using, after which I figured it out by looking at the datasheet. Also with pot I got 25-30 stable ADC reading at 0.02V and around 3700 - 3750 stable reading at 2.8V which is ok.