<?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>i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112246/i2s_trigger-failing-while-setting-up---nrf5340-audio-dk</link><description>Hey, I&amp;#39;m trying to setup i2s buffers and other related stuff for mic communication, this is my code for i2s 
 
 
 There are no errors while building or flashing, however while running i2s_trigger, I&amp;#39;m getting this error 
 &amp;lt;err&amp;gt; i2s_custom: i2s_trigger</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Jul 2024 11:00:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112246/i2s_trigger-failing-while-setting-up---nrf5340-audio-dk" /><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/494535?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2024 11:00:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af072ebb-7b20-4060-bf8b-7dbdc77c4bb5</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hi Soham,&lt;/p&gt;
&lt;p&gt;Thank you for your patience so far.&lt;/p&gt;
&lt;p&gt;I have just looked into this for a short time, so please exuse anything I may have missed.&lt;/p&gt;
&lt;p&gt;Have you verified that there is data in mem_block when calling i2s write? (line 223 in your shared code)&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/492088?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 13:44:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5aadc6c9-da09-4ce6-aa4f-ab9f7fda7663</guid><dc:creator>SohamGhugare</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;Yes I modified my application, this is the complete code.&lt;/p&gt;
&lt;p&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(i2s0)
#define I2S_TX_NODE  DT_NODELABEL(i2s0)

#define SAMPLE_FREQUENCY    44100
#define SAMPLE_BIT_WIDTH    16
#define BYTES_PER_SAMPLE    sizeof(int16_t)
#define NUMBER_OF_CHANNELS  2
#define TONE_FREQUENCY      440 
/* Such block length provides an echo with the delay of 100 ms. */
#define SAMPLES_PER_BLOCK   ((SAMPLE_FREQUENCY / 10) * NUMBER_OF_CHANNELS)
#define INITIAL_BLOCKS      2
#define TIMEOUT             1000

#define M_PI 3.14159

#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 sine_wave[SAMPLES_PER_BLOCK];

static int16_t echo_block[SAMPLES_PER_BLOCK];
static volatile bool echo_enabled = true;
static K_SEM_DEFINE(toggle_transfer, 1, 1);

static void generate_sine_wave(void)
{
    for (int i = 0; i &amp;lt; SAMPLES_PER_BLOCK / NUMBER_OF_CHANNELS; ++i) {
        double sample = sin(2.0 * M_PI * TONE_FREQUENCY * i / SAMPLE_FREQUENCY);
        int16_t sample_value = (int16_t)(sample * INT16_MAX);
        for (int j = 0; j &amp;lt; NUMBER_OF_CHANNELS; ++j) {
            sine_wave[i * NUMBER_OF_CHANNELS + j] = sample_value;
        }
    }
}

static void process_block_data(void *mem_block, uint32_t number_of_samples)
{
	static bool clear_echo_block;

	if (echo_enabled) {
		for (int i = 0; i &amp;lt; number_of_samples; ++i) {
			int16_t *sample = &amp;amp;((int16_t *)mem_block)[i];
			*sample += echo_block[i];
			echo_block[i] = (*sample) / 2;
		}

		clear_echo_block = true;
	} else if (clear_echo_block) {
		clear_echo_block = false;
		memset(echo_block, 0, sizeof(echo_block));
	}
}

static bool configure_streams(const struct device *i2s_dev_rx,
			      const struct device *i2s_dev_tx,
			      const struct i2s_config *config)
{
	int ret;

	if (i2s_dev_rx == i2s_dev_tx) {
		ret = i2s_configure(i2s_dev_rx, I2S_DIR_BOTH, config);
		if (ret == 0) {
			return true;
		}
		/* -ENOSYS means that the RX and TX streams need to be
		 * configured separately.
		 */
		if (ret != -ENOSYS) {
			printk(&amp;quot;Failed to configure streams: %d\n&amp;quot;, ret);
			return false;
		}
	}

	ret = i2s_configure(i2s_dev_rx, I2S_DIR_RX, config);
	if (ret &amp;lt; 0) {
		printk(&amp;quot;Failed to configure RX stream: %d\n&amp;quot;, ret);
		return false;
	}

	ret = i2s_configure(i2s_dev_tx, I2S_DIR_TX, config);
	if (ret &amp;lt; 0) {
		printk(&amp;quot;Failed to configure TX stream: %d\n&amp;quot;, ret);
		return false;
	}

	return true;
}

static bool prepare_transfer(const struct device *i2s_dev_rx,
			     const struct device *i2s_dev_tx)
{
	int ret;

	for (int i = 0; i &amp;lt; INITIAL_BLOCKS; ++i) {
		void *mem_block;

		ret = k_mem_slab_alloc(&amp;amp;mem_slab, &amp;amp;mem_block, K_NO_WAIT);
		if (ret &amp;lt; 0) {
			printk(&amp;quot;Failed to allocate TX block %d: %d\n&amp;quot;, i, ret);
			return false;
		}

		memcpy(mem_block, sine_wave, BLOCK_SIZE);

		ret = i2s_write(i2s_dev_tx, mem_block, BLOCK_SIZE);
		if (ret &amp;lt; 0) {
			printk(&amp;quot;Failed to write block %d: %d\n&amp;quot;, i, ret);
			return false;
		}
	}

	return true;
}

static bool trigger_command(const struct device *i2s_dev_rx,
			    const struct device *i2s_dev_tx,
			    enum i2s_trigger_cmd cmd)
{
	int ret;

	if (i2s_dev_rx == i2s_dev_tx) {
		ret = i2s_trigger(i2s_dev_rx, I2S_DIR_BOTH, cmd);
		if (ret == 0) {
			return true;
		}
		/* -ENOSYS means that commands for the RX and TX streams need
		 * to be triggered separately.
		 */
		if (ret != -ENOSYS) {
			printk(&amp;quot;Failed to trigger command %d: %d\n&amp;quot;, cmd, ret);
			return false;
		}
	}

	ret = i2s_trigger(i2s_dev_rx, I2S_DIR_RX, cmd);
	if (ret &amp;lt; 0) {
		printk(&amp;quot;Failed to trigger command %d on RX: %d\n&amp;quot;, cmd, ret);
		return false;
	}

	ret = i2s_trigger(i2s_dev_tx, I2S_DIR_TX, cmd);
	if (ret &amp;lt; 0) {
		printk(&amp;quot;Failed to trigger command %d on TX: %d\n&amp;quot;, cmd, ret);
		return false;
	}

	return true;
}

int main(void)
{
	const struct device *const i2s_dev_rx = DEVICE_DT_GET(I2S_RX_NODE);
	const struct device *const i2s_dev_tx = DEVICE_DT_GET(I2S_TX_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;
	}

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

	generate_sine_wave();

	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, i2s_dev_tx, &amp;amp;config)) {
		return 0;
	}

	for (;;) {
		k_sem_take(&amp;amp;toggle_transfer, K_FOREVER);

		if (!prepare_transfer(i2s_dev_rx, i2s_dev_tx)) {
			return 0;
		}

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

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

		while (k_sem_take(&amp;amp;toggle_transfer, K_NO_WAIT) != 0) {
			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;
			} else if(ret == 0) {
				printk(&amp;quot;Successfully read data (%d)...\n&amp;quot;, block_size);
			}
			
			

			process_block_data(mem_block, SAMPLES_PER_BLOCK);
			memcpy(mem_block, sine_wave, BLOCK_SIZE);


			ret = i2s_write(i2s_dev_tx, mem_block, block_size);
			if (ret &amp;lt; 0) {
				printk(&amp;quot;Failed to write data: %d\n&amp;quot;, ret);
				break;
			} else if(ret == 0) {
				printk(&amp;quot;Successfully wrote data (%d)\n\n&amp;quot;, block_size);
			}

		}

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

		printk(&amp;quot;Streams stopped\n&amp;quot;);
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This code is supposed to generate a sine wave tone and play it to the speakers connected to the I2S pins.&lt;/p&gt;
&lt;p&gt;No build or flash errors, after running it just spams&lt;/p&gt;
&lt;p&gt;Successfully read data (17640)&lt;/p&gt;
&lt;p&gt;Successfully wrote data (17640)&lt;/p&gt;
&lt;p&gt;which im assuming means its&amp;nbsp;able to read and write data from I2S, but I ain&amp;#39;t getting any output from the speakers.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/492079?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 13:22:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:788361ce-cb5e-41c3-ab0a-ff84d74737ba</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Soham,&lt;/p&gt;
&lt;p&gt;We only have&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/main/applications/nrf5340_audio"&gt;Nrf5340_Audio&lt;/a&gt;&amp;nbsp;application as a sample in NCS.&lt;/p&gt;
&lt;p&gt;Even if you use the zephyr api, it would connect to underlying nordic drivers.&lt;/p&gt;
&lt;p&gt;Did you modify your application as suggested by Karl? Are you getting a different error (as previously you got:&amp;nbsp;&lt;span&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&amp;lt;err&amp;gt; i2s_nrfx: Next buffers not supplied on time&lt;/span&gt;)?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/491438?ContentTypeID=1</link><pubDate>Sat, 29 Jun 2024 12:38:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5ea548b-7647-4d53-b96c-3c7fecaec178</guid><dc:creator>SohamGhugare</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;Sorry for the delayed reply. I am working with Zephyr I2S API and the functions you are pointing at are irrelevant as they are use nrfx_i2s. I have gone through the buffer filling part and there&amp;#39;s a lot of complicated stuff going on there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/490785?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2024 08:07:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:329586c7-61c0-4a3f-97f6-32ca3fafde3b</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Great! I am glad to hear that you&amp;#39;re now able to send data once.&lt;br /&gt;The next thing then for us to look into is to play continuously. To do this you will need to supply new buffers to the I2S peripheral as you go. You can use the audio system implementation from the nRF5340 LE Audio reference application as a reference for how to implement this in your project. &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/952948a9ac53f7042ef0e48145b8fcf1cd64999d/applications/nrf5340_audio/src/audio/audio_datapath.c#L768-L769"&gt;In the audio system start function you can see how additional buffers are prepared&lt;/a&gt;&amp;nbsp;using the&amp;nbsp;audio_i2s_set_next_buf function, and then &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/952948a9ac53f7042ef0e48145b8fcf1cd64999d/applications/nrf5340_audio/src/audio/audio_datapath.c#L720"&gt;again as part of the BLK complete handler function&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Please add this into your application as well, and see if this then resolves your issue so that you may play continuously.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/490611?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 11:51:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89dc08a3-f842-4716-9d9a-e534419a865a</guid><dc:creator>SohamGhugare</dc:creator><description>[quote userid="87869" url="~/f/nordic-q-a/112246/i2s_trigger-failing-while-setting-up---nrf5340-audio-dk/490534"]have you already populated these buffers before issuing the tx command?[/quote]
&lt;p&gt;Oh right, that was the issue, I was executing the START Trigger before populating the buffers. I fixed that but now I can only send data once.&lt;/p&gt;
&lt;p&gt;So I made a write_audio handler which collects the audio data sent over ble and writes it to I2S, here&amp;#39;s the relevant files:&lt;/p&gt;
&lt;p&gt;i2s.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2s.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;

#include &amp;quot;i2s.h&amp;quot;

/* Audio I2S Configuration Definitions */
#define SAMPLE_FREQUENCY    44100
#define SAMPLE_BIT_WIDTH    16
#define BYTES_PER_SAMPLE    sizeof(int16_t)
#define NUMBER_OF_CHANNELS  2
/* Such block length provides an echo with the delay of 100 ms. */
// #define SAMPLES_PER_BLOCK   ((SAMPLE_FREQUENCY / 10) * NUMBER_OF_CHANNELS)
#define SAMPLES_PER_BLOCK 	16
#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);

#define I2S_DEV DT_NODELABEL(i2s_dev)

static int16_t echo_block[SAMPLES_PER_BLOCK];
static volatile bool echo_enabled = true;
static K_SEM_DEFINE(toggle_transfer, 1, 1);

/* Device definitions */
const struct device *const i2s_dev_rx = DEVICE_DT_GET(DT_NODELABEL(i2s_dev));
const struct device *const i2s_dev_tx = DEVICE_DT_GET(DT_NODELABEL(i2s_dev));


// LOG_MODULE_REGISTER(i2s_custom, CONFIG_I2S_LOG_LEVEL);
LOG_MODULE_REGISTER(i2s_custom, LOG_LEVEL_DBG);

static void process_block_data(void *mem_block, uint32_t number_of_samples)
{
	static bool clear_echo_block;

	if (echo_enabled) {
		for (int i = 0; i &amp;lt; number_of_samples; ++i) {
			int16_t *sample = &amp;amp;((int16_t *)mem_block)[i];
			*sample += echo_block[i];
			echo_block[i] = (*sample) / 2;
		}

		clear_echo_block = true;
	} else if (clear_echo_block) {
		clear_echo_block = false;
		memset(echo_block, 0, sizeof(echo_block));
	}
}

static bool configure_streams(const struct device *i2s_dev_rx,
			      const struct device *i2s_dev_tx,
			      const struct i2s_config *config)
{
	int ret;

	if (i2s_dev_rx == i2s_dev_tx) {
		ret = i2s_configure(i2s_dev_rx, I2S_DIR_BOTH, config);
		if (ret == 0) {
			return true;
		}
		/* -ENOSYS means that the RX and TX streams need to be
		 * configured separately.
		 */
		if (ret != -ENOSYS) {
			LOG_ERR(&amp;quot;Failed to configure streams: %d\n&amp;quot;, ret);
			return false;
		}
	}

	ret = i2s_configure(i2s_dev_rx, I2S_DIR_RX, config);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to configure RX stream: %d\n&amp;quot;, ret);
		return false;
	}

	ret = i2s_configure(i2s_dev_tx, I2S_DIR_TX, config);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to configure TX stream: %d\n&amp;quot;, ret);
		return false;
	}

	return true;
}

static bool prepare_transfer(const struct device *i2s_dev_tx)
{
	int ret;

	for (int i = 0; i &amp;lt; INITIAL_BLOCKS; ++i) {
		void *mem_block;

		ret = k_mem_slab_alloc(&amp;amp;mem_slab, &amp;amp;mem_block, K_NO_WAIT);
		if (ret &amp;lt; 0) {
			LOG_ERR(&amp;quot;Failed to allocate TX block %d: %d\n&amp;quot;, i, ret);
			return false;
		}

		memset(mem_block, 0, BLOCK_SIZE);

		ret = i2s_write(i2s_dev_tx, mem_block, BLOCK_SIZE);
		if (ret &amp;lt; 0) {
			LOG_ERR(&amp;quot;Failed to write block %d: %d\n&amp;quot;, i, ret);
			return false;
		}
	}

	return true;
}

static bool trigger_command(const struct device *i2s_dev_rx,
			    const struct device *i2s_dev_tx,
			    enum i2s_trigger_cmd cmd)
{
	int ret;

	if (i2s_dev_rx == i2s_dev_tx) {
		ret = i2s_trigger(i2s_dev_rx, I2S_DIR_BOTH, cmd);
		if (ret == 0) {
			return true;
		}
		/* -ENOSYS means that commands for the RX and TX streams need
		 * to be triggered separately.
		 */
		if (ret != -ENOSYS) {
			LOG_ERR(&amp;quot;Failed to trigger command %d: %d\n&amp;quot;, cmd, ret);
			return false;
		}
	}

	ret = i2s_trigger(i2s_dev_rx, I2S_DIR_RX, cmd);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to trigger command %d on RX: %d\n&amp;quot;, cmd, ret);
		return false;
	}

	ret = i2s_trigger(i2s_dev_tx, I2S_DIR_TX, cmd);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to trigger command %d on TX: %d\n&amp;quot;, cmd, ret);
		return false;
	}

	return true;
}

int i2s_write_audio_data(const uint8_t *data, size_t len) {
	LOG_INF(&amp;quot;Writing audio to i2s...&amp;quot;);

    int ret;

	// if(!prepare_transfer(i2s_dev_tx)){
	// 	LOG_ERR(&amp;quot;Failed to prepare transfer...&amp;quot;);
	// 	return -1;
	// }

    void *mem_block;
    ret = k_mem_slab_alloc(&amp;amp;mem_slab, &amp;amp;mem_block, K_NO_WAIT);
    if (ret &amp;lt; 0) {
        LOG_ERR(&amp;quot;Failed to allocate memory slab for I2S write: %d\n&amp;quot;, ret);
        return ret;
    }

    memcpy(mem_block, data, len);
	LOG_DBG(&amp;quot;mem allocated...&amp;quot;);


    ret = i2s_write(i2s_dev_tx, mem_block, len);
    if (ret &amp;lt; 0) {
        LOG_ERR(&amp;quot;Failed to write audio data to I2S: %d\n&amp;quot;, ret);
        k_mem_slab_free(&amp;amp;mem_slab, &amp;amp;mem_block);
        return ret;
    }

	LOG_DBG(&amp;quot;i2s_write done...&amp;quot;);

	ret = i2s_trigger(i2s_dev_tx, I2S_DIR_TX, I2S_TRIGGER_START);
	if(ret!=0){
		LOG_ERR(&amp;quot;i2s_trigger (START) failed with error %d&amp;quot;, ret);
		return ret;
	}

	// ret = i2s_trigger(i2s_dev_tx, I2S_DIR_TX, I2S_TRIGGER_DROP);
	// if(ret!=0){
	// 	LOG_ERR(&amp;quot;i2s_trigger (DROP) failed with error %d&amp;quot;, ret);
	// 	return ret;
	// }

	return 0;
}

int audio_i2s_setup(void) {
    int err;

	LOG_INF(&amp;quot;Setting up I2S...&amp;quot;);

    
	struct i2s_config config;

	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, i2s_dev_tx, &amp;amp;config)) {
		return 0;
	}

	LOG_INF(&amp;quot;I2S configured successfully&amp;quot;);

    return 0;

}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;ble.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/conn.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/hci.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/gap.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/gatt.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/uuid.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/addr.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2s.h&amp;gt;


#include &amp;quot;../gpio/gpio.h&amp;quot;
#include &amp;quot;../audio/i2s.h&amp;quot;

LOG_MODULE_REGISTER(ble_custom, CONFIG_BLE_LOG_LEVEL);

#define AUDIO_UUID_VAL BT_UUID_128_ENCODE(0x00001234, 0x1234, 0xabcd, 0x1234, 0x785feabcd123)
#define AUDIO_CHAR_UUID_VAL BT_UUID_128_ENCODE(0x00001235, 0x1234, 0xabcd, 0x1234, 0x785feabcd123)
#define AUDIO_UUID BT_UUID_DECLARE_128(AUDIO_UUID_VAL)
#define AUDIO_CHAR_UUID BT_UUID_DECLARE_128(AUDIO_CHAR_UUID_VAL)


/* Audio characteristic value */
// static uint8_t audio_value[251]; 
static uint8_t audio_value[32]; // TODO: Change Buffer Length


/* Write data handler for GATT service */
static ssize_t write_audio(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
{
    LOG_INF(&amp;quot;Received audio data, len: %d&amp;quot;, len);

    // Process the received audio data
    memcpy(audio_value, buf, len);

    int err;
    // Send the audio data to the I2S interface
    err = i2s_write_audio_data(audio_value, len);
    if(err!=0){
        LOG_ERR(&amp;quot;i2s_write_audio_data failed with error %d&amp;quot;, err);
        return -1;
    }
    LOG_INF(&amp;quot;Sent audio data to I2S, len: %d&amp;quot;, len);

    return len;
}


BT_GATT_SERVICE_DEFINE(audio_svc,
    BT_GATT_PRIMARY_SERVICE(AUDIO_UUID),
    BT_GATT_CHARACTERISTIC(AUDIO_CHAR_UUID,
                           BT_GATT_CHRC_WRITE,
                           BT_GATT_PERM_WRITE,
                           NULL, write_audio, NULL),
);



/* GATT Operation Callbacks */
static void connected(struct bt_conn *conn, uint8_t err)
{
    if (err) {
        LOG_ERR(&amp;quot;Failed to connect (err %u)&amp;quot;, err);
        return;
    }
    LOG_INF(&amp;quot;Connected&amp;quot;);

    /* Request Data Length Extension (DLE) */
    struct bt_conn_le_data_len_param data_len_params = {
        .tx_max_len = 251,
        .tx_max_time = 2120,
    };

    int data_len_err = bt_conn_le_data_len_update(conn, &amp;amp;data_len_params);
    if (data_len_err) {
        LOG_ERR(&amp;quot;Data length update failed (err %d)&amp;quot;, data_len_err);
    } else {
        LOG_INF(&amp;quot;Data length update requested&amp;quot;);
    }


    set_green_led();
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
    LOG_INF(&amp;quot;Disconnected (reason %u)&amp;quot;, reason);
    set_red_led();
    k_msleep(1000);
    set_blue_led();
}

static void le_data_length_updated(struct bt_conn *conn, const struct bt_conn_le_data_len_info *info)
{
    LOG_INF(&amp;quot;Data length updated: TX (%u) RX (%u)&amp;quot;, info-&amp;gt;tx_max_len, info-&amp;gt;rx_max_len);
}

struct bt_conn_cb connection_callbacks = {
    .connected = connected,
    .disconnected = disconnected,
    .le_data_len_updated = le_data_length_updated,
};

int ble_setup(void) {
    LOG_INF(&amp;quot;Setting up BLE...&amp;quot;);

    bt_conn_cb_register(&amp;amp;connection_callbacks);

    int err;
    err = bt_enable(NULL);
    if (err) {
        LOG_ERR(&amp;quot;Bluetooth init failed (err %d)&amp;quot;, err);
        return err;
    }
    LOG_INF(&amp;quot;Bluetooth initialized&amp;quot;);

    err = bt_le_adv_start(BT_LE_ADV_CONN, NULL, 0, NULL, 0);
    if (err) {
        LOG_ERR(&amp;quot;Advertising failed to start (err %d)&amp;quot;, err);
        return err;
    }
    LOG_INF(&amp;quot;Advertising successfully started&amp;quot;);

    set_blue_led();

	LOG_INF(&amp;quot;BLE configured successfully&amp;quot;);

    return 0;

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The end result what I want to achieve is being able to stream audio data from my mobile phone to the speakers connected. The data flow is as follows:&lt;/p&gt;
&lt;p&gt;BLE -&amp;gt; I2S -&amp;gt; CS47L63 Codec -&amp;gt; Headphone Out&lt;/p&gt;
&lt;p&gt;however now when I connect to the board via BLE and send some data, it writes to I2S successfully once and then throws this error&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;err&amp;gt; i2s_nrfx: Next buffers not supplied on time&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Where am I going wrong now?&lt;/p&gt;
&lt;p&gt;PS: I changed the buffer size for testing, it was initially 17k bytes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/490534?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 09:10:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1d48144-7874-4e26-ae50-a885f73b9671</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="SohamGhugare"]It&amp;#39;s mentioned in the definition of i2s_trigger function that the EIO error corresponds to that description.[/quote]
&lt;p&gt;You are correct.&lt;br /&gt;Your issue here is likely the state in which the trigger is issued. The I2S START trigger can only be used in READY state.&lt;br /&gt;Could you write out your I2S states throughout the program, so that we may verify that they are set as expected?&lt;br /&gt;&lt;a href="https://docs.zephyrproject.org/latest/hardware/peripherals/audio/i2s.html#c.i2s_trigger_cmd.I2S_TRIGGER_START"&gt;The I2S_TRIGGER_START command requires that some data is already queued&lt;/a&gt;, have you already populated these buffers before issuing the tx command?&lt;/p&gt;
[quote user="SohamGhugare"]I did not get you, can you please elaborate how I&amp;#39;m supposed to do that?[/quote]
&lt;p&gt;Do you have access to a logic analyzer or oscilloscope so that you may scope the I2S lines, to verify what is being sent on them?&lt;br /&gt;This question will become relevant again if you should encounter any issues with the audio once we get the transfers started.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/490517?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 08:33:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5f360d6-9d6e-4531-8a75-bad7416389a5</guid><dc:creator>SohamGhugare</dc:creator><description>[quote userid="87869" url="~/f/nordic-q-a/112246/i2s_trigger-failing-while-setting-up---nrf5340-audio-dk/490514"]Where do you get your interpretation of the error number 5?[/quote]
&lt;p&gt;It&amp;#39;s mentioned in the definition of i2s_trigger function that the EIO error corresponds to that description.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/112246/i2s_trigger-failing-while-setting-up---nrf5340-audio-dk/490514"]Do you have access to a logic analyzer, so that you may confirm that communication on the lines directly?[/quote]
&lt;p&gt;I did not get you, can you please elaborate how I&amp;#39;m supposed to do that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/490514?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 08:28:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:081fb027-4a46-4a7b-960c-4da826f69afd</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Thank you for your extreme patience with this.&lt;/p&gt;
[quote user=""]&lt;p&gt;There are no errors while building or flashing, however while running i2s_trigger, I&amp;#39;m getting this error&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;err&amp;gt; i2s_custom: i2s_trigger failed with -5 error&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This supposedly means that&amp;nbsp;&amp;nbsp;&lt;code&gt;The trigger cannot be executed in the current state or a DMA channel cannot be allocated.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;code&gt;What could be the possible reason for this, even tho the rx and tx i2s instances are being configured properly?&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/apidoc/latest/group__system__errno.html"&gt;Error 5 is IO error&lt;/a&gt;, which could mean that the communication with the device is not going as expected.&lt;br /&gt;Do you have access to a logic analyzer, so that you may confirm that communication on the lines directly?&lt;br /&gt;&lt;br /&gt;Where do you get your interpretation of the error number 5?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2s_trigger failing while setting up - nRF5340 Audio DK</title><link>https://devzone.nordicsemi.com/thread/490463?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 06:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8413f35c-ac10-4017-ab83-9179eb01e5e7</guid><dc:creator>SohamGhugare</dc:creator><description>&lt;p&gt;Bumping this thread since there&amp;#39;s no reply for the past 6 days.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can someone please look into this on priority?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>