Skip to content

rescurib/I2S_Mic_STM32_Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I2S Microphone Recorder Example

This project demonstrates how to use the STM32 I2S peripheral in DMA mode to acquire audio data from an INMP441 digital MEMS microphone and stream it over UART.

The I2S protocol is a kind of straight forward, at this point you might already found docs like this or that. But perhaps you haven't come across simple examples, instead of complete applications where you have to dig deep to find out how the heck they made the I2S work on an STM32. That's why I'm publish this repo. Hope it helps.

Features

  • I2S audio acquisition from INMP441 MEMS microphone
  • DMA-based data transfer for efficient sampling
  • UART streaming of audio samples to a host PC (460800 baudrate)
  • Start/stop recording with a user button (B1)
  • Status LED (LD2) indicates recording state
  • STM32CubeIDE and STM32CubeMX projects (so you can see all the configs you need)

Hardware Requirements

  • STM32F3 series microcontroller (tested on STM32F303RE)
  • INMP441 MEMS microphone (I2S interface)
  • UART connection to host PC
  • User button (B1)
  • Status LED (LD2)

How It Works

  1. Initialization:
    • I2S and UART peripherals are configured.
    • The system waits in an idle loop.
  2. Start/Stop Recording:
    • Press the user button (B1) to start or stop audio acquisition.
    • The status LED (LD2) lights up when recording is active.
  3. Data Acquisition:
    • Audio samples are acquired from the INMP441 via I2S using DMA.
    • Each received stereo sample is sent over UART in a simple binary format.

UART Output Format

Each audio frame sent over UART consists of:

  • Left Chan Low byte
  • Left Chan Mid byte
  • Left Chan High byte
  • Newline character (\n)

Usage

  1. Connect the INMP441 microphone to the STM32 I2S pins.
  2. Connect UART2 to your host PC and open a serial terminal.
  3. Flash the firmware to your STM32 board.
  4. Press the user button (B1) to start/stop recording.
  5. Observe the status LED and monitor the UART output for audio data.

File Overview

  • Src/serial_mic_recorder.c: Main logic for I2S acquisition and UART streaming.
  • Inc/serial_mic_recorder.h: Function prototypes.
  • I2S_Mic.ioc: STM32CubeMX project configuration.

Recording and Saving Audio to WAV

You can use serial_to_wav.py to record the audio data sent over UART and save it as a 24-bit mono WAV file on your PC.

python serial_to_wav.py --port COM12 --rate 8000 --output output.wav

The script will wait you for pressing the B1 button and then you will see "Mic acquisition: START" and record all incoming audio samples, and stop when you press the button again. The samples are then saved to the specified WAV file.

About

A simple (no bullshit) example on how to use the I2S module for I2S microphones data acquisition.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages