<?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: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89426/i2s-bit-alignment-in-24bit-mono-mode</link><description>Hi, 
 I&amp;#39;m using a nRF52 DK (nRF52832) and nRF5 SDK 17.0.1. to read data from an external ADC via I2S. I can read some data from the I2S bus, but I&amp;#39;m confused about the bit alignment. 
 The ADC is configured to provide 24 bit samples. The Product Specification</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 Jul 2022 13:04:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89426/i2s-bit-alignment-in-24bit-mono-mode" /><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/379141?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 13:04:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb8a68d7-73cb-4c79-a432-99872725b686</guid><dc:creator>Moritz_S</dc:creator><description>&lt;p&gt;I found the answer to my problem. I used the queue in overflow mode, which caused the data distortion + I think NRF_LOG_INFO() and printf() should be avoided for debugging such issues. It seems they also do not output all the data. However, I also don&amp;#39;t know another efficient way to debug this.&lt;/p&gt;
&lt;p&gt;More details about this can be found here: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/88752/sending-i2s-data-via-ble-using-queue"&gt;devzone.nordicsemi.com/.../sending-i2s-data-via-ble-using-queue&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/376263?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2022 14:54:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42db26c1-38d6-4ca8-9ecf-355cd2513565</guid><dc:creator>Moritz_S</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I managed to print the data. I realized that the amount of print statements has an influence on the data distortion.&lt;/p&gt;
&lt;p&gt;If I print my data in a loop in my data_handler(), the result is an almost perfect sine wave.&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/data_5F00_handler_5F00_sinus_5F00_close.png" /&gt;&lt;/p&gt;
&lt;p&gt;Printing in the data_handler() AND the queue_data() function will not work (only the prints in the data_handler() will show up), I have to remove the log statement in the data_handler() and add it in the queue_data(). When I plot the data here, the sinus is still recognizable, but already distorted:&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/queue_5F00_data_5F00_32bit_5F00_close.png" /&gt;&lt;/p&gt;
&lt;p&gt;What could be the reason for that?&lt;/p&gt;
&lt;p&gt;My guess is, that while I&amp;#39;m processing the data in queue_data(), the data_handler() is called again and overwrites the data in mp_block_to_check while I&amp;#39;m still processing it.&lt;/p&gt;
&lt;p&gt;for your reference, I&amp;#39;m adding my main loop, which checks if data has been written to mp_block_to_check by the data_handler() and, if yes, passes the address to queue_data().&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// variables are declared in the beginning of the file as global variable
// I just add it here for reference
static uint32_t const * volatile mp_block_to_check = NULL;
static uint8_t m_array[243] = {0};

// my main loop, simplyfied to the most important parts
for (;;)
{
    if (mp_block_to_check)
    {
        queue_data(mp_block_to_check);
        mp_block_to_check = NULL;
    }

    //get data from the queue
    err_code = nrf_queue_read(&amp;amp;m_queue, &amp;amp;m_array, sizeof(m_array));
    if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_NOT_FOUND)
       )
    {
        APP_ERROR_CHECK(err_code);
    }

    // send data via BLE
    if (err_code != NRF_ERROR_NOT_FOUND)
    {
        err_code = ble_aas_value_update(&amp;amp;m_aas, &amp;amp;m_array);
        if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
            (err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
           )
        {
            APP_ERROR_CHECK(err_code);
        }
        else if (err_code == NRF_ERROR_RESOURCES)
        {
            ble_ready = false;
            while (!ble_ready)
            {
                idle_state_handle();
            }
            err_code = ble_aas_value_update(&amp;amp;m_aas, &amp;amp;m_array);
            if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
                (err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
                (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
                (err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
                (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
               )
            {
                APP_ERROR_CHECK(err_code);
            }
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The function queue_data() is already included in my initial post. ble_aas_value_update just sends the data via BLE.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any idea what could cause the data distrotion and how to improve my code to avoid that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/376221?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2022 12:54:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d53fb3ce-4397-4856-ab5e-95edf7f4c6de</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you need to log a lot of data fast you could consider not using deferred logging (that might cause timing problems for you app, but if would make logging more efficient). You could also increase buffer sizes in sdk_config.h both for RTT and the logger module. And lastly, perhaps you don&amp;#39;t need to log much/for a long time if this is consistent?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/376211?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2022 12:29:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df3599c6-6041-421b-8318-c496316a6e96</guid><dc:creator>Moritz_S</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thanks for the info. Could you tell me how to log a large array? I was trying with RTTLogger (which basically works for simple debug messages), but when it comes to logging the data array the chip freezes (All LEDs on). I was trying NRF_LOG_INFO() and NRF_LOG_HEXDUMP_INFO().&lt;/p&gt;
&lt;p&gt;I was using&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_LOG_HEXDUMP_INFO(mp_block_to_check,(I2S_DATA_BLOCK_WORDS*4));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in the data_handler which is provided in my initial post. mp_block_to_check points towards p_released-&amp;gt;p_rx_buffer and I2S_DATA_BLOCK_WORDS is the size of this buffer in uint32_t samples.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/376159?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2022 09:49:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81f3bd8d-981e-42d2-9cd8-1820ef43b585</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote user="Moritz_S"]In the meantime, could it be that BLE and I2S interfere with each other? That some BLE interrupts cause the I2S to not read correcly from the bus?[/quote]
&lt;p&gt;The I2S peripheral use DMA, so the CPU is not used during a transaction, so BLE (or other) activity should not cause any problems in that case. But the pre- and post processing could potentially be delayed if higher priority interrupts happen, including BLE related from the SoftDevice. (It should be quick to check if this is related though, by simply stripping away the BLE part and logging the samples via for instance RTT to check if there is any difference)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/376151?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2022 09:30:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4559c12-a1ee-4884-94de-9337914d5289</guid><dc:creator>Moritz_S</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thanks for your reponse. I verified now that my data is in fact left aligned, so discarding the first 8 bits should be correct and not cause this problem.&lt;/p&gt;
&lt;p&gt;I also checked the data that are received by the i2s, i.e., I checked the data in&amp;nbsp;p_released-&amp;gt;p_rx_buffer in the data_handler(). Turns out that the data is already corrupted here - I&amp;#39;m expecting a sine wave, but the signal I receive is far from that.&amp;nbsp;I will try to create some plots of the logged data and post them the coming days.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the meantime, could it be that BLE and I2S interfere with each other? That some BLE interrupts cause the I2S to not read correcly from the bus?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S: Bit-Alignment in 24bit Mono mode</title><link>https://devzone.nordicsemi.com/thread/374722?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 11:46:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8d1f063-2c68-477f-96a7-3814a790228c</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not clear to mere where the data gets corrupted (in one way or another). Can you try to log the data both when received via I2S, and when you have packed it for BLE transfer and when received just to pinpoint where things get mixed up, to verify if this is an issue of alignment or something else?&lt;/p&gt;
&lt;p&gt;Regarding&amp;nbsp;I2S_CONFIG_ALIGN 0 here means left-aligned, so you should set to 1 if you want right-aligned and use this when configuring the driver (it is mapped to&amp;nbsp;NRFX_I2S_CONFIG_ALIGN, which in turn is used in&amp;nbsp;NRFX_I2S_DEFAULT_CONFIG). If you don&amp;#39;t use this and instead provide your ow struct to&amp;nbsp;nrf_drv_i2s_init(), then you need to update the alignment there to change it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>