nRF5 SDK v14.2.0
PDM

The PDM driver includes two layers: the hardware access layer (HAL) and the driver layer (DRV).

The hardware access layer provides basic APIs for accessing the registers of the PDM peripheral. See the API documentation for the PDM HAL for details.

The driver layer provides APIs on a higher level than the HAL. See the API documentation for the PDM driver for details.

Key features include:

Driver configuration

The PDM default configuration is located in sdk_config.h. The PDM peripheral must be explicitly enabled in sdk_config.h before the driver can be used. You must provide a valid configuration structure and an event handler function during initialization.

The interface is initialized by calling the nrf_drv_pdm_init function. The driver configuration includes:

Example:

static void pdm_event_handler(nrf_drv_pdm_evt_t const * const evt)
{
/* Process the events. */
}
/* ... */
nrf_drv_pdm_config_t pdm_cfg = NRF_DRV_PDM_DEFAULT_CONFIG(CLK_PIN, DOUT_PIN);
ret_code_t err_code = nrf_drv_pdm_init(&pdm_cfg, pdm_event_handler);

Using the PDM driver

After initialization, the sampling procedure is started by calling the nrf_drv_pdm_start function. The driver will immediately request a sample buffer from the user by generating an event (nrf_drv_pdm_evt_t::buffer_requested is set). To start the sampling, you must pass the buffer by calling nrf_drv_pdm_buffer_set. After starting the sampling process, another event is generated to request the next buffer which will be filled right after the current one. From now on, while the sampling is running, the driver will release every filled buffer back to the user (nrf_drv_pdm_evt_t::buffer_released pointer is set) and request the next one. To preserve the continuity, you must prevent the driver from releasing all currently owned buffers by supplying a new one with an nrf_drv_pdm_buffer_set call after every request. In case of underflow, an error is generated (nrf_drv_pdm_evt_t::error is set). Note that the request, release, and error condition may occur at the same time within one event. When nrf_drv_pdm_stop is called, sampling will stop and the driver will generate release events for all currently owned buffers.

The output PCM samples are stored as 16-bit signed integers. If stereo mode is selected, the buffer will contain alternating left and right channel samples.


Documentation feedback | Developer Zone | Subscribe | Updated