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

PDM Mic on nRF9160DK and SPM

Hi

I am working on interfacing PDM mic (Adafruit PDM MEMS Microphone) with nRF9160 DK, I used AT Client sample as a base code and I have added all rest code from the following ticket devzone.nordicsemi.com/.../pdm-working step by step and other related tickets. my project is successfully build but when i flashed it in nRF9160 DK I am getting repeated output in LTE link monitor as shown below in txt file. The output keep repeating information about SPM which I did not change anything in please find the attached code below. Thank you 

0045.LTEmonitorlogfile.txt 

/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include <zephyr.h>
#include <stdio.h>
#include <drivers/uart.h>
#include <string.h>

#include <nrfx_pdm.h>
#include <hal/nrf_gpio.h>
#include <nrf9160.h>


#define PDM_BUF_SIZE 3072  //length of buffer in 16 bit words

int16_t pdm_buf[PDM_BUF_SIZE];

/**@brief Recoverable BSD library error. */
void bsd_recoverable_error_handler(uint32_t err)
{
	printk("bsdlib recoverable error: %u\n", err);
}

void nrfx_pdm_event_handler(nrfx_pdm_evt_t const *const p_evt)
{
	if (p_evt->buffer_requested) {
		nrfx_pdm_buffer_set(pdm_buf, PDM_BUF_SIZE);
	}
	if (p_evt->buffer_released != 0) {
		printk("Out: %4x @ 0x%x\r\n %4x @ 0x%x\r\n",
		       (uint16_t)pdm_buf[0], &pdm_buf[0],
		       (uint16_t)pdm_buf[1], &pdm_buf[1]);
	}
}

static void pdm_init(void)
{
	nrfx_pdm_config_t pdm_config = NRFX_PDM_DEFAULT_CONFIG(
		10, 11); /*configures CLK to pin 10 and Din to pin 11*/
	nrfx_pdm_init(&pdm_config, nrfx_pdm_event_handler);
}

/*ISR workaround given by Nordic*/
ISR_DIRECT_DECLARE(pdm_isr_handler)
{
	nrfx_pdm_irq_handler();
	ISR_DIRECT_PM(); /* PM done after servicing interrupt for best latency
			  */

	return 1; /* We should check if scheduling decision should be made */
}

void main(void)
{
	printk("The AT host sample started\n");

{
	IRQ_DIRECT_CONNECT(PDM_IRQn, 0, pdm_isr_handler, 0);  //workaround line 
	printk("Starting PDM program!\n");
	printk("PDM Buffer size: %d in 16 bit words\n", PDM_BUF_SIZE);

	/*
	bool enabled = nrfx_pdm_enable_check();
	printk(enabled ? "true/n" : "false\n");
	*/

	pdm_init();
	printk("%4x is the starting address\n", &pdm_buf);
	printk("%4x is current value at %x\n", pdm_buf[0], &pdm_buf);
	printk("The PDM will start reading NOW...\n");
      /*  for (int i = 0; i < 500; i++) {
          int k = 5;
          for (volatile int j = 0; j < 50; j++) {
                k = !k;
		}
	}*/
	nrfx_pdm_start();
	for (int i = 0; i < 100; i++) {
          int k = 5;
          for (volatile int j = 0; j < 100; j++) {
                k = !k;
		}
	}
	nrfx_pdm_stop();

	printk("%4x is current value at %x\n", pdm_buf[0], &pdm_buf);
}
}

Related