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 Einar,

    so I added these lines to zephyr\ext\hal\nordic\CMakeLists.txt

    zephyr_sources_ifdef(CONFIG_NRFX_PDM nrfx/drivers/src/nrfx_pdm.c)
    zephyr_sources_ifdef(CONFIG_NRFX_PDM_NS nrfx/drivers/src/nrfx_pdm_ns.c)

    I then re-built the project and tried to build the solution, and still got the same undefined reference errors. Did I add the correct lines, or was there something I missed?

    Thanks

  • Hi,

     

    This isn't straight-forward due to the PDM not being natively supported.

    1. First thing is to add the sources in zephyr/ext/hal/nordic/CMakeLists.txt:

    zephyr_sources_ifdef(CONFIG_NRFX_PDM nrfx/drivers/src/nrfx_pdm.c)

     

    2. And you also need to add these two lines to zephyr/ext/hal/nordic/Kconfig:

    config NRFX_PDM
        bool

     

    3. Now we start on the application side. you need to append this to your prj.conf:

    CONFIG_COMPILER_OPT="-DNRF_PDM=NRF_PDM_NS -DNRFX_PDM_ENABLED=1"

     

    This will enable the module, and define NRF_PDM to NRF_PDM_NS.

     

    4. Next up is selecting the NRFX_PDM in Kconfig. This is a symbol that needs to be selected by a module, so let's add one to your application.

    Create the file "Kconfig" in nrf/samples/nrf9160/my_sample/ and paste into the file:

    mainmenu "PDM test"
    
    config FORCE_PDM
    	bool "Test to force PDM"
    	select NRFX_PDM
        default y
    
    source "$ZEPHYR_BASE/Kconfig.zephyr"

     

    You can name the config what-ever you'd like, in this case it is "FORCE_PDM", and it's default y (so no need to manually add it to your prj.conf in this case).

      

    Could you try these steps and see if it compiles properly now?

    Sorry for the comprehensive workaround and the inconvenience.

     

    *edit* in order to use the non-blocking (ie: the handler function), you have to add this to your main to forward the interrupt vector:

    ISR_DIRECT_DECLARE(pdm_isr_handler)
    {
    	nrfx_pdm_irq_handler();
    	ISR_DIRECT_PM(); /* PM done after servicing interrupt for best latency
    			  */
    
    	return 1; /* We should check if scheduling decision should be made */
    }
    
    void main(void)
    {
    	IRQ_DIRECT_CONNECT(PDM_IRQn, 0,
    			   pdm_isr_handler, 0);
    	/* Rest of main */

     

    Kind regards,

    Håkon

  •    I'm looking at getting a PDM mic working with an nRF9160, but on NCS 2.3/TFM 1.6/Zephyr 3.2.99.

    Is there an up-to-date reference on how to do this, and furthermore is it possible to use the Zephyr DMIC library on-top of the Nrfx PDM driver?

Related