<?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 Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112300/i2s-master-clock-always-runs-at-same-speed-as-bit-clock</link><description>Hi, 
 I have used the I2S echo sample project as a starting point and try to configure it to sample data from an I2S microphone running on the nRF5340. 
 However, I cannot get the I2S Master Clock to run at a multiple of the Bit Clock. There doesn&amp;#39;t seem</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Apr 2024 07:38:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112300/i2s-master-clock-always-runs-at-same-speed-as-bit-clock" /><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489692?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2024 07:38:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06e75635-935e-4eab-9e07-c39c9174fdca</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Yes. Did you see my previous reply from yesterday?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489691?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2024 06:11:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63a49818-0775-4122-af2f-2b8f749a1fef</guid><dc:creator>sthon</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;any updates?&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Steinar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489690?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 07:48:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5bc2851-b4f5-4640-b315-4fd3eb369f68</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Steinar,&lt;/p&gt;
&lt;p&gt;Sorry for the late replies. Karl got back, but then had to leave again.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I looked into this some more, and discussed with some of the authors of our I2S drivers. Unfortunately, there is no out of the box support to directly set the I2S Master Clock frequency in Zephyr, but it is possible to do so by either using the nrfx_i2s driver directly, or by modifying the nrfx_i2s driver sligtly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The way that the frequency is chosen is through the find_suitable_clock() function in i2s_nrfx.c (ncs\zephyr\drivers\i2s\n2s_nrfx.c).&lt;/p&gt;
&lt;p&gt;If you comment out the line starting with &amp;quot;{&amp;nbsp; 64, ...&amp;quot;&lt;/p&gt;
&lt;p&gt;from here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void find_suitable_clock(const struct i2s_nrfx_drv_cfg *drv_cfg,
				nrfx_i2s_config_t *config,
				const struct i2s_config *i2s_cfg)
{
	static const struct {
		uint16_t        ratio_val;
		nrf_i2s_ratio_t ratio_enum;
	} ratios[] = {
		{  32, NRF_I2S_RATIO_32X },
		{  48, NRF_I2S_RATIO_48X },
		//{  64, NRF_I2S_RATIO_64X },
		{  96, NRF_I2S_RATIO_96X },
		{ 128, NRF_I2S_RATIO_128X },
		{ 192, NRF_I2S_RATIO_192X },
		{ 256, NRF_I2S_RATIO_256X },
		{ 384, NRF_I2S_RATIO_384X },
		{ 512, NRF_I2S_RATIO_512X }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This function, which finds the first suitable frequency, will not find the 64 one, and it will move on to the 128 (the 96 will not match). Then you will see that the MCK that the frequency will double.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Alternatively, you can use the nrfx driver directly, instead of the Zephyr API. If so, you can change the&amp;nbsp;nrfx_i2s_config_t.mck_setup to the MCK frequency you want to use, and make sure to also adjust&amp;nbsp;nrfx_i2s_config_t.ratio, to get the correct bit-clock frequency. Do this before calling&amp;nbsp;nrfx_i2s_init(). It should be pretty straight forward.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489689?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2024 13:04:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a66523bd-1a5a-4275-8d5b-4a24a1cc7aaa</guid><dc:creator>sthon</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;any updates?&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Steinar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489688?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2024 12:36:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73546302-c668-4467-a997-2431c950a9dc</guid><dc:creator>sthon</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thank you for the reply.&lt;/p&gt;
&lt;p&gt;In addition to the code already submitted above in the original ticket, you can add the following for a&amp;nbsp;minimized application&amp;nbsp;to replicate the issue I am seeing:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;

static uint8_t mem_block[BLOCK_SIZE];

int main(void)
{
	i2s_init();

	while (1)
	{
		uint32_t block_size;

		i2s_buf_read(i2s_dev_rx, &amp;amp;mem_block, &amp;amp;block_size);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;All that is needed in the prj.conf is:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_I2S=y&lt;/pre&gt;&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;The&amp;nbsp;application will print the following to the terminal when started:&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting nRF Connect SDK v2.5.0 ***
[00:00:00.411,102] &amp;lt;inf&amp;gt; i2s_nrfx: I2S MCK frequency: 3072000, actual PCM rate: 48000&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Kind regards,&lt;/div&gt;
&lt;div&gt;Steinar&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489687?ContentTypeID=1</link><pubDate>Tue, 26 Mar 2024 14:35:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edfc1141-d18a-4947-90c5-6383d449082b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Steinar,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. Karl is out of office, so I will try to look into this ticket.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is it possible to share a minimized application replicate the issue that you are seeing? We are a bit short staffed due to easter holidays, so if I could use this to get a flying start, that would be really helpful.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489686?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2024 08:56:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32b1d75e-a1fb-4654-887f-d10d949a1a0e</guid><dc:creator>sthon</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;Thank you for the&amp;nbsp;help so far.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve attached the oscilloscope traces showing master clock (MCLK) and serial clock (SCLK) being equal.&lt;/p&gt;
&lt;p&gt;&lt;img style="height:auto;max-width:500px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1000x0/__key/communityserver-discussions-components-files/4/pastedimage1710751431729v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Here is a screenshot showing&amp;nbsp;all I2S signals:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:150px;max-width:872px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1744x300/__key/communityserver-discussions-components-files/4/pastedimage1710751519172v3.png" /&gt;&lt;/p&gt;
&lt;p&gt;As can be seen, the LRCLK is close to the expected sample frequency of 48kHz.&lt;/p&gt;
&lt;p&gt;Furthermore, using the equation for calculating SCK:&amp;nbsp; &amp;nbsp;&lt;code&gt;&lt;em&gt;SCK = 2 * LRCK * CONFIG.SWIDTH&lt;/em&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;SCK = 2 * 48 kHz * 32 = 3.072 MHz&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/em&gt;&lt;em&gt;which is close to the measured SCLK = 3.012 MHz from the trace&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried to find a setting for&amp;nbsp;&lt;em&gt;mck_setup&amp;nbsp;&lt;/em&gt;that you referred or anything related to master clock, but I cannot find where in&amp;nbsp;&lt;em&gt;i2s_config&lt;/em&gt; this is?&lt;/p&gt;
&lt;p&gt;Or is the master clock configured in the overlay somhow?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Steinar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S Master Clock always runs at same speed as Bit Clock</title><link>https://devzone.nordicsemi.com/thread/489685?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2024 20:49:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39b6277d-a42a-44d2-b20d-2efc7a55a262</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Steinar,&lt;br /&gt;&lt;br /&gt;Thank you for your patience with this.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/i2s.html"&gt;From the nRF5340 I2S documentation we have that&lt;/a&gt;:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;pre&gt;&lt;em&gt;&lt;code&gt;LRCK = MCK / CONFIG.RATIO&lt;/code&gt;&lt;/em&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;p&gt;&lt;em&gt;The serial clock (SCK), often referred to as the serial bit clock, pulses once for each data bit being transferred on the serial data lines SDIN and SDOUT.&lt;/em&gt;&lt;/p&gt;
&lt;div&gt;&lt;em&gt;When operating in Master mode, the SCK is generated from the MCK, and the frequency of SCK is then given as:&lt;/em&gt;
&lt;pre&gt;&lt;code&gt;&lt;em&gt;SCK = 2 * LRCK * CONFIG.SWIDTH&lt;/em&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;I do not however see that this should produce a SCK equal to the MCK in your case. Could you possibly share the oscilloscope traces so that I could have a look?&lt;br /&gt;&lt;br /&gt;I also notice that you are not setting the mck_setup explicitly - could you try this, and see if it then achieves the mck frequency you were intending?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>