Is there any working PDM example for nRF52832? or can anyone give a sample initialization code for PDM with easyDMA using the inbuilt nrf_pdm_drv functions?
We don't have any full examples yet. But here is some code to get you started:
#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
// <o> PDM CLK Pin
#define CONFIG_IO_PDM_CLK 0x06
// <o> PDM DATA Pin
#define CONFIG_IO_PDM_DATA 0x05
// <o> PDM Microphone Power Control Pin
#define CONFIG_IO_PDM_MIC_PWR_CTRL 0x1A
/**@brief Audio buffer handler. */
typedef void (*drv_audio_buffer_handler_t)(int16_t *p_buffer, uint16_t samples);
static int16_t m_pdm_buff[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(uint32_t *p_buffer, uint16_t length)
m_buffer_handler((int16_t *)p_buffer, length);
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,
if (buffer_handler == NULL)
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);
* @brief Function for application main entry.
err_code = drv_audio_init(m_audio_buffer_handler);
err_code = nrf_drv_pdm_start();
// Do nothing.
/** @} */
I also recommend taking a look at the PDM driver. It's located in SDK_folder\components\drivers_nrf\pdm
Thanks Sigurd. That helped me a lot. The program executes into the "drv_audio_pdm_event_handler" but I am unable to capture any data from the "p_buffer". It returns either zero sometimes or 0xFFF8FFF8.
I am using SPK0838HT4H PDM microphone in my application. The configuration is mono. I have made the(L/R)select pin as ground(which is R). The configuration is set as same as above. I have changed the frequency with all the three options. But there is no convincing result. What are the things I should look into?
Are you samling data on the correct edge of PDM_CLK?
Try to set pdm_cfg.edge = NRF_PDM_EDGE_LEFTRISING; in drv_audio_init()
pdm_cfg.edge = NRF_PDM_EDGE_LEFTRISING;
edge settings is currently default NRF_PDM_EDGE_LEFTFALLING, which is what the application note says.
I tried with NRF_PDM_EDGE_LEFTRISING as well but similar result. It is going into the drv_audio_pdm_event_handler. What is the significance of CONFIG_PDM_BUFFER_SIZE_SAMPLES ?
I am not able to move any further from this. Is there anything I can check with?