This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PDM example on Stereo mode

I have two mic , how can I get data from Left and Right mic? Is there any example code to help me?

My code like this : ( I think the data from pdm_data_handler is like 0xFFFFxxxx or 0x0000xxxx, when I removed a mic from my PCBA)

void user_pdm_init(void)
{
uint32_t err_code = NRF_SUCCESS;
nrfx_pdm_config_t config = NRFX_PDM_DEFAULT_CONFIG(PDM_CLK,PDM_DIN);
err_code = nrfx_pdm_init(&config, pdm_data_handler);
APP_ERROR_CHECK(err_code);

nrf_gpio_cfg_output(PDM_LEFT_PIN);
nrf_gpio_cfg_output(PDM_RIGHT_PIN);

nrf_gpio_pin_set(PDM_RIGHT_PIN);
nrf_gpio_pin_clear(PDM_LEFT_PIN);
}

#define PDM_BUFF_LEN 320 //1000
#define PDM_CLCA_LEN 10

static uint32_t pdm_buffer_rx[2][PDM_BUFF_LEN];

static void pdm_data_handler(nrfx_pdm_evt_t const * p_evt)
{

ASSERT(p_evt);
if (p_evt->error == NRFX_PDM_ERROR_OVERFLOW )
{
return;
}
if(p_evt->buffer_released != 0)
{
pdm_block_to_fill = pdm_buffer_rx[get_finished_buffer()];
}
if(p_evt->buffer_requested)
{
/*curr_buff_index = get_finished_buffer();
uint32_t* buff = pdm_buffer_rx[curr_buff_index];
uint8_t i = 0;
for(i=0; i < 4;i++)
{
uint32_t h = ((buff[i]) >> 16) & (uint32_t)0xffff;
uint32_t l = ((buff[i]) ) & (uint32_t)0xffff;

//pdm_LOG("buff = %x, pdm_buffer_rx =%x,%x h =%x,l = %x\r\n",buff[i],(pdm_buffer_rx[curr_buff_index][i]),pdm_buffer_rx[curr_buff_index][i+1],h,l);
}
*/
nrfx_pdm_buffer_set((int16_t *)pdm_buffer_rx[1 - curr_buff_index],PDM_BUFF_LEN);
}
}

Parents Reply Children
No Data
Related