<?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 change from writing in Register to driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55029/i2s-change-from-writing-in-register-to-driver</link><description>Hello, 
 I will use the I2S driver instead the direct acess to the registers. 
 I have implemented the registers version like this and it works / sounds normaly. 
 
 now I have modified the code to the driver code but the output sound is slower than the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 02 Dec 2019 22:39:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55029/i2s-change-from-writing-in-register-to-driver" /><item><title>RE: I2S change from writing in Register to driver</title><link>https://devzone.nordicsemi.com/thread/223165?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 22:39:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71de183f-85db-4fb4-8387-1116a30e5312</guid><dc:creator>wpaul</dc:creator><description>[quote userid="73427" url="~/f/nordic-q-a/55029/i2s-change-from-writing-in-register-to-driver/223149"]Have you tried the i2s example in the SDK?[/quote]
&lt;p&gt;I must point out that the I2S example in the SDK is of limited use for someone designing or troubleshooting a real world application. The problem is that you need an external codec chip in order to actually hear the output of the I2S module, and the Nordic NRF52 dev boards don&amp;#39;t include one. Because of this, the SDK example can&amp;#39;t do much except loop samples back between the TX and RX paths. This is not how most people are going to to use I2S.&lt;/p&gt;
&lt;p&gt;The one major difference between the &amp;quot;direct access to registers&amp;quot; and &amp;quot;driver&amp;quot; approach used here is that the former relies on polling the EVENTS_TXPTRUPD register while the latter relies on the interrupt that&amp;#39;s supposedly generated when the EVENTS_TXPTRUPD register changes state.&lt;/p&gt;
&lt;p&gt;I say &amp;quot;supposedly&amp;quot; because in my own attempts to use the I2S module, it didn&amp;#39;t seem to work that way. My expectation was that an interrupt event would be generated immediately once the I2S controller finished transferring the number of words specified in the RXTXD_MAXCNT register. I assumed that this would allow me to accurately detect when the current batch of samples had finished playing However that&amp;#39;s not what appeared to actually happen. The contents of the EVENTS_TXPTRUPD did indeed seem to change at this point, such that polling this register produced the correct result, but the interrupt event seemed to occur at the wrong time. From what I could tell, it was triggering too early, with the result being that the output sounded garbled.&lt;/p&gt;
&lt;p&gt;I worked around this by using the PPI module. I tied the EVENTS_TXPTRUPD register to a PPI channel and then tied that channel to a software generated interrupt,&amp;nbsp; and then set things up so that the following would happen:&lt;/p&gt;
&lt;p&gt;- samples are queued up to play&lt;/p&gt;
&lt;p&gt;- the I2S EVENTS_TXPTRUPD interrupt occurs&lt;/p&gt;
&lt;p&gt;- the I2S interrupt handler acks the EVENTS_TXPTRUPD event and then enables the PPI channel&lt;/p&gt;
&lt;p&gt;- once the EVENTS_TXPTRUPD register actually changes state, the PPI channel triggers the software interrupt&lt;/p&gt;
&lt;p&gt;- the software interrupt is now triggered once the samples are actually done playing&lt;/p&gt;
&lt;p&gt;Below is a link to my driver code:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/netik/dc27_badge/blob/master/software/firmware/badge/nrf52i2s_lld.c"&gt;https://github.com/netik/dc27_badge/blob/master/software/firmware/badge/nrf52i2s_lld.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/netik/dc27_badge/blob/master/software/firmware/badge/nrf52i2s_lld.h"&gt;https://github.com/netik/dc27_badge/blob/master/software/firmware/badge/nrf52i2s_lld.h&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know if I was doing something wrong elsewhere that caused this condition to occur, but I experimented for quite some time trying to figure it out and in the end (like the poster above), I wasn&amp;#39;t able to find where I was doing anything wrong. The manual seemed to strongly imply that the I2S module would generate an interrupt as soon as the current batch of samples was finished transferring, but that did not seem to be the case, and I nothing I did seemed to change that. My PPI workaround was good enough for my needs so I never followed up on it further. Also, since the Nordic DK boards do not have an audio codec chip on them, I wasn&amp;#39;t sure that asking Nordic for help would do any good since there would be no easy way for them to reproduce my environment for testing. Otherwise, I would have asked:&lt;/p&gt;
&lt;p&gt;- How can one be sure exactly when the I2S interrupt fires? Is it supposed to trigger right when EVENTS_TXPTRUPD changes state or not? If not, when? If yes, have you guys actually tested it with a codec attached, and do you have an actual known good working example for playing audio samples that behaves correctly?&lt;/p&gt;
&lt;p&gt;Note that I used the ChibiOS RTOS in my application and did not use the Nordic SDK, however I don&amp;#39;t think this had anything to do with the problem. The codec we used was a CS4344.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2S change from writing in Register to driver</title><link>https://devzone.nordicsemi.com/thread/223149?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 17:14:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4aa702e-f929-4ea0-8691-62752e1d6cc1</guid><dc:creator>Marjeris Romero</dc:creator><description>[quote user=""]Its like the handler is too slow.[/quote]
&lt;p&gt;How are you measuring this?&lt;/p&gt;
&lt;p&gt;Are you running other things than I2S in your application?&lt;/p&gt;
&lt;p&gt;Which SDK version are you using?&lt;/p&gt;
&lt;p&gt;What is NRFX_I2S_CONFIG_IRQ_PRIORITY set to in sdk_config.h?&lt;/p&gt;
&lt;p&gt;Have you tried the i2s example in the SDK?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>