Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PDM example in SDK 15.3.0

I cannot find an example project for using the PDM module on SDK 15.3.0. Can you please direct me to where I will be able to find such an example project?

Thank you.

Parents
  • Hi, Sarnab I too, have the same question as yours. So how far have you reached?I tried the example which Simonr have provided the link for the example. But I am getting the following errors:

    undefined reference to `nrfx_pdm_init' and undefined reference to `nrfx_pdm_start'

    @ Simonr if you have any idea about how can I solve the above errors?

  • Hi Sara, I was able to get it working though I have not extensively tested if the data is valid. To get the nrfx_pdm_xxx() functions you have to include nrfx_pdm.h in your project. Hope that helps. Also if you are able to get meaningful data please let me know what you did!

  • yes it takes me to file to the file and when I right click on nrf_drv_pdm_start it takes me to its macro definition in nrfx_drv_pdm.h  as  nrfx_pdm_start 

  • Hmm, that is strange. What IDE are you using? I am on Segger Embedded Studio (SES). Are you sure your include paths are set correctly?

  • yes I have set the paths correctly.I have added #include "nrf_drv_pdm.h" in main .c file , then added the following in the   .emProject file <file file_name="../../../../../../modules/nrfx/drivers/src/nrfx_pdm.c" />  is there anything else I am missing? 

    And I m using SES too. SDK ver 15.3.0

  • The error was solved, I had not enabled 

    #ifndef PDM_ENABLED
    #define PDM_ENABLED 1

    I programmed the code but now question is how should i check whether pdm is working properly or not? I am not storing anything in flash. For now, I just need the data of pdm so how should I test it to get the results

    static void bsp_event_handler(bsp_event_t event)
    {
        ret_code_t err_code;
    
        switch (event)
        {
            case BSP_EVENT_SLEEP:
                sleep_mode_enter();
                break; // BSP_EVENT_SLEEP
    
            case BSP_EVENT_DISCONNECT:
                err_code = sd_ble_gap_disconnect(m_conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
                break; // BSP_EVENT_DISCONNECT
    
            case BSP_EVENT_WHITELIST_OFF:
                if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
                {
                    err_code = ble_advertising_restart_without_whitelist(&m_advertising);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                }
                break; // BSP_EVENT_KEY_0
              case BSP_EVENT_KEY_1:
                NRF_LOG_INFO("\n Press Button key 1\n");
                NRF_LOG_INFO("\n Erase the flash content !!\n");
    //            err_code = pcm_pstorage_eraseall();
    //            APP_ERROR_CHECK(err_code);
                break;
    
             case BSP_EVENT_KEY_2:
                NRF_LOG_INFO("\n Start:PDM --> PCM\n");
                err_code =  nrf_drv_pdm_start(); 
                APP_ERROR_CHECK(err_code);
                break;
    
             case BSP_EVENT_KEY_3:
                NRF_LOG_INFO("\n Stop:PDM --> PCM\n");
                // stop audio sample
                nrf_drv_pdm_stop();
                break;
    
            default:
                break;
        }
    }
    
    
    
    
    
    
    
    
    
    static void drv_audio_pdm_event_handler(uint32_t *p_buffer, uint16_t length)
    {
    	m_buffer_handler((int16_t *)p_buffer, length);
            int i;
    //        for(i=0;i<= length;i++)
    //        {
    //          NRF_LOG_INFO("%s ",&p_buffer[i]);
    //        }
    //        NRF_LOG_INFO("\n ");
              NRF_LOG_INFO("pdm event handler \n");
    
    }
    
    
    uint32_t drv_audio_init(drv_audio_buffer_handler_t buffer_handler)
    {
    //    nrf_drv_pdm_config_t pdm_cfg = NRF_DRV_PDM_DEFAULT_CONFIG(CONFIG_IO_PDM_CLK,
    //                                                              CONFIG_IO_PDM_DATA,
    //                                                              m_pdm_buff[0],
    //                                                              m_pdm_buff[1],
    //                                                              CONFIG_PDM_BUFFER_SIZE_SAMPLES);
        nrf_drv_pdm_config_t pdm_cfg = NRF_DRV_PDM_DEFAULT_CONFIG(CONFIG_IO_PDM_CLK,CONFIG_IO_PDM_DATA);
        
        if (buffer_handler == NULL)
        {
            return NRF_ERROR_INVALID_PARAM;
        }
        
        m_buffer_handler    = buffer_handler;
        pdm_cfg.gain_l      = CONFIG_PDM_GAIN;
        pdm_cfg.gain_r      = CONFIG_PDM_GAIN;
        
    
        return nrf_drv_pdm_init(&pdm_cfg, drv_audio_pdm_event_handler);
    }
    
    
    
    
    
    
    
    
    
    
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        advertising_init();
        services_init();
        conn_params_init();
        peer_manager_init();
    
        // Start execution.
        NRF_LOG_INFO("Template example started.");
        application_timers_start();
    
    //    advertising_start(erase_bonds);
        uint32_t err_code;
        err_code = drv_audio_init(drv_audio_pdm_event_handler);
        APP_ERROR_CHECK(err_code);
        
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }
    
    .For your reference, I am attaching my code snippet

    I have checked the clk pin on Oscilloscope , the clock is not being generated.In order to generate clk at pin number 22 of nrf52 DK board should I define pin clk as #define CONFIG_IO_PDM_CLK 0x22 or 0x16 (hex value of 22 )instead of 0x22?

  • And when I read the pdm documentation it says I need to change the PSEL.CLK register value? Then how should I do it and with what value? same for PSEL.DIN register. I am confused a lot. Please suggest me the solution to all my doubts.

Reply Children
Related