Skip to main content
Visitor II
April 18, 2023
Question

PDM to PCM via DFSDM getting nothing but static

  • April 18, 2023
  • 1 reply
  • 1362 views

On the BL47E-IOT01A2 there are two mems microphones (MP34DT01) both connected to DFSDM1_DATIN2. I'm trying to extract the data from just one of those boards and convert it to PCM using a DFSDM filter. I've configured DFSDM Channel 2 to connect to PDM/SPI and trigger on the rising edge, and filter 0 I've configured in one-shot mode, connected to DMA, with an oversampling value of 154, and an integral oversampling value of 3. The internal SPI clock on the board is configured to 1/4 the system clock which is 80MHz, thus the SPI clock should be 20MHz. The code to capture the audio is here:

void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) {
	micAudioBuf[micAudioBufIdx] = micRecSample << 8;
	micAudioBufIdx++;
	if (micAudioBufIdx >= AUDIO_LEN) {
		micAudioBufIdx = 0;
		audioFilterCplt = TRUE;
	} else {
		micReset(hdfsdm_filter);
	}
 }
 
void micReset(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) {
	HAL_DFSDM_FilterRegularStop_DMA(hdfsdm_filter);
	HAL_DFSDM_FilterRegularStart_DMA(hdfsdm_filter, &micRecSample, 1);
}

And the transmission code is in the main loop here:

 while (1) {
 // toggle LED2 to indicate activity
 HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
 // if programming the transmitter
 if (audioFilterCplt == TRUE) {
 // reset the flag
 audioFilterCplt = FALSE;
 CDC_Transmit_FS((uint8_t*)micAudioBuf, AUDIO_LEN);
 // Reset the mic and start recording again
 micReset(&hdfsdm1_filter0);
 }
}

I'm able to get the data by connecting to the serial port in python, but the output is just static. Here is the code I'm using to capture the output:

import serial
import wave
import struct
import numpy as np
 
if __name__ == '__main__':
 
 # Replace '/dev/ttyACM0' with the appropriate device path for your system
 ser = serial.Serial('/dev/ttyACM1', timeout=1)
 
 # Configure the WAV file settings
 num_channels = 1
 sample_width = 2 # 16-bit audio
 frame_rate = 44100
 num_frames = 0 # Will be updated as data is received
 compression_type = 'NONE'
 compression_name = 'not compressed'
 
 # Create a new WAV file
 wav_file = wave.open('output.wav', 'wb')
 wav_file.setparams((num_channels, sample_width, frame_rate, num_frames, compression_type, compression_name))
 
 try:
 while True:
 # Read data from the serial port
 data = ser.read(2) # Read 2 bytes at a time (16-bit samples)
 
 if data:
 # Unpack the received data as a signed 16-bit integer
 sample = struct.unpack('<h', data)[0]
 
 # Write the sample to the WAV file
 wav_file.writeframesraw(struct.pack('<h', sample))
 else:
 break
 finally:
 # Close the serial port and WAV file
 ser.close()
 wav_file.close()

I'm not sure what else to try at this point

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    April 20, 2023

    Hi @RBair.3​ ,

    Have you set a CLK > 2MHz?

    In addition I suggest you to use the channel 1 of DFSDM (DFSDM1_CKOUT).

    If not, please try to do it and let me know if you solve the problem :)