AnsweredAssumed Answered

Issues with SAI I2S DMA Callback Firing one Frame Too Early on KL27

Question asked by Kyle Manna on Jan 19, 2017
Latest reply on Jan 20, 2017 by Kyle Manna

Hi all,

 

I have a KL27 with a SGTL5000 audio codec using the I2S SAI peripheral using Kinetis SDK 2.1.  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.

 

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.  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.  If I repeat the transfer, the last frame appears immediately on the wire and the problem repeats.

 

I've captured this with my scope to confirm my suspicions:

Should be a 3 frame I2S transfer with [ 0x1122, 0x3344, 0x4455 ], but last frame was never sent.

 

If I modify `SAI_TransferAbortSendDMA()` and comment out the 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:

SAI transfer with all data with call back disabling the SAI disable

 

Does anyone have a solution to this?  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.

Outcomes