<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF52840 PDK - PDM - Where to call nrfx_pdm_buffer_set()?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33870/nrf52840-pdk---pdm---where-to-call-nrfx_pdm_buffer_set</link><description>Hi, 
 I&amp;#39;m using nRF5 SDK v15.0.0, and I&amp;#39;m trying to use the PDM peripheral for a digital microphone. I&amp;#39;m modifying the driver from ThingySDK, but I can&amp;#39;t seem to find where nrfx_pdm_buffer_set() is set. From what I understood from the PDM driver description</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 May 2019 00:42:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33870/nrf52840-pdk---pdm---where-to-call-nrfx_pdm_buffer_set" /><item><title>RE: nRF52840 PDK - PDM - Where to call nrfx_pdm_buffer_set()?</title><link>https://devzone.nordicsemi.com/thread/189997?ContentTypeID=1</link><pubDate>Thu, 30 May 2019 00:42:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f953836-df5d-458b-81f3-4d0991111176</guid><dc:creator>Funkelfetisch</dc:creator><description>&lt;p&gt;Hey Abdul,&lt;/p&gt;
&lt;p&gt;did you ever manage to get your code working?&lt;/p&gt;
&lt;p&gt;Best&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 PDK - PDM - Where to call nrfx_pdm_buffer_set()?</title><link>https://devzone.nordicsemi.com/thread/135521?ContentTypeID=1</link><pubDate>Mon, 11 Jun 2018 09:16:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:830330db-3db7-4b6c-bf23-73b888f6d616</guid><dc:creator>abdulhaseeb</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve updated the driver, however now I&amp;#39;m facing the problem that the buffer is not being updated with new values. I have a single buffer now (of 800 samples) that should be filled periodically. I&amp;#39;m trying to discontinue sampling as soon as the buffer is full, and then wait for the next cycle to start over again.&lt;/p&gt;
&lt;p&gt;Please see the following code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;stdint.h&amp;quot;
#include &amp;quot;stdbool.h&amp;quot;
#include &amp;quot;stdlib.h&amp;quot;
#include &amp;quot;string.h&amp;quot;

#include &amp;quot;nrf_assert.h&amp;quot;
#include &amp;quot;nrf_error.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;pdm.h&amp;quot;
#include &amp;quot;nrfx_pdm.h&amp;quot;
#include &amp;quot;nrf_drv_pdm.h&amp;quot;
#include &amp;quot;nrf_pdm.h&amp;quot;

#include &amp;quot;math.h&amp;quot;

int                  sound_level = 0;
static volatile bool buffer_full = false;
int16_t buffer[BUFFER_SIZE];      

static void pdm_event_handler(nrfx_pdm_evt_t const * const p_evt)
{	

    ret_code_t err_code;

    if(p_evt-&amp;gt;buffer_requested)
    {
        err_code =  nrfx_pdm_buffer_set(buffer, BUFFER_SIZE);
        APP_ERROR_CHECK(err_code);
    }

    if(p_evt-&amp;gt;buffer_released)
    {
        
	/* Stop PDM */
        err_code = nrfx_pdm_stop();
        buffer_full = true;

        /* Process current buffer */
        int sum_of_squares = 0;
        int16_t *p_buffer_8 = (int16_t*)p_evt-&amp;gt;buffer_released;

        for( int16_t i = 0 ; i &amp;lt; BUFFER_SIZE ; i++ )
        {
            sum_of_squares += p_buffer_8[0] * p_buffer_8[0];
            p_buffer_8++;
        }

        sound_level = sqrt(sum_of_squares / BUFFER_SIZE) ;


        /* Clear MIC power pin */
        nrf_gpio_pin_clear(MIC_PWR_CTRL);

        /* Configure DATA power pin */
        nrf_gpio_cfg_default(MIC_DATA);
        
    }
}

//get PDM buffer
uint32_t get_PDM_buffer(void)
{
    ret_code_t err_code;

    /* Set MIC power pin */
    nrf_gpio_pin_set(MIC_PWR_CTRL);

    /* Wait for 50ms (for Knowles microphone) to wake up. Add more delay afterwards to ignore useless data */
    //nrf_delay_ms(50);

    /* Start PDM */
    err_code = nrfx_pdm_start();
    APP_ERROR_CHECK(err_code);

    return err_code;
}


uint32_t drv_audio_enable(void)
{
    ret_code_t err_code;

    /* Set MIC power pin */
    nrf_gpio_pin_set(MIC_PWR_CTRL);

    /* Wait for 50ms (for Knowles microphone) to wake up. Add more delay afterwards to ignore useless data */
    nrf_delay_ms(50);

    err_code = nrfx_pdm_start();
    
    APP_ERROR_CHECK(err_code);

    while (!buffer_full)
    {
      __WFE();
    }
    buffer_full = false;

    return err_code;
}


uint32_t drv_audio_disable(void)
{
    ret_code_t err_code;

    /* Clear MIC power pin */
    nrf_gpio_pin_clear(MIC_PWR_CTRL);

    /* Configure DATA power pin */
    nrf_gpio_cfg_default(MIC_DATA);

    return err_code;
}


uint32_t drv_audio_init(void)
{
    nrfx_pdm_config_t pdm_cfg = NRFX_PDM_DEFAULT_CONFIG(MIC_CLK, MIC_DATA);

    pdm_cfg.gain_l          = CONFIG_AUDIO_PDM_GAIN;
    pdm_cfg.gain_r          = CONFIG_AUDIO_PDM_GAIN;

    return nrf_drv_pdm_init(&amp;amp;pdm_cfg, pdm_event_handler);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 PDK - PDM - Where to call nrfx_pdm_buffer_set()?</title><link>https://devzone.nordicsemi.com/thread/135210?ContentTypeID=1</link><pubDate>Thu, 07 Jun 2018 14:17:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6bc780f-df8d-4390-8065-f89a9d79f06a</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi, sorry for the late response. Did you find a solution, or do you still need help?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>