<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Issues with SAI I2S DMA Callback Firing one Frame Too Early on KL27 in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630088#M6698</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kyle,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a similar problem when using DMA to transfer data over SPI.&amp;nbsp; I only needed to transmit data and turn off the SPI Chip Select line after that.&amp;nbsp; The DMA callback would get called right after the last byte hit the FIFO, and before the byte made it over the bus.&amp;nbsp; This would result in the CS line being de-asserted too soon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case the solution was simple: providing an RX buffer would delay the time at which the callback was invoked.&amp;nbsp; Would a solution like that work in your case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Jan 2017 21:17:34 GMT</pubDate>
    <dc:creator>javiercardona</dc:creator>
    <dc:date>2017-01-20T21:17:34Z</dc:date>
    <item>
      <title>Issues with SAI I2S DMA Callback Firing one Frame Too Early on KL27</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630087#M6697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a KL27 with&amp;nbsp;a SGTL5000 audio codec using the I2S SAI peripheral using Kinetis SDK 2.1. &amp;nbsp;I'm able to setup and send data as expected, but the DMA transfer seems to fire the callback exactly one I2S frame too early.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect that the DMA callback fires when all the data is written to the FIFO, but the FIFO hasn't been written out the serial line yet. &amp;nbsp;The DMA callback in the fsl_sai_dma driver then disables the I2S transmitter and it appears that the last frame is stuck in the FIFO. &amp;nbsp;If I repeat the transfer, the last frame appears immediately on the wire and the problem repeats.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've captured this with my scope to confirm my suspicions:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="174820_174820.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/122769i7AF7CE894FA3A38D/image-size/large?v=v2&amp;amp;px=999" role="button" title="174820_174820.png" alt="174820_174820.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="SAI DMA Missing Frame.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/12994i341A373AE7377F8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAI DMA Missing Frame.png" alt="SAI DMA Missing Frame.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I modify `SAI_TransferAbortSendDMA()` and comment out the&amp;nbsp;the `SAI_TxEnable(base, false);` line so that the I2S transmitter stays enabled then the last byte shows up on the scope, but something is broke and subsequent transfers fail and I haven't debugged this yet, but I suspect a SAI FIFO error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="174869_174869.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/122770i78D4B66B9A184914/image-size/large?v=v2&amp;amp;px=999" role="button" title="174869_174869.png" alt="174869_174869.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="SAI DMA All Frames with TX left Enabled.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/13034i5E4C90548FBC41EF/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAI DMA All Frames with TX left Enabled.png" alt="SAI DMA All Frames with TX left Enabled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have a solution to this? &amp;nbsp;It seems that disabling the SAI transmitter needs to be delayed until after the last frame is on it's way out as opposed to sitting in the FIFO.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2017 06:38:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630087#M6697</guid>
      <dc:creator>2bluesc</dc:creator>
      <dc:date>2017-01-20T06:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with SAI I2S DMA Callback Firing one Frame Too Early on KL27</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630088#M6698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kyle,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a similar problem when using DMA to transfer data over SPI.&amp;nbsp; I only needed to transmit data and turn off the SPI Chip Select line after that.&amp;nbsp; The DMA callback would get called right after the last byte hit the FIFO, and before the byte made it over the bus.&amp;nbsp; This would result in the CS line being de-asserted too soon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case the solution was simple: providing an RX buffer would delay the time at which the callback was invoked.&amp;nbsp; Would a solution like that work in your case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2017 21:17:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630088#M6698</guid>
      <dc:creator>javiercardona</dc:creator>
      <dc:date>2017-01-20T21:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with SAI I2S DMA Callback Firing one Frame Too Early on KL27</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630089#M6699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I worked around this by turning on the FIFO empty warning IRQ in the DMA About Send function instead of disabling the the transmitter. &amp;nbsp;In the FIFO empty warning call back I then disable the transmitter and it works as expected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I threw together a &lt;A href="https://gist.github.com/c7dd795167f8a8c315c31894394fdc8e"&gt;patch to share&lt;/A&gt;. &amp;nbsp;Hopefully NXP can implement an improved version in to the next SDK release or suggest a better solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Working scope trace:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="NewFile36.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/12225i75248D3B4A2CB1A0/image-size/large?v=v2&amp;amp;px=999" role="button" title="NewFile36.png" alt="NewFile36.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://gist.github.com/c7dd795167f8a8c315c31894394fdc8e"&gt;Link to Github gist of the patch&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2017 21:42:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Issues-with-SAI-I2S-DMA-Callback-Firing-one-Frame-Too-Early-on/m-p/630089#M6699</guid>
      <dc:creator>2bluesc</dc:creator>
      <dc:date>2017-01-20T21:42:29Z</dc:date>
    </item>
  </channel>
</rss>

