This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using PDM Mic on nRF9160DK

I was wondering if there were any good examples of how to get a PDM device (in this case a microphone) working on the nRF9160DK. I've read parts of the datasheet and I've been able to find the nrfx_pdm driver in the SDK but am unaware what pins to use to get it to read data and how to use the easy-dma feature.

Any pointers in the right direction are appreciated. Thank you

  • Hi,

    I am sorry, it seems I have played too little with nRF Connect SDK. Setting NRFX_PDM_ENABLED in nrfx_config_nrf9160 does not have effect if it is defined somewhere else. Can you try to set it to 1 in prj.conf also/instead? You could also try to replace:

    #ifndef NRFX_PDM_ENABLED
    #define NRFX_PDM_ENABLED 0
    #endif

    with:

    #undef NRFX_PDM_ENABLED
    #define NRFX_PDM_ENABLED 1

    Note that PDM is not properly integrated with Zephyr as of now. It is missing in the device tree, so there are no register definitions etc. If you need PDM now you have to add it yourself, unfortunately.

  • So, I tried adding  your undefine and then define into my main.c file, but that didn't help matters. I'm still getting the same undefined reference error.

    I'm including my file, just in case there is a glaring error I'm missing

    /*  
    		C Program to run a pulse density modulation (PDM) Microphone on the nRF9160 Dev Kit using the Nordic SDK
    */
    
    #include <nrf9160.h>
    #include <zephyr.h>
    #include <misc/printk.h>
    #include <string.h>
    #include <stdlib.h>
    #include <nrfx_pdm_ns.h>
    
    
    
    
    #include <gpio.h>
    
    #undef NRFX_PDM_ENABLED
    #define NRFX_PDM_ENABLED
    
    #define PDM_BUF_ADDRESS 0x20000000 // buffer address in RAM
    #define PDM_BUF_SIZE 256 //size in 32 bit words --> 40 bytes
    
    int16_t pdm_buf[PDM_BUF_SIZE];
    
    
    void nrfx_pdm_event_handler(nrfx_pdm_evt_t const *const p_evt)
    {
    	if (p_evt->buffer_requested) {
    		nrfx_pdm_buffer_set(pdm_buf, PDM_BUF_SIZE);
    	}
    	if (p_evt->buffer_released != 0) {
    		printk("Out: %.2x %2x\r\n", (uint16_t)pdm_buf[0],
    		       (uint16_t)pdm_buf[1]);
    	}
    }
    
    static void pdm_init(void)
    {
    	nrfx_pdm_config_t pdm_config = NRFX_PDM_DEFAULT_CONFIG(10, 11); /*configures CLK to pin 10 and Din to pin 11*/
    	nrfx_pdm_init(&pdm_config, nrfx_pdm_event_handler);
    }
    
    void main(void)
    {
    	printk("Starting PDM program!\n");
    	printk("PDM Buffer size: %d\n", (PDM_BUF_SIZE * 4));
    	printk("PDM Starting Address: %x\n", PDM_BUF_ADDRESS);
    
    	pdm_init();
    }

  • i should add, I've also tried include <nrfx_pdm.h> as well

  • Ah, I see. There no reason to define NRFX_PDM_ENABLED in the main.c file.

    Did you put it in nrfx_config_nrf9160? The file holding the implementation of nrfx_pdm_buffer_set, nrfx_pdm.c, includes nrfx.h, which includes nrfx_config.h which includes nrfx_config_nrf9160.h, which is where we set the configuration. So it should be included in that case.

    If it still does not work, then perhaps you can print some warnings or similar using, for instance, #warning to track where the definition is set to which value, and where it "gets lost". I have not spotted it, at least.

    By the way, are you using NCS 1.0.0?

Related