<?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 does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21504/i2s-does-not-work-as-expected-on-nrf52832</link><description>Hello, 
 some time ago I was struggling with interfacing an I2S microphone with the nRF52832. That remained unsuccessful. My conclusion back then was that the selected I2S microphone and the nRF52832 were incompatible (the mic wanted 32-bit word size</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 Nov 2017 08:22:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21504/i2s-does-not-work-as-expected-on-nrf52832" /><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84404?ContentTypeID=1</link><pubDate>Wed, 15 Nov 2017 08:22:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dac0c291-1c62-44ed-a456-167f8ab23a34</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;Hi Rahul, no, I cannot give you any code as it&amp;#39;s IP of my employer not mine. Sorry.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84403?ContentTypeID=1</link><pubDate>Wed, 15 Nov 2017 08:04:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c113e270-af31-4d9d-9d22-6953a7a6a2bb</guid><dc:creator>Raja</dc:creator><description>&lt;p&gt;Hi @endnode do you have sample code for max98357a wit nrf52. I am learning i2s for audio.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84407?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2017 19:54:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a23c9be1-11e5-4104-9b88-a417b1366e07</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;Hi Jørn,&lt;/p&gt;
&lt;p&gt;thanks for the reply. We are still checking this problem - but with rather low priority.
I will get back to you soon.&lt;/p&gt;
&lt;p&gt;Tamas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84406?ContentTypeID=1</link><pubDate>Thu, 11 May 2017 07:58:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c428cff-da5d-474f-93ea-b35585b83685</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Hello newtom&lt;/p&gt;
&lt;p&gt;I apologize for the late reply&lt;/p&gt;
&lt;p&gt;The fact that the 1kHz noise is not affected by any of the changes you make leads me to believe it is caused by either the power supply, or possibly something on a timer running with a 1ms interval. How have you powered your system? If you are powering it through USB, I would like you to try and switch to a battery, or at least a more clean running power supply, and see if that clears up the noise. If it doesn&amp;#39;t, see if you have any timers running, or if anything with a high current consumption triggers (i.e. the radio), with a 1ms interval.&lt;/p&gt;
&lt;p&gt;It would also be interesting to know if the distortions are present on the data sent from the Codec, or if it is generated on being received at the nRF. If you could use a logic analyzer and look at the data outputted from the codec that could be helpful.
As for the SD-card noise, are the pins you use for the SPI and I2S close to each other?&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Jørn Frøysa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84405?ContentTypeID=1</link><pubDate>Wed, 26 Apr 2017 11:19:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83438480-5fc4-4645-8737-416250d6f95a</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
&lt;p&gt;after much invested time I came to the conclusion that the WM8731 I was using was damaged! I don&amp;#39;t know when and how it happened, but after swapping the codec, things worked better.&lt;/p&gt;
&lt;p&gt;So at this point I&amp;#39;d like to formally apologise for my previous assumption that the I2S interface of the nRF52 would be useless. (Whether it is buggy or not, I am not sure yet.)&lt;/p&gt;
&lt;p&gt;I am now able to record over line-in through the WM8731, when the nRF52 is master. I used the following setup:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define TWI_frequency     NRF_TWI_FREQ_400K

#define I2S_BUFF_LENGTH 512
uint32_t m_i2sBuffer[I2S_BUFF_LENGTH]= {0};

nrf_drv_i2s_config_t const I2S_config=
{ 
  .sck_pin      = (uint8_t) PIN_I2S_SCK,
  .lrck_pin     = (uint8_t) PIN_I2S_LRCK,
  .mck_pin      = (uint8_t) PIN_I2S_MCK,
  .sdout_pin    = (uint8_t) NRF_DRV_I2S_PIN_NOT_USED,
  .sdin_pin     = (uint8_t) PIN_I2S_SDIN,
  .irq_priority = (uint8_t) APP_IRQ_PRIORITY_LOW,
  .mode         = (nrf_i2s_mode_t) I2S_CONFIG_MODE_MODE_Master,
  .format       = (nrf_i2s_format_t) I2S_CONFIG_FORMAT_FORMAT_I2S,
  .alignment    = (nrf_i2s_align_t) I2S_CONFIG_ALIGN_ALIGN_Left,
  .sample_width = (nrf_i2s_swidth_t) I2S_CONFIG_SWIDTH_SWIDTH_16Bit,
  .channels     = (nrf_i2s_channels_t) I2S_CONFIG_CHANNELS_CHANNELS_Left,
  .mck_setup    = (nrf_i2s_mck_t) I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV8,
  .ratio        = (nrf_i2s_ratio_t) I2S_CONFIG_RATIO_RATIO_128X
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above gives me 31250 Hz, 16 bit, mono recording. This is how I set up the codec:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;wm8731_reset(&amp;amp;m_twi);
wm8731_set_master_or_slave_mode(&amp;amp;m_twi, 0);           // set codec to be slave
wm8731_power_mode_all_active(&amp;amp;m_twi);
wm8731_set_sampling_control(&amp;amp;m_twi, 0, 0, 7);         // normal mode, BOSR=0, SR=[0,1,1,1]
wm8731_set_digital_audio_interface_format(&amp;amp;m_twi, 2); // I2S
wm8731_set_digital_audio_data_bit_length(&amp;amp;m_twi, 0);  // IWL_16_BIT
wm8731_adc_input_select(&amp;amp;m_twi, 0);                   // select Line-in
wm8731_left_line_in_volume_set(&amp;amp;m_twi, 0x1F);         // max input volume
wm8731_right_line_in_volume_set(&amp;amp;m_twi, 0x1F);        // max input volume
wm8731_set_left_line_in_mute(&amp;amp;m_twi, 0);              // unmute
wm8731_set_right_line_in_mute(&amp;amp;m_twi, 0);             // unmute
wm8731_enable_adc_high_pass_filter(&amp;amp;m_twi, 1);        // enable HPF
wm8731_set_active(&amp;amp;m_twi, 1);  
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And this is how I start I2S:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_i2s_start(m_i2sBuffer, NULL, I2S_BUFF_LENGTH, 0);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, I have some comments on the I2S driver. According to the documentation, it splits the pointed buffer into two halves and uses them as ping-pong buffers. Then the documentation says, the last parameter of &lt;code&gt;nrf_drv_i2s_start()&lt;/code&gt; is &lt;em&gt;&amp;quot;Size of the buffers (in 32-bit words).&amp;quot;&lt;/em&gt; For me it is ambiguous: does it mean the size of each buffer or the total size of the buffers? It turns out, it means the total size.&lt;/p&gt;
&lt;p&gt;The next surprise was, that the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v13.0.0/group__nrf__drv__i2s.html#ga51dda23b1076dc7534954fda093977a5"&gt;I2S handler&lt;/a&gt; seems to deliver the contents of the sample buffers in a (for me) unexpected order. What I mean is, if the input audio can be split into a sequence of buffers &amp;quot;A,B,C,D,E,F,...&amp;quot;, then I get the buffers from the I2S handler in this order: &amp;quot;B,A,D,C,F,E,...&amp;quot;. (I really think that I did not mess up things here myself ...)&lt;/p&gt;
&lt;p&gt;This is an example recording:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/REC_5F00_0092_5F00_TheKyotoConnection_2D00_Hachiko.mp3"&gt;REC_0092_TheKyotoConnection-Hachiko.mp3&lt;/a&gt;
(From &lt;a href="http://freemusicarchive.org/music/The_Kyoto_Connection/Wake_Up_1957/09_Hachiko_The_Faithtful_Dog"&gt;freemusicarchive&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;At first it sounds okay. No clicks at buffer edges, i.e., buffers of samples are transferred OK.&lt;/p&gt;
&lt;p&gt;But if you look at the samples more closely OR if you look at recordings where the input was muted, you will see that there are two problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Every 31st or 32nd sample
(alternating, and this is NOT aligned
with buffer sizes) is superimposed by
a small click, which leads to a 1000
Hz (+harmonics) overlay.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Every writing to the SD card can be
seen (and heard) in form of a
low-frequency (as compared to the 1000 Hz one) distortion.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Waveform.png" alt="Waveform" /&gt;&lt;/p&gt;
&lt;p&gt;Samples are here (to be viewed as waveform):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/REC_5F00_0082_5F00_8MHz_2D00_SPI_5F00_16bit_2D00_DMA.wav"&gt;REC_0082_8MHz-SPI_16bit-DMA.wav&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/REC_5F00_0081_5F00_2MHz_2D00_SPI_5F00_16bit_2D00_DMA.wav"&gt;REC_0081_2MHz-SPI_16bit-DMA.wav&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/REC_5F00_0084_5F00_8MHz_2D00_SPI_5F00_16bit_2D00_NoDMA.wav"&gt;REC_0084_8MHz-SPI_16bit-NoDMA.wav&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/REC_5F00_0086_5F00_8MHz_2D00_SPI_5F00_24bit_2D00_DMA.wav"&gt;REC_0086_8MHz-SPI_24bit-DMA.wav&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are some facts about these distortions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SPI priority (SD card) makes no
difference&lt;/li&gt;
&lt;li&gt;SPI speed (SD card) makes
no difference (tried 2, 4, and 8 MHz)&lt;/li&gt;
&lt;li&gt;Enabling or disabling EasyDMA for SPI
makes no difference&lt;/li&gt;
&lt;li&gt;Bit depth (16 or
24 bit over I2S) makes no difference&lt;/li&gt;
&lt;li&gt;I2S clock (i.e. sampling rate) makes
a difference: doubling the sampling
rate doubles the distance between
clicks&lt;/li&gt;
&lt;li&gt;I2S buffer size makes no
difference (tried: 64, 128, 256, and
512 32-bit words)&lt;/li&gt;
&lt;li&gt;I added all
relevant external components (mostly
capacitors) as
&lt;a href="http://www.mouser.com/ds/2/76/WM8731_v4.9-532414.pdf#page=60"&gt;recommended&lt;/a&gt;,
but they also make no difference.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Can anyone suggest a fix to get rid of the distortions?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thanks,
Tamas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84402?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 20:46:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b426f4f-4203-47cb-ac16-6c5e40c6109d</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thank you very much for the quick reply! I am happy to hear that I2S of the nRF52 worked for you! :) The two main differences I see are a) the direction of the stream (Nordic-&amp;gt;Codec in your case) and b) no need of an MCL with the MAX98357A.&lt;/p&gt;
&lt;p&gt;Regarding your points to double check:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I use a 2-wire interface (TWI) to set up the codec. I already checked it and the TWI part works perfectly.&lt;/li&gt;
&lt;li&gt;I am not affected by the currently listed I2S anomalies.&lt;/li&gt;
&lt;li&gt;I already tried various formats, bit depths, mono and stereo, and sampling frequencies, which both sides (Nordic and Codec) support, but no success.&lt;/li&gt;
&lt;li&gt;My buffers are large enough and handling is OK.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next week I will have access to a 4-channel oscilloscope and I will have a closer look on the I2S stream. Until then I may try to use the codec to play back something from the nRF52 and see if that direction works.&lt;/p&gt;
&lt;p&gt;Thanks again,
Tamas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S does not work as expected on nRF52832</title><link>https://devzone.nordicsemi.com/thread/84401?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2017 22:15:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0881668-5d9a-4083-8a9b-fb89c4c9f42b</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;Hi, I managed to set nRF52832 working on custom PCB with MAX98357A Class-D amplifier connected over I2S and it works very well. Might not be 100% relevant as you have opposite use case (I2S as input to nRF52) but I would double check:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What exact coding on 3-wire interface is configured in your A2D (they typically support I2S, Left-justified and TDM, all with Mono or Stereo, different bit resolutions and different sampling frequencies = in total easily 10-20 configurations leading to &amp;quot;noise&amp;quot; decoding if not aligned on both sides).&lt;/li&gt;
&lt;li&gt;Observe 3-wire interface with logical analyzer and try to decode it manually to confirm it&amp;#39;s exactly what it should be.&lt;/li&gt;
&lt;li&gt;Double check if you are not affected by one of three &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev1.errata/err_832_new.html?cp=2_2_1_0_1"&gt;I2S anomalies existing on nRF52832 Rev 1&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sample recordings with monotone signal (or is it just background noise?) you provide are not helping much but if I understand it correctly it works, there are just some crackling noise cuts. Are you sure that you have correctly implemented both I2S input and SPI output with at least two DMA buffers which make sure that while one is being read the other is being sent over SPI? I managed to get pretty nice opposite application (reading over SPI from external flash and playing over I2S) but it was little flaky when there was heavy BLE activity  (because even with 100-250B buffers in &amp;quot;swing&amp;quot; implementation you need to have some computing time to shift the indexes so if you are blocked for longer period then is one of your I2S input/SPI output blocks you can see crackling effects similar to what you present here).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>