50.5.12 Audio Protocol Operation
The register SPIxCTRL_* contains the audio specific protocol control bits. When AUDEN = 1 the macro operates like an audio CODEC host or client. The audio protocol requires certain features of the SPI protocol and therefore overrides some SPI settings.
The macro uses the serial audio protocol defined by AUDMOD, AUDWD_MODE, and AUDFMT. In each of the modes the serial clock is free running and audio data is always transferred.
Four pins make up the serial interface. However, each audio connection is only half-duplex so SDO exists only on the transmit side and SDI exists only on the receive side of the interface. The four pins are:
- SDI: Serial Data Input
- SDO: Serial Data Output
- SCK: Serial Clock
- LRC: Left/Right Clock (on SS/FSYNC)
Some codecs refer to Serial Clock (SCK) as Baud/Bit Clock (BCLK). Also, the Left/Right Clock is commonly referred to as LRC or LRCK. The I2S (and other audio) protocol refers to LRC as Word Select (WS). This section refers to signal on SS/FSYNC as LRC (to be consistent with CODEC naming conventions).
An Audio Protocol data transfer takes place between two devices. Usually one device is the host and the other is the client. However, audio data can be transferred between two clients. Because the audio protocols require free running clocks the Host can be a third party controller. In either case the Host generates two free running clocks: SCK and LRC. The (clock) host must generate LRC and SCK continuously, regardless of the availability of transmit data.
Host mode for Audio is enabled by setting the SPIxCTRL_*.MSTEN bit. The clocks (SCK and LRC) continue to generate pulses as long as SPIxCTRL_*.ENABLE = 1 and AUDEN = 1. In other words, the host controls the rate at which the data bits get transmitted. So, SCK is clock output in Host mode while in Client mode, it is clock input.
Most codecs require a host clock, usually called MCLK. MCLK provides a higher speed clock that has a timing relationship to the Sample Frequency (fs) and therefore SCK and LRC. Codecs that require an MCLK are almost always the host device. Many codecs are capable of generating their own MCLK from a crystal. Using an audio crystal with the CODEC provides accurate audio sample rates.
Certain codecs that require MCLK but without a crystal oscillator may still be usable. In this case codecs that support USB frequencies for MCLK (i.e., 12MHz) work best (because of their supported divider ratios). Also, the micro-controller that uses this macro must have a Clock Out feature for the USB clock. Using a USB frequency for MCLK does not provide 100% accurate audio sample rates for all audio frequencies.