<?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: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/107248/i2s-configuring-clock-details-with-zephyr</link><description>Hello, 
 I have developed an NCS/Zephyr-based application that is able to stream out .WAV files over the I2S peripheral. 
 I have a dev board using a MAX98357A audio amplifier. This amplifier is able to interpret the I2S output from my nRF52840 and it</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Feb 2024 12:40:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/107248/i2s-configuring-clock-details-with-zephyr" /><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467919?ContentTypeID=1</link><pubDate>Wed, 07 Feb 2024 12:40:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ce2a13f-7022-49c9-8535-276ce62dc39f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Chris&lt;/p&gt;
&lt;p&gt;The reason these options are conditional in the build is that they are only available on some of our devices, not all. As you can see from the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/i2s.html?cp=4_0_0_6_14_9_22#register.CONFIG.SWIDTH"&gt;nRF5340 CONFIG.SWIDTH register definition&lt;/a&gt;&amp;nbsp;they are available in this device, but not in the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/i2s.html?cp=5_0_0_5_10_9_15#register.CONFIG.SWIDTH"&gt;CONFIG.SWIDTH register for the nRF52840&lt;/a&gt; unfortunately.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In other words you would have to switch to an nRF5340 to get access to these modes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467821?ContentTypeID=1</link><pubDate>Tue, 06 Feb 2024 22:33:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11a00752-daf6-4af4-8c0a-9dbc7e0a76a0</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;I am noticing that despite my best efforts, I cannot seem to get an SCK/LRCK ratio of 64. I can get a ratio of 32, and I can get 48, but not 64.&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t help but wonder if this is related to the sample widths only&amp;nbsp;showing support for 8, 16, and 24 bits.&lt;/p&gt;
&lt;p&gt;Given&amp;nbsp;the formula&amp;nbsp;SCK = 2 * LRCK * CONFIG.SWIDTH, it makes&amp;nbsp;some sense to me that the max SCK/LRCK ratio I can get is 48, when the max SWIDTH I can support is 24 bits (2*24 = 48, and the LRCK cancels out).&lt;/p&gt;
&lt;p&gt;This makes me increasingly suspicious that the key to hitting my desired clock settings is enabling support for 32 bit sample widths for the I2S peripheral.&lt;/p&gt;
&lt;p&gt;What do I need to do to enable the 32 bit sample width options in the I2S driver?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467820?ContentTypeID=1</link><pubDate>Tue, 06 Feb 2024 22:12:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aba4ca22-4c72-4d0c-84fb-58e6fddb3555</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;I can see that the&amp;nbsp;nrf_i2s_swidth_t type, which is used for the config.swidth field, is defined at lines 176-197&amp;nbsp;in&amp;nbsp;sdk/modules/hal/nordic/nrfx/hal/nrf_i2s.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/** @brief I2S sample widths. */
typedef enum
{
    NRF_I2S_SWIDTH_8BIT          = I2S_CONFIG_SWIDTH_SWIDTH_8Bit,      ///&amp;lt; 8 bit.
    NRF_I2S_SWIDTH_16BIT         = I2S_CONFIG_SWIDTH_SWIDTH_16Bit,     ///&amp;lt; 16 bit.
    NRF_I2S_SWIDTH_24BIT         = I2S_CONFIG_SWIDTH_SWIDTH_24Bit,     ///&amp;lt; 24 bit.
#if NRF_I2S_HAS_SWIDTH_32BIT
    NRF_I2S_SWIDTH_32BIT         = I2S_CONFIG_SWIDTH_SWIDTH_32Bit,     ///&amp;lt; 32 bit.
#endif
#if defined(I2S_CONFIG_SWIDTH_SWIDTH_8BitIn16) || defined(__NRFX_DOXYGEN__)
    NRF_I2S_SWIDTH_8BIT_IN16BIT  = I2S_CONFIG_SWIDTH_SWIDTH_8BitIn16,  ///&amp;lt; 8 bit sample in a 16-bit half-frame.
#endif
#if defined(I2S_CONFIG_SWIDTH_SWIDTH_8BitIn32) || defined(__NRFX_DOXYGEN__)
    NRF_I2S_SWIDTH_8BIT_IN32BIT  = I2S_CONFIG_SWIDTH_SWIDTH_8BitIn32,  ///&amp;lt; 8 bit sample in a 32-bit half-frame.
#endif
#if defined(I2S_CONFIG_SWIDTH_SWIDTH_16BitIn32) || defined(__NRFX_DOXYGEN__)
    NRF_I2S_SWIDTH_16BIT_IN32BIT = I2S_CONFIG_SWIDTH_SWIDTH_16BitIn32, ///&amp;lt; 16 bit sample in a 32-bit half-frame.
#endif
#if defined(I2S_CONFIG_SWIDTH_SWIDTH_24BitIn32) || defined(__NRFX_DOXYGEN__)
    NRF_I2S_SWIDTH_24BIT_IN32BIT = I2S_CONFIG_SWIDTH_SWIDTH_24BitIn32, ///&amp;lt; 24 bit sample in a 32-bit half-frame.
#endif
} nrf_i2s_swidth_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, when I try to use NRF_I2S_SWIDTH_32BIT or&amp;nbsp;I2S_CONFIG_SWIDTH_SWIDTH_16BitIn32, I get errors that these values are not defined. Which makes sense, they are behind an #if defined block. These values are also ghosted out in the vs code editor, reinforcing that they are not defined in the current build:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/i2s_5F00_sample_5F00_width_5F00_definitions.png" /&gt;&lt;/p&gt;
&lt;p&gt;I tried defining&amp;nbsp;NRF_I2S_HAS_SWIDTH_32BIT and&amp;nbsp;I2S_CONFIG_SWIDTH_SWIDTH_16BitIn32 in my application, hoping to enable these 32 bit sample width options:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define NRF_I2S_HAS_SWIDTH_32BIT 1
#define I2S_CONFIG_SWIDTH_SWIDTH_32Bit 1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;However, this did not appear to work. The 32 bit sample width options remain disabled.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;What do I need to do to enable the 32 bit sample width options?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467653?ContentTypeID=1</link><pubDate>Mon, 05 Feb 2024 19:22:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5416c9b-36f9-44d6-b7cf-ad4f3cc9fe18</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;According to the formulas in the Infocenter&amp;nbsp;documentation you linked to above, the two relevant formulas are:&lt;/p&gt;
&lt;p&gt;LRCK = MCK / CONFIG.RATIO&lt;/p&gt;
&lt;p&gt;SCK = 2 * LRCK * CONFIG.SWIDTH&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;MCK is set by config.mck_setup =&amp;nbsp;NRF_I2S_MCK_32MDIV21, giving MCK = 1.536MHz.&lt;/p&gt;
&lt;p&gt;config.ratio = NRF_I2S_RATIO_96X should give 16kHz (1.536MHz/16kHz = 96)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;SCK = 2 * LRCK * CONFIG.SWIDTH&lt;/p&gt;
&lt;p&gt;SCK = 2 * 16kHz * config.swidth&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Desired SCK: 1.024MHz, or 1.536MHz, or 2.048MHz&lt;/p&gt;
&lt;p&gt;1.024MHz = 2 * 16kHz * config.swidth&lt;br /&gt;config.swidth = 32&lt;/p&gt;
&lt;p&gt;Shouldn&amp;#39;t this give me a BCK of 1.024MHz?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467652?ContentTypeID=1</link><pubDate>Mon, 05 Feb 2024 19:14:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76f5c733-0597-441a-a778-fdbdfb9073f2</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I tried this out today. I swapped the pins so that my SCK hardware is connected to the MCK output instead. This gives me a SCK rate of 1.53MHz with an LRCK of 16kHz, which matches the ratio I desire. The SCK output (now routed to my unused MCK pin) continues to run at 512kHz (ratio of 32x from the LRCK of 16kHz).&lt;/p&gt;
&lt;p&gt;However, you are also correct that the I2S peripheral is changing the SDOUT data according to the SCK rate, not the MCK rate. So this &amp;#39;hack&amp;#39; technically gives me the SCK/LRCK ratio I desired, but now the data output does not align with the SCK, so it is still unusable.&lt;/p&gt;
&lt;p&gt;Are there any other techniques to directly set the SCK and LRCK speeds, rather than having the driver calculate them for me automatically?&lt;br /&gt;&lt;br /&gt;It would be great if both the LRCK and SCK could be directly set as a multiple of the I2S peripheral MCK value. Something like:&lt;/p&gt;
&lt;p&gt;MCK: 1.524MHz (set by mck_setup =&amp;nbsp;NRF_I2S_MCK_32MDIV21, 32MHz oscillator / 21 = 1.524 MHz)&lt;br /&gt;BCK: 1.524MHz (1:1 BCK to LRCK ratio)&lt;br /&gt;LRCK: 15.875kHz (96 MCK cycles = 1 LRCK cycle, 1.524MHz/96 = 15.875kHz)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467559?ContentTypeID=1</link><pubDate>Mon, 05 Feb 2024 12:31:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9a7ccc9-248d-485c-9b25-6fdbb03cd94a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I suspect the issue here is that the ratio has no impact on the SCK output, AKA the BCLK, as can be seen from the SCK formula &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/i2s.html?cp=5_0_0_5_10_3#concept_ogc_dsy_vr"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Essentially the SCK clock is a simple multiple of the LRCK and the bitwidth, and is not affected by the MCK directly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I did a quick test of this myself and confirmed that changing the ratio from 64 to 128 only affected MCK, not SCK or LRCK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried to connect the MCK signal to the TAS2563 rather than the SCK, and see if this works fine?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I guess the question is when the TI device will sample the bits, since the output data from the nRF device will be changed according to SCK, not MCK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467259?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2024 21:54:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afa455ce-3df2-49e9-9fe2-b3ddc7c45016</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&amp;nbsp;, I have not tried this yet, but I am very hesitant to modify any of the code within the SDK itself. I don&amp;#39;t want to have to fork the SDK and maintain these customizations outside of my own software repositories.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/467258?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2024 21:53:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a70e64b-c29b-407c-af4c-92f393e2adf0</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;Apologies for the lateness of this reply.&lt;/p&gt;
&lt;p&gt;I have spent some time rewriting my audio thread to use the nrfx I2S driver, instead of the Zephyr I2S driver. I now have a version of my application that is successfully clocking out data over I2S again, and I can adjust the clock speeds by changing inputs to the nrfx_i2s_config_t struct.&lt;/p&gt;
&lt;p&gt;However, I am still having trouble controlling the BCLK to LRCLK ratio, specifically.&lt;br /&gt;I have tried a variety of inputs, adjusting the mck_setup, ratio, and sample_width parameters. However I am still unable to achieve a BCLK to LRCLK ratio of 64. It seems that no matter what ratio I apply (48X/64X/96X/192X) the actual ratio I observe is 32 BCLKs per LRCLK.&lt;/p&gt;
&lt;p&gt;I also dug through the sample_width parameter definitions and tried out I2S_CONFIG_SWIDTH_SWIDTH_16BitIn32 (#defined as 0x6), which did allow me to hit a ratio of 48 BCLKs per LRCLK. I tried I2S_CONFIG_SWIDTH_SWIDTH_8BitIn32 (#define as 0x5), but that again gives me an observed ratio of 32.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Here is a table I created of the I2S config parameters I have tested, and the output clock speeds I have observed on my oscilloscope:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/I2S_5F00_clock_5F00_testing.png" /&gt;&lt;/p&gt;
&lt;p&gt;My target I2S parameters:&lt;br /&gt;-16kHz sampling&lt;br /&gt;-Mono audio&lt;br /&gt;-16 bits/sample&lt;br /&gt;-BCLK to LRCLK ratio of 64, 96, or 128 (so, BCLK freq of 1.024MHz/1.536MHz/2.048MHz)&lt;/p&gt;
&lt;p&gt;Is there a process behind the scenes that is calculating clock speeds automatically?&lt;br /&gt;Why isn&amp;#39;t the nrfx_i2s_config_t.ratio parameter being respected?&lt;br /&gt;What other parameters can I change to hit 64 BCLKs per LRCLK?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/464394?ContentTypeID=1</link><pubDate>Tue, 16 Jan 2024 12:53:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72762c9f-fe71-4232-8087-5990236068bd</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Chris&lt;/p&gt;
&lt;p&gt;Looking at the code it seems the radio is automatically configured, trying to find a configuration that gives the least amount of offset from the requested settings without giving you exact control of all the parameters.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As an experiment, could you try to change this line in i2s_nrfx.c to start the loop at 2 rather than 0?&amp;nbsp;&lt;br /&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/i2s/i2s_nrfx.c#L92"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/i2s/i2s_nrfx.c#L92&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for (r = 2; r &amp;lt; ARRAY_SIZE(ratios); ++r) {&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then it should hopefully select a ratio of 64 rather than 32...&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/463832?ContentTypeID=1</link><pubDate>Thu, 11 Jan 2024 16:19:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:765d17a6-2c4a-4735-b136-fc1f4c10363a</guid><dc:creator>cfernandezruns</dc:creator><description>&lt;p&gt;Understood. I wondered if that might be the case. I appreciate you taking a look to see if this is possible with the Zephyr driver. I look forward to hearing back from you on this, thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: configuring clock details with Zephyr</title><link>https://devzone.nordicsemi.com/thread/463772?ContentTypeID=1</link><pubDate>Thu, 11 Jan 2024 13:53:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58bf3e52-3b69-4fa4-b526-8082dda7e83b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Chris&lt;/p&gt;
&lt;p&gt;The Zephyr I2S driver is quite generic and will not be able to cover all the configuration options of the I2S peripheral in the nRF devices.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The developers behind the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/nrf5340_audio/doc/index.html"&gt;LE Audio project&lt;/a&gt; ended up using the nrfx_i2s driver rather than the Zephyr driver for just this reason, and you might want to do the same in order to get full control over the I2S peripheral.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can take a closer look at the driver implementation tomorrow and see if I can spot a way to get the configuration you need, but I wouldn&amp;#39;t be surprised if this can only be handled by the nrfx driver.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>