<?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 Why doesn't my I2S controller transmit data?  in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-doesn-t-my-I2S-controller-transmit-data/m-p/618147#M36879</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to output sound using a K22F microcontroller connected to an SGTL5000 audio codec. I have been able to configure all the required clocks (TX_FS, TX_BCLK and MCLK) but am unable to produce any data on the I2S0_TXD0 pin of the K22F. I'm using version 2.0 of the Kinetis SDK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my setup code for the I2S/SAI controller:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Initialise the SAI/I2S module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.protocol = kSAI_BusI2S;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.syncMode = kSAI_ModeAsync; // Since the MCU is providing MCLK&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.mclkOutputEnable = true;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.mclkSource = kSAI_MclkSourceSysclk;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.bclkSource = kSAI_BclkSourceMclkDiv;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.masterSlave = kSAI_Master;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;SAI_TxInit(I2S0, &amp;amp;g_sai_tx_config);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Set the format of the data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.bitWidth = kSAI_WordWidth16bits;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.channel = 0; // Taken from Kinetis Serial Audio Training P17&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.sampleRate_Hz = kSAI_SampleRate48KHz;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.masterClockHz = 256 * kSAI_SampleRate48KHz; //12.288MHz&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.stereo = kSAI_Stereo;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.protocol = kSAI_BusI2S;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.watermark = 4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;SAI_TxSetFormat(I2S0, &amp;amp;g_sai_tx_format, CLOCK_GetCoreSysClkFreq(), g_sai_tx_format.masterClockHz);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;SAI_TxEnable(I2S0, true);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here's my attempt to output some audio data (a 1kHz square wave)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#define I2S_BUFFER_SIZE 96 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;uint8_t buffer[I2S_BUFFER_SIZE];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;int8_t amplitude = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;I2S0-&amp;gt;TCSR |= I2S_TCSR_FEF_MASK; // Write 1 to clear transmit underrun flag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;for(;;) { /* Infinite loop to avoid leaving the main function */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; // Transmit a square wave - alternately send a full buffer of 0xFF then 0x00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for (int i = 0; i &amp;lt; I2S_BUFFER_SIZE; i++){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buffer[i] = (0xFF * amplitude);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; amplitude ^= 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; SAI_WriteBlocking(I2S0, 0, kSAI_WordWidth16bits, buffer, I2S_BUFFER_SIZE);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that I don't see any data being generated on the TX pin, pausing execution I can see the code is caught in this loop in the SAI_WriteBlocking method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Wait until it can write data */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;while (!(base-&amp;gt;TCSR &amp;amp; I2S_TCSR_FWF_MASK))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This implies (and I have verified) that the I2S0-&amp;gt;TCSR-&amp;gt;FWF register (FIFO warning flag) is 0 which means "No enabled transmit FIFO is empty.". Why isn't the transmit FIFO being sent (and emptied) by the I2S controller?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may also be relevant that when I pause execution I can see that the I2S0-&amp;gt;TCSR-&amp;gt;FEF (FIFO error flag) register is 1 indicating "Transmit underrun detected.". What could be causing the underrun? I've tried clearing this flag but as soon as I queue data again it is immediately set to 1 again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Sep 2016 10:26:07 GMT</pubDate>
    <dc:creator>donturner</dc:creator>
    <dc:date>2016-09-14T10:26:07Z</dc:date>
    <item>
      <title>Why doesn't my I2S controller transmit data?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-doesn-t-my-I2S-controller-transmit-data/m-p/618147#M36879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to output sound using a K22F microcontroller connected to an SGTL5000 audio codec. I have been able to configure all the required clocks (TX_FS, TX_BCLK and MCLK) but am unable to produce any data on the I2S0_TXD0 pin of the K22F. I'm using version 2.0 of the Kinetis SDK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my setup code for the I2S/SAI controller:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Initialise the SAI/I2S module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.protocol = kSAI_BusI2S;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.syncMode = kSAI_ModeAsync; // Since the MCU is providing MCLK&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.mclkOutputEnable = true;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.mclkSource = kSAI_MclkSourceSysclk;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.bclkSource = kSAI_BclkSourceMclkDiv;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_config.masterSlave = kSAI_Master;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;SAI_TxInit(I2S0, &amp;amp;g_sai_tx_config);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Set the format of the data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.bitWidth = kSAI_WordWidth16bits;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.channel = 0; // Taken from Kinetis Serial Audio Training P17&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.sampleRate_Hz = kSAI_SampleRate48KHz;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.masterClockHz = 256 * kSAI_SampleRate48KHz; //12.288MHz&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.stereo = kSAI_Stereo;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.protocol = kSAI_BusI2S;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;g_sai_tx_format.watermark = 4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;SAI_TxSetFormat(I2S0, &amp;amp;g_sai_tx_format, CLOCK_GetCoreSysClkFreq(), g_sai_tx_format.masterClockHz);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;SAI_TxEnable(I2S0, true);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here's my attempt to output some audio data (a 1kHz square wave)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#define I2S_BUFFER_SIZE 96 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;uint8_t buffer[I2S_BUFFER_SIZE];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;int8_t amplitude = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;I2S0-&amp;gt;TCSR |= I2S_TCSR_FEF_MASK; // Write 1 to clear transmit underrun flag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;for(;;) { /* Infinite loop to avoid leaving the main function */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; // Transmit a square wave - alternately send a full buffer of 0xFF then 0x00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for (int i = 0; i &amp;lt; I2S_BUFFER_SIZE; i++){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buffer[i] = (0xFF * amplitude);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; amplitude ^= 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; SAI_WriteBlocking(I2S0, 0, kSAI_WordWidth16bits, buffer, I2S_BUFFER_SIZE);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that I don't see any data being generated on the TX pin, pausing execution I can see the code is caught in this loop in the SAI_WriteBlocking method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;/* Wait until it can write data */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;while (!(base-&amp;gt;TCSR &amp;amp; I2S_TCSR_FWF_MASK))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This implies (and I have verified) that the I2S0-&amp;gt;TCSR-&amp;gt;FWF register (FIFO warning flag) is 0 which means "No enabled transmit FIFO is empty.". Why isn't the transmit FIFO being sent (and emptied) by the I2S controller?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may also be relevant that when I pause execution I can see that the I2S0-&amp;gt;TCSR-&amp;gt;FEF (FIFO error flag) register is 1 indicating "Transmit underrun detected.". What could be causing the underrun? I've tried clearing this flag but as soon as I queue data again it is immediately set to 1 again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2016 10:26:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-doesn-t-my-I2S-controller-transmit-data/m-p/618147#M36879</guid>
      <dc:creator>donturner</dc:creator>
      <dc:date>2016-09-14T10:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't my I2S controller transmit data?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-doesn-t-my-I2S-controller-transmit-data/m-p/618148#M36880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Don, &lt;/P&gt;&lt;P&gt;which example in SDK2.0 are you using? Can you see the TX_FS, TX_BCLK?&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;XiangJun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Sep 2016 09:30:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-doesn-t-my-I2S-controller-transmit-data/m-p/618148#M36880</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2016-09-18T09:30:33Z</dc:date>
    </item>
  </channel>
</rss>

