19.4.2.8 Streaming Data Support and Error Handling
Most audio streaming applications transmit or receive data continuously. This is required to keep the channel active during the period of operation and ensures the best possible accuracy. Due to streaming audio, the data feeds could be bursty or packet loss can occur causing the module to encounter underrun. The software needs to be involved to recover from an underrun.
The Ignore Transmit Underrun (IGNTUR) bit (SPIxCON1[28]), when set to a
‘1
’, ignores an Underrun condition. This is helpful for cases when
software does not care or does not need to know about underrun conditions. When an
underrun is encountered, the SPI module sets the SPITUR bit (SPIxSTAT[8]) and when
URDTEN = 1
(SPIxCON1[26]), the module remains in an error state until
the software clears the state or the ON bit = 0
(SPIxCON1[15]).
During the Underrun condition, the SPI module loads the SPIxTXSR with the data in the
SPIxURDT register when the URDTEN bit is set to ‘1
’. If URDTEN is not
set to ‘1
’, then the last received data during underrun is loaded to
SPIxTXSR. The module samples the Underrun condition on channel boundaries, so
transmission of SPIxURDT data can start with either the left or right audio channel.
When the condition clears (i.e., SPIxTXB is not empty), the logic loads audio data from the transmit buffer into the SPIxTXSR on the next LRC frame boundary. Because recovery from the Underrun condition occurs on the LRC frame boundary (i.e., at the end of a full left and right channel pair), software must ensure the left and right audio data is always transferred to the FIFO in pairs.
The Ignore Receive Overflow (IGNROV) bit (SPIxCON1[29]), when set to a
‘1
’, ignores a Receive Overflow condition. This is useful when
there is a general performance problem in the system that software must handle. An
alternate method to handle the Receive Overflow is by setting the DISSDI bit =
1
(SPIxCON1[4]) when the system does not need to receive audio
data. After changing the DISSDI bit on-the-fly, the SPIx Receive Shift register starts a
receive on the leading LRCK edge.
If an RX overflow occurs when IGNROV = 0
, the I2S will behave
just like it would in SPI mode, that is, it will stop writing to the RX FIFO. However,
recovery from overflow is different from SPI mode. When the CPU gets around to reading
the RX FIFO, the I2S will restart receiving into the RX FIFO only when two
additional conditions are met:
- The I2S is on an LRC boundary
- There are a multiple of two locations free in the RX FIFO
These conditions will ensure the received data will start at the beginning of the LEFT channel and there is room to receive the RIGHT channel information immediately following.