Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM

Hi,

   Iam currently working with NRF5340 module for the integration of MEMS microphone (IM72D128V01). need to configure PCM sampling rate as 2KHz.

                .min_pdm_clk_freq =  120000,
                .max_pdm_clk_freq = 160000,

this is the configuration that I have given to configure PCM as 2Khz. but while probing the data and clock pins. Iam able to view the clock but no data out.

 

note: have use the DMIC example code.

1) is there any way to use this microphone (IM72D128V01)?

      attaching the screenshot of MEMs microphone.

2) can u suggest the step to validate the data?

        2.1) how to convert the hex data to audio. and validate?

  • I have been able to use a similar MEMS microphone from Infineon with the 5340. If you want to configure the sampling rate to 2 KHz you should set the pcm_rate field in the dmic_cfg structure:

    cfg.streams[0].pcm_rate = <SAMPLE_RATE>;

    Regarding point number 2, you could stream the 16-bit data over the serial port and have a python script convert it into a .wav file. You should then be able to listen to the recorded data or analyze it using some kind of software.

    Also I think the maxmium and minimum clk frequencies you have specified are incorrect. They should reflect the microphone's specification, which I think, if reading the datasheet correctly is 440 KHz to 5.04 Mhz.

  • thanks for the reply.

    1) is there any way to down sample (pcm) using any api?

             

  • Are you referring to the conversion between PDM to PCM? Because the DMIC api will do this for you. dmic_read will give you a "usable" format (PCM) that can be directly used to create a .wav file.

    Does this answer your question or did I misinterpet it?

  • how we create the .wave file .. can u explain in detail. 
    share example if any.

  • This code should work, it has been a while since I used it. I think it expects binary data (not hex string). I hope this helps.

    import serial
    import numpy as np
    from scipy.io import wavfile
    
    # Configuration: duration in seconds and sampling rate in Hz
    duration = 5  # Record for 5 seconds
    Fs = 2000    # Sampling rate of 2000 Hz
    
    # Open the serial port
    ser = serial.Serial('/dev/ttyACM0', baudrate=115200, timeout=1)
    
    # Number of samples to read (calculated from duration and sampling rate)
    num_samples = int(duration * Fs)
    
    # Buffer to store audio data
    audio_data = np.zeros(num_samples, dtype=np.int16)
    
    bytes_per_sample = 2
    samples_read = 0
    i = 0
    
    # Read audio data from the serial port
    while i < num_samples:
        # Read two bytes (16-bit integer)
        data_bytes = ser.read_all()
        
        # Ensure there are exactly 2 bytes to read
        if len(data_bytes) % 2 != 0:
            print(f"Error: {len(data_bytes)} bytes read")
            continue
    
        # Convert bytes to integer (little-endian)
        for j in range(0, len(data_bytes), bytes_per_sample):
            sample = int.from_bytes(data_bytes[j:j+bytes_per_sample], byteorder='little', signed=True)
            audio_data[i] = sample
            i += 1
        
        # Increment the number of samples read
        samples_read += len(data_bytes) / bytes_per_sample
    
    # Close the serial port
    ser.close()
    
    # Path to the output file
    output_file = 'output.wav'
    
    # Write to .wav file
    wavfile.write(output_file, Fs, audio_data)
    
    print(f"Audio data saved to {output_file}")

Related