Not Getting I2S Data.

Hi,

I have been working with I2S Mic sph0645lm4h-b and nRF5340 audio DK. I configured mic and while I'm reading the data it throughs an error code of -5. I'm Sharing the code below

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2s.h>

#define I2S_RX_NODE  DT_NODELABEL(i2s_rx)

#define SAMPLE_FREQUENCY    16000
#define SAMPLE_BIT_WIDTH    32
#define BYTES_PER_SAMPLE    sizeof(int16_t)
#define NUMBER_OF_CHANNELS  1
#define SAMPLES_PER_BLOCK   ((SAMPLE_FREQUENCY / 10) * NUMBER_OF_CHANNELS)
#define INITIAL_BLOCKS      2
#define TIMEOUT             1000

#define BLOCK_SIZE  (BYTES_PER_SAMPLE * SAMPLES_PER_BLOCK)
#define BLOCK_COUNT (INITIAL_BLOCKS + 2)
K_MEM_SLAB_DEFINE_STATIC(mem_slab, BLOCK_SIZE, BLOCK_COUNT, 4);

static const struct device *i2s_dev_rx;
static struct i2s_config config;
static int ret;

static void audInit(void){
	i2s_dev_rx = DEVICE_DT_GET(I2S_RX_NODE);
	if(!i2s_dev_rx){
		printk("Unable to find i2s_rxtx device \n");
	}
	else{
		printk("Found i2s_rxtx device \n");
	}

	config.word_size = SAMPLE_BIT_WIDTH;
	config.channels = NUMBER_OF_CHANNELS;
	config.format = I2S_FMT_DATA_FORMAT_I2S;
	config.options = I2S_OPT_BIT_CLK_MASTER | I2S_OPT_FRAME_CLK_MASTER;
	config.frame_clk_freq = SAMPLE_FREQUENCY;
	config.mem_slab = &mem_slab;
	config.block_size = BLOCK_SIZE;
	config.timeout = TIMEOUT;
	ret = i2s_configure(i2s_dev_rx, I2S_DIR_RX, &config);
	if (ret!=0) {
		printk("i2s_config failed %d \n", ret);
	}
	else{
		printk("i2s_config Pass \n");
	}
}

int main(void)
{
	audInit();
	ret = i2s_trigger(i2s_dev_rx, I2S_DIR_RX, I2S_TRIGGER_START);
	if (ret != 0) {
	    printk("i2s_trigger failed %d \n", ret);
	}
	else{
		printk("i2s_trigger Pass \n");
	}

	void *mem_block;
	uint32_t block_size;
	int16_t sampleData;

	while (1) {
		ret = i2s_read(i2s_dev_rx, &mem_block, &block_size);
		if (ret < 0) {
			printk("Failed to read data: %d\n", ret);
		}
		for (int i = 0; i < SAMPLES_PER_BLOCK; ++i) {
                        sampleData = ((int16_t *)mem_block)[i] >> 16;
						// printk("data: %d\n", sampleData);
            }
	}
	k_free(mem_block);
	return 0;
}

Output: 


Also I'm sharing the overlay code 

&pinctrl {
    i2s0_default: i2s0_default {
        group1 {
            psels = <NRF_PSEL(I2S_MCK, 0, 12)>;
            nordic,drive-mode = <NRF_DRIVE_H0H1>;
        };
        group2 {
            psels = <NRF_PSEL(I2S_SCK_M, 0, 26)>,
                <NRF_PSEL(I2S_LRCK_M, 0, 25)>,
                <NRF_PSEL(I2S_SDOUT, 1, 14)>,
                <NRF_PSEL(I2S_SDIN, 0, 7)>;
        };
    };

    i2s0_sleep: i2s0_sleep {
        group1 {
            psels = <NRF_PSEL(I2S_MCK, 0, 12)>,
                <NRF_PSEL(I2S_SCK_M, 0, 26)>,
                <NRF_PSEL(I2S_LRCK_M, 0, 25)>,
                <NRF_PSEL(I2S_SDOUT, 1, 14)>,
                <NRF_PSEL(I2S_SDIN, 0, 7)>;
            low-power-enable;
        };
    };
};

i2s_rx:&i2s0 {
    compatible = "nordic,nrf-i2s";
    status = "okay";
    pinctrl-0 = <&i2s0_default>;
    pinctrl-1 = <&i2s0_sleep>;
    pinctrl-names = "default", "sleep";
};

clock: clock@5000 {
	compatible = "nordic,nrf-clock";
	reg = <0x5000 0x1000>;
	interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>;
	status = "okay";
	hfclkaudio-frequency = <11289600>;
};


In proj.conf I have also enabled I2S using "CONFIG_I2S=y"

Help me out here. Am I dong any mistake here, just correct me out.

Thanks in advance,
Laksh


Related