<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Not Getting I2S Data.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113509/not-getting-i2s-data</link><description>Hi, I have been working with I2S Mic sph0645lm4h-b and nRF5340 audio DK. I configured mic and while I&amp;#39;m reading the data it throughs an error code of -5. I&amp;#39;m Sharing the code below 
 Output: Also I&amp;#39;m sharing the overlay code In proj.conf I have also enabled</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Aug 2024 06:21:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113509/not-getting-i2s-data" /><item><title>RE: Not Getting I2S Data.</title><link>https://devzone.nordicsemi.com/thread/497263?ContentTypeID=1</link><pubDate>Wed, 07 Aug 2024 06:21:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:079dc052-bc8b-452c-817f-c247c671d3b5</guid><dc:creator>laksh</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;I Managed to get the data but the thing is when i print the data with printk it&amp;nbsp;throws a read error of -5. The error indicates -EIO.&amp;nbsp;As I checked it is related to memory slab. Can anyone help me on this issue. Im Sharing the code here.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2s.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

#define I2S_RX_NODE DT_NODELABEL(i2s_rxtx)

#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 int16_t echo_block[SAMPLES_PER_BLOCK];
uint8_t loopCnt = 0;

static void process_block_data(void *mem_block, uint32_t number_of_samples)
{
	for (int i = 0; i &amp;lt; number_of_samples; ++i)
	{
		int16_t *sample = &amp;amp;((int16_t *)mem_block)[i];
		echo_block[i] = *sample;
		printk(&amp;quot;%d\n&amp;quot;, echo_block[i]);
	}
}

static bool configure_streams(const struct device *i2s_dev_rx, const struct i2s_config *config)
{
	int ret = i2s_configure(i2s_dev_rx, I2S_DIR_RX, config);
	if (ret == 0)
	{
		printk(&amp;quot;Configure Stream Successful.\n&amp;quot;);
		return true;
	}
	printk(&amp;quot;Failed to configure streams: %d\n&amp;quot;, ret);
	return false;
}

static bool trigger_command(const struct device *i2s_dev_rx, enum i2s_trigger_cmd cmd)
{
	int ret = i2s_trigger(i2s_dev_rx, I2S_DIR_RX, cmd);
	if (ret == 0)
	{
		printk(&amp;quot;Trigger Command Successful.\n&amp;quot;);
		return true;
	}
	printk(&amp;quot;Failed to trigger command %d: %d\n&amp;quot;, cmd, ret);
	return false;
}

int main(void)
{
	const struct device *const i2s_dev_rx = DEVICE_DT_GET(I2S_RX_NODE);
	struct i2s_config config;

	printk(&amp;quot;I2S echo sample\n&amp;quot;);

	if (!device_is_ready(i2s_dev_rx))
	{
		printk(&amp;quot;%s is not ready\n&amp;quot;, i2s_dev_rx-&amp;gt;name);
		return 0;
	}

	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 = &amp;amp;mem_slab;
	config.block_size = BLOCK_SIZE;
	config.timeout = TIMEOUT;

	if (!configure_streams(i2s_dev_rx, &amp;amp;config))
	{
		return 0;
	}

	if (!trigger_command(i2s_dev_rx, I2S_TRIGGER_START))
	{
		return 0;
	}

	printk(&amp;quot;Streams started\n&amp;quot;);

	while (1)
	{
		void *mem_block;
		uint32_t block_size;
		int ret;

		ret = i2s_read(i2s_dev_rx, &amp;amp;mem_block, &amp;amp;block_size);
		if (ret &amp;lt; 0)
		{
			printk(&amp;quot;Failed to read data: %d\n&amp;quot;, ret);
			break;
		}

		process_block_data(mem_block, block_size);

		k_mem_slab_free(&amp;amp;mem_slab, mem_block);

		printk(&amp;quot;Loop: %d\n&amp;quot;, loopCnt);
		loopCnt++;
	}
	printk(&amp;quot;Exiting main loop\n&amp;quot;);
	return 0;
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Thanks in advance&lt;br /&gt;Laksh&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not Getting I2S Data.</title><link>https://devzone.nordicsemi.com/thread/496317?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 05:07:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f898830-64f4-4f0b-b8ee-cc4d11479cd8</guid><dc:creator>laksh</dc:creator><description>&lt;p&gt;In&amp;nbsp;&lt;span&gt;\zephyr\samples\drivers\i2s\echo\src\main.c project I made modifications to only init and get data. There is nothing much I did in that code. I have shared the code&lt;/span&gt;&lt;/p&gt;
[quote userid="134579" url="~/f/nordic-q-a/113509/not-getting-i2s-data"]I&amp;#39;m Sharing the code below[/quote]
&lt;p&gt;&lt;span&gt;&lt;br /&gt;Laksh&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not Getting I2S Data.</title><link>https://devzone.nordicsemi.com/thread/496217?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 12:42:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6f724fe-3f36-4994-a125-37f50b1c6465</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Looking at the code it looks like you started with the \zephyr\samples\drivers\i2s\echo\src\main.c project, I suggest to revert back a bit, and provide a bit more information about what change caused it to fail to start with.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not Getting I2S Data.</title><link>https://devzone.nordicsemi.com/thread/496152?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 08:50:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdcbc2d6-b083-4bdb-acba-4d58b4a33261</guid><dc:creator>laksh</dc:creator><description>&lt;p&gt;Hi Turbo,&lt;br /&gt;&lt;br /&gt;Can you elaborate a bit, so that I can proceed further.&amp;nbsp;As you mentioned i cahnged the code&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;while (1) {
		ret = i2s_read(i2s_dev_rx, &amp;amp;mem_block, &amp;amp;block_size);
		if (ret &amp;lt; 0) {
			printk(&amp;quot;Failed to read data: %d\n&amp;quot;, ret);
		}
		else{
			printk(&amp;quot;Read Data Success \n&amp;quot;);
		}
		for (int i = 0; i &amp;lt; SAMPLES_PER_BLOCK; ++i) {
                        sampleData = ((int16_t *)mem_block)[i] &amp;gt;&amp;gt; 16;
						printk(&amp;quot;data: %d\n&amp;quot;, sampleData);
            }

		k_mem_slab_free(&amp;amp;mem_slab, mem_block);
	}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;After this im getting the data as only 0 and -1 since Im using mic I know the data is wrong.&lt;/p&gt;
&lt;p&gt;Also, When I checked the BCLK pin in oscillosocpe its not generating any clock signal.&lt;br /&gt;&lt;br /&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not Getting I2S Data.</title><link>https://devzone.nordicsemi.com/thread/496124?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 06:56:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94d873c5-8514-42f6-8053-8bef502e2c1d</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Your code is missing the required k_mem_slab_free()&amp;nbsp; call inside the while loop. The k_free() call is both wrong function and in the wrong place.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>