SDK17.1.0 nRF52840 PDM

Hello Nordic support,

I work on receive data from the microphone mp34dt05-a . I have some question.
1- How to enable PDM in SDK_CONFIG.H .

2- For this project do I need enable easydma for convert PDM to PCM.if your answer is yes, then 
 how to enable this.

I write this code in "SDK.config.h"

// <e> PDM_ENABLED - nrf_drv_pdm - PDM peripheral driver - legacy layer
//==========================================================
#ifndef PDM_ENABLED
#define PDM_ENABLED 1
#endif
// <o> PDM_CONFIG_MODE  - Mode
 
// <0=> Stereo 
// <1=> Mono 

#ifndef PDM_CONFIG_MODE
#define PDM_CONFIG_MODE 1
#endif

// <o> PDM_CONFIG_EDGE  - Edge
 
// <0=> Left falling 
// <1=> Left rising 

#ifndef PDM_CONFIG_EDGE
#define PDM_CONFIG_EDGE 0
#endif

// <o> PDM_CONFIG_CLOCK_FREQ  - Clock frequency
 
// <134217728=> 1000k 
// <138412032=> 1032k (default) 
// <142606336=> 1067k 

#ifndef PDM_CONFIG_CLOCK_FREQ
#define PDM_CONFIG_CLOCK_FREQ 138412032
#endif

// <o> PDM_CONFIG_IRQ_PRIORITY  - Interrupt priority
 

// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest) 
// <1=> 1 
// <2=> 2 
// <3=> 3 
// <4=> 4 
// <5=> 5 
// <6=> 6 
// <7=> 7 

#ifndef PDM_CONFIG_IRQ_PRIORITY
#define PDM_CONFIG_IRQ_PRIORITY 7
#endif

// </e>
// <e> NRFX_PDM_ENABLED - nrfx_pdm - PDM peripheral driver
//==========================================================
#ifndef NRFX_PDM_ENABLED
#define NRFX_PDM_ENABLED 1
#endif
// <o> NRFX_PDM_CONFIG_MODE  - Mode
 
// <0=> Stereo 
// <1=> Mono 

#ifndef NRFX_PDM_CONFIG_MODE
#define NRFX_PDM_CONFIG_MODE 1
#endif

// <o> NRFX_PDM_CONFIG_EDGE  - Edge
 
// <0=> Left falling 
// <1=> Left rising 

#ifndef NRFX_PDM_CONFIG_EDGE
#define NRFX_PDM_CONFIG_EDGE 0
#endif

// <o> NRFX_PDM_CONFIG_CLOCK_FREQ  - Clock frequency
 
// <134217728=> 1000k 
// <138412032=> 1032k (default) 
// <142606336=> 1067k 

#ifndef NRFX_PDM_CONFIG_CLOCK_FREQ
#define NRFX_PDM_CONFIG_CLOCK_FREQ 138412032
#endif

// <o> NRFX_PDM_CONFIG_IRQ_PRIORITY  - Interrupt priority
 
// <0=> 0 (highest) 
// <1=> 1 
// <2=> 2 
// <3=> 3 
// <4=> 4 
// <5=> 5 
// <6=> 6 
// <7=> 7 

#ifndef NRFX_PDM_CONFIG_IRQ_PRIORITY
#define NRFX_PDM_CONFIG_IRQ_PRIORITY 7
#endif

// <e> NRFX_PDM_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_PDM_CONFIG_LOG_ENABLED
#define NRFX_PDM_CONFIG_LOG_ENABLED 1
#endif
// <o> NRFX_PDM_CONFIG_LOG_LEVEL  - Default Severity level
 
// <0=> Off 
// <1=> Error 
// <2=> Warning 
// <3=> Info 
// <4=> Debug 

#ifndef NRFX_PDM_CONFIG_LOG_LEVEL
#define NRFX_PDM_CONFIG_LOG_LEVEL 3
#endif

// <o> NRFX_PDM_CONFIG_INFO_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

#ifndef NRFX_PDM_CONFIG_INFO_COLOR
#define NRFX_PDM_CONFIG_INFO_COLOR 0
#endif

// <o> NRFX_PDM_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

#ifndef NRFX_PDM_CONFIG_DEBUG_COLOR
#define NRFX_PDM_CONFIG_DEBUG_COLOR 0
#endif

// </e>

// </e>
/* PDM */
// <e> NRFX_PDM_ENABLED - nrfx_pdm - PDM peripheral driver
//==========================================================
#ifndef NRFX_PDM_ENABLED
#define NRFX_PDM_ENABLED 1
#define PDM_ENABLED 1
#endif

#ifndef PDM_CONFIG_USE_EASY_DMA
#define PDM_CONFIG_USE_EASY_DMA 1
#endif 

//#if (PDM_ENABLED == 1)
//#define PDM_CONFIG_MODE            NRF_PDM_MODE_MONO
//#define PDM_CONFIG_EDGE            NRF_PDM_EDGE_LEFTFALLING
//#define PDM_CONFIG_CLOCK_FREQ      NRF_PDM_FREQ_1032K
//#define PDM_CONFIG_IRQ_PRIORITY    APP_IRQ_PRIORITY_LOW
//#endif
// <e> PDM_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef PDM_CONFIG_LOG_ENABLED
#define PDM_CONFIG_LOG_ENABLED 1
#endif
// <o> PDM_CONFIG_LOG_LEVEL  - Default Severity level
 
// <0=> Off 
// <1=> Error 
// <2=> Warning 
// <3=> Info 
// <4=> Debug 

#ifndef PDM_CONFIG_LOG_LEVEL
#define PDM_CONFIG_LOG_LEVEL 3
#endif

// <o> PDM_CONFIG_INFO_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

#ifndef PDM_CONFIG_INFO_COLOR
#define PDM_CONFIG_INFO_COLOR 0
#endif

// <o> PDM_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

#ifndef PDM_CONFIG_DEBUG_COLOR
#define PDM_CONFIG_DEBUG_COLOR 0
#endif

// </e>



and this is my cod in main.c
#include <stdio.h>
#include "nrf_delay.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "boards.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_drv_pdm.h"
#include "nrf_pdm.h"

#define CONFIG_PDM_BUFFER_SIZE_SAMPLES 320

// <o> PDM Decimation Filter Gain <0x00-0x50>
// <i> For details on the PDM decimation filter, see the 'Decimation filter' section in the nRF52 Product Specification document.


#define CONFIG_PDM_GAIN 0x28


/**@brief Audio buffer handler. */
//typedef void (*drv_audio_buffer_handler_t)(nrfx_pdm_evt_t const *p_buffer, uint16_t samples);


static int16_t m_pdm_buff[2][CONFIG_PDM_BUFFER_SIZE_SAMPLES];

//static drv_audio_buffer_handler_t m_buffer_handler;


static void m_audio_buffer_handler(int16_t *p_buffer, uint16_t samples)
{
    // Audio processing
}

static void drv_audio_pdm_event_handler(nrfx_pdm_evt_t const *p_buffer, uint16_t length)
{
	
        if (p_buffer->buffer_requested) {
		nrfx_pdm_buffer_set(m_pdm_buff, 3027);
	}
	if (p_buffer->buffer_released != 0) {
		printf("Out: %4x @ 0x%x\r\n %4x @ 0x%x\r\n",
		       (uint16_t)m_pdm_buff[0], &m_pdm_buff[0],
		       (uint16_t)m_pdm_buff[1], &m_pdm_buff[1]);
	}

        //m_buffer_handler((int16_t *)p_buffer, length);
}



uint32_t drv_audio_init( )
{
    nrf_drv_pdm_config_t pdm_cfg = NRF_DRV_PDM_DEFAULT_CONFIG(MIC_CLK,MIC_DOUT);
    pdm_cfg.clock_freq=PDM_PDMCLKCTRL_FREQ_1333K;
    return nrf_drv_pdm_init(&pdm_cfg, drv_audio_pdm_event_handler);
}


int main(void)
{
    uint32_t err_code = NRF_SUCCESS;



    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("PDM  example started.\n\t");
    
    err_code =nrfx_pdm_enable_check();
    APP_ERROR_CHECK(err_code);


    // Initialize PDM and start receiving PDM data    //
    nrfx_pdm_buffer_set(&m_pdm_buff[0],CONFIG_PDM_BUFFER_SIZE_SAMPLES);

    err_code = drv_audio_init();
    APP_ERROR_CHECK(err_code);
    
    err_code =  nrf_drv_pdm_start();
    APP_ERROR_CHECK(err_code);
 
	for (int i = 0; i < 300; i++) {
          int k = 5;
          for (volatile int j = 0; j < 100; j++) {
                k = !k;
		}
	}
         printf("%4x is current value at %x\n", m_pdm_buff[0], &m_pdm_buff);

            


}

 
the microphone PDM clock is 1.2Mhz to 3.25Mhz and I set this clock 1333Khz.
I can not receive data correct.
this figure has PDM clock.

and this figure is my data output.


 and other figure.

can you help me to run the microphone.

Parents Reply Children
No Data
Related