PDM driver

group nrfx_pdm

Pulse Density Modulation (PDM) peripheral driver.



Maximum supported PDM buffer size.


PDM additional ratio configuration.


PDM additional master clock source configuration.

NRFX_PDM_DEFAULT_CONFIG(_pin_clk, _pin_din)

PDM driver default configuration.

This configuration sets up PDM with the following options:

  • mono mode

  • data sampled on the clock falling edge

  • frequency: 1.032 MHz

  • standard gain

  • _pin_clk[in] CLK output pin.

  • _pin_din[in] DIN input pin.


typedef void (*nrfx_pdm_event_handler_t)(nrfx_pdm_evt_t const *p_evt)

Handler for the PDM interface ready events.

This event handler is called on a buffer request, an error or when a buffer is full and ready to be processed.

Param p_evt

[in] Pointer to the PDM event structure.


enum nrfx_pdm_error_t

PDM error type.


enumerator NRFX_PDM_NO_ERROR

No error.


Overflow error.


nrfx_err_t nrfx_pdm_init(nrfx_pdm_config_t const *p_config, nrfx_pdm_event_handler_t event_handler)

Function for initializing the PDM interface.

  • p_config[in] Pointer to the structure with the initial configuration.

  • event_handler[in] Event handler provided by the user. Cannot be NULL.

Return values
  • NRFX_SUCCESS – Initialization was successful.

  • NRFX_ERROR_INVALID_STATE – The driver is already initialized.

  • NRFX_ERROR_INVALID_PARAM – Invalid configuration was specified.

void nrfx_pdm_uninit(void)

Function for uninitializing the PDM interface.

This function stops PDM sampling, if it is in progress.

NRFX_STATIC_INLINE uint32_t nrfx_pdm_task_address_get(nrf_pdm_task_t task)

Function for getting the address of a PDM interface task.

  • task[in] Task.


Task address.

NRFX_STATIC_INLINE bool nrfx_pdm_enable_check(void)

Function for getting the state of the PDM interface.

Return values
  • true – The PDM interface is enabled.

  • false – The PDM interface is disabled.

nrfx_err_t nrfx_pdm_start(void)

Function for starting the PDM sampling.

Return values
  • NRFX_SUCCESS – Sampling was started successfully or was already in progress.

  • NRFX_ERROR_BUSY – Previous start/stop operation is in progress.

nrfx_err_t nrfx_pdm_stop(void)

Function for stopping the PDM sampling.

When this function is called, the PDM interface is stopped after finishing the current frame. The event handler function might be called once more after calling this function.

Return values
  • NRFX_SUCCESS – Sampling was stopped successfully or was already stopped before.

  • NRFX_ERROR_BUSY – Previous start/stop operation is in progress.

nrfx_err_t nrfx_pdm_buffer_set(int16_t *buffer, uint16_t buffer_length)

Function for supplying the sample buffer.

Call this function after every buffer request event.

  • buffer[in] Pointer to the receive buffer. Cannot be NULL.

  • buffer_length[in] Length of the receive buffer in 16-bit words.

Return values
  • NRFX_SUCCESS – The buffer was applied successfully.

  • NRFX_ERROR_BUSY – The buffer was already supplied or the peripheral is currently being stopped.

  • NRFX_ERROR_INVALID_STATE – The driver was not initialized.

  • NRFX_ERROR_INVALID_PARAM – Invalid parameters were provided.

struct nrfx_pdm_evt_t
#include <nrfx_pdm.h>

PDM event structure.

Public Members

bool buffer_requested

Buffer request flag.

int16_t *buffer_released

Pointer to the released buffer. Can be NULL.

nrfx_pdm_error_t error

Error type.

struct nrfx_pdm_config_t
#include <nrfx_pdm.h>

PDM interface driver configuration structure.

Public Members

nrf_pdm_mode_t mode

Interface operation mode.

nrf_pdm_edge_t edge

Sampling mode.

uint8_t pin_clk

CLK pin.

uint8_t pin_din

DIN pin.

nrf_pdm_freq_t clock_freq

Clock frequency.

nrf_pdm_gain_t gain_l

Left channel gain.

nrf_pdm_gain_t gain_r

Right channel gain.

uint8_t interrupt_priority

Interrupt priority.

bool skip_gpio_cfg

Skip GPIO configuration of pins.

When set to true, the driver does not modify any GPIO parameters of the used pins. Those parameters are supposed to be configured externally before the driver is initialized.

bool skip_psel_cfg

Skip pin selection configuration.

When set to true, the driver does not modify pin select registers in the peripheral. Those registers are supposed to be set up externally before the driver is initialized.


When both GPIO configuration and pin selection are to be skipped, the structure fields that specify pins can be omitted, as they are ignored anyway.