mems microphone test on the STM32L4 DISCOVERY dev board using bit banging. very primitive and not recommended, but works.

Dependencies:   BSP_DISCO_L476VG mbed

a shitty MICROPHONE RECORDER for the DISCOVERY STM32L476 dev board

Records audio and sends it via UART (to the PC) as text-encoded samples sample rate: 25600 Hz (ish) sample format: 8 bit unsigned (0-255) uart baud rate: 115,200

press the UP and DOWN keys to set the recording size press RIGHT to perform recording. The result is sent via UART after it is recorded can record up to 31744 samples, doesn't want to allocate more memory (I don't know why though)

you can encode the recording from the UART text dump into a .wav file in Matlab, by doing this:

wavedata = wavedata - 128; wavedata = wavedata / 256; audiowrite('wave.wav', wavedata, 25600);

where "wavedata" is a vector containing just the NUMBERS from the imported UART log

PRINCIPAL OF OPERATION:

The microphone is read by bit-banning it's clock pin (PE_9) and reading it's data pin (PE_7). The hardware PDM decoder should have been used for this, but was not. The hardware SPI or I2C would also be a good choice, but there happens to be no such hardware functionality on that specific set of pins.

The microphone returns PDM encoded audio data. This is a 1-bit format. The data is more likely to be a "1" the higher the current readout from the microphone. In practice this means that if we sample this fast enough and then low-pass it in a 8 or 16 bit format, we should get an audio waveform.

Method of filtering

The MCU collects 64 1-bit samples and adds them. This returns a value between 0 and 64 (a 6 bit sample). The 1-bit sampling is at a clock of about 1.64Mhz. Therefore, the 6bit samples are produced at 1,700,000 / 64 = 25,600 Hz

Theese 6bit samples are stored in a 7-slot cyclic buffer. The content of this buffer is summed whenever a new 6bit sample is added. The "middle" sample is counted twice.

This produces a 9-bit sample, which is halved to produce the final 8bit sample that is stored in RAM

After the recording is finished, the content of the RAM is sent over UART in text form.

This is a silly implementation of the microphone, but you may find some of it useful.

Changes

RevisionDateWhoCommit message
0:dcefe9e5ec82 2016-07-15 Mawrk works default tip