22 Data Converter Interface (DCI)
22 Data Converter Interface (DCI)
22 Data Converter Interface (DCI)
HIGHLIGHTS
This section of the manual contains the following topics:
22
22.1 Introduction .................................................................................................................. 22-2
Data Converter
Interface (DCI)
22.2 Control Register Descriptions ...................................................................................... 22-2
22.3 Codec Interface Basics and Terminology..................................................................... 22-8
22.4 DCI Operation ............................................................................................................ 22-10
22.5 Using the DCI Module................................................................................................ 22-17
22.6 Operation in Power Saving Modes ............................................................................ 22-28
22.7 Registers Associated with DCI................................................................................... 22-28
22.8 Design Tips ................................................................................................................ 22-30
22.9 Related Application Notes.......................................................................................... 22-31
22.10 Revision History ......................................................................................................... 22-32
22.1 Introduction
The dsPIC Data Converter Interface (DCI) module allows simple interfacing of devices, such as
audio coder/decoders (codecs), A/D converters, and D/A converters.
The following interfaces are supported:
• Framed Synchronous Serial Transfer (Single or Multi-Channel)
• Inter-IC Sound (I2S) Interface
• AC-Link Compliant mode
Many codecs intended for use in audio applications support sampling rates between 8 kHz and
48 kHz and use one of the interface protocols listed above. The DCI automatically handles the
interface timing associated with these codecs. No overhead from the CPU is required until the
requested amount of data has been transmitted and/or received by the DCI. Up to four data
words may be transferred between CPU interrupts.
The data word length for the DCI is programmable up to 16 bits to match the data size of the
dsPIC30F CPU. However, many codecs have data word sizes greater than 16 bits. Long data
word lengths can be supported by the DCI. The DCI is configured to transmit/receive the long
word in multiple 16-bit time slots. This operation is transparent to the user and the long data word
is stored in consecutive register locations.
The DCI can support up to 16 time slots in a data frame, for a maximum frame size of 256 bits.
There are control bits for each time slot in the data frame that determine whether the DCI will
transmit/receive during the time slot.
22.2 Control Register Descriptions
The DCI has five Control registers and one Status register, which are listed below:
• DCICON1: DCI module enable and mode bits.
• DCICON2: DCI module word length, data frame length, and buffer setup.
• DCICON3: DCI module bit clock generator setup.
• DCISTAT: DCI module status information.
• RSCON: Active frame time slot control for data reception.
• TSCON: Active frame time slot control for data transmit.
In addition to these Control and Status registers, there are four Transmit registers,
TXBUF0....TXBUF3, and four Receive registers, RXBUF0....RXBUF3.
Lower Byte:
R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 R/W-0 R/W-0
UNFM CSDOM DJST — — — COFSM<1:0>
bit 7 bit 0
22
bit 15 DCIEN: DCI Module Enable bit
Data Converter
Interface (DCI)
1 = Module is enabled
0 = Module is disabled
bit 14 Reserved: Read as ‘0’
bit 13 DCISIDL: DCI Stop in Idle Control bit
1 = Module will halt in CPU Idle mode
0 = Module will continue to operate in CPU Idle mode
bit 12 Reserved: Read as ‘0’
bit 11 DLOOP: Digital Loopback Mode Control bit
1 = Digital Loopback mode is enabled. CSDI and CSDO pins internally connected.
0 = Digital Loopback mode is disabled
bit 10 CSCKD: Sample Clock Direction Control bit
1 = CSCK pin is an input when DCI module is enabled
0 = CSCK pin is an output when DCI module is enabled
bit 9 CSCKE: Sample Clock Edge Control bit
1 = Data changes on serial clock falling edge, sampled on serial clock rising edge
0 = Data changes on serial clock rising edge, sampled on serial clock falling edge
bit 8 COFSD: Frame Synchronization Direction Control bit
1 = COFS pin is an input when DCI module is enabled
0 = COFS pin is an output when DCI module is enabled
bit 7 UNFM: Underflow Mode bit
1 = Transmit last value written to the Transmit registers on a transmit underflow
0 = Transmit ‘0’s on a transmit underflow
bit 6 CSDOM: Serial Data Output Mode bit
1 = CSDO pin will be tri-stated during disabled transmit time slots
0 = CSDO pin drives ‘0’s during disabled transmit time slots
bit 5 DJST: DCI Data Justification Control bit
1 = Data transmission/reception is begun during the same serial clock cycle as the frame synchronization
pulse
0 = Data transmission/reception is begun one serial clock cycle after frame synchronization pulse
bit 4-2 Reserved: Read as ‘0’
bit 1-0 COFSM<1:0>: Frame Sync Mode bits
11 = 20-bit AC-Link mode
10 = 16-bit AC-Link mode
01 = I2S Frame Sync mode
00 = Multi-Channel Frame Sync mode
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
COFSG<2:0> — WS<3:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
BCG<7:0>
bit 7 bit 0
22
bit 15-12 Reserved: Read as ‘0’.
Data Converter
Interface (DCI)
bit 11-0 BCG<11:0>: DCI Bit Clock Generator Control bits
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 R-0 R-0 R-0 R-0
— — — — ROV RFUL TUNF TMPTY
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
RSE7 RSE6 RSE5 RSE4 RSE3 RSE2 RSE1 RSE0
bit 7 bit 0
22
bit 11 RSE<15:0>: Receive Slot Enable bits
Data Converter
Interface (DCI)
1 = CSDI data is received during the individual time slot n
0 = CSDI data is ignored during the individual time slot n
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
TSE7 TSE6 TSE5 TSE4 TSE3 TSE2 TSE1 TSE0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: The details given in this section are not specific to the DCI module. This discussion
is intended to provide the user some background and terminology related to the
digital serial interface protocols found in most codec devices.
CSCK SCK
dsPIC® COFS FS
(See Note)
Codec
(Controller) CSDO SDI
CSDI SDO
CSCK SCK
dsPIC®
FS
(Controller) COFS A/D #1
CSDI SDO
FSO
SCK
FS
Daisy-Chained Configuration A/D #2
SDO
to Other Devices FSO
Controller
CSCK SCK
® COFS FS
dsPIC
Codec
(Controller) CSDO SDI
CSDI SDO
All interfaces have a serial transfer clock, SCK. The SCK signal may be generated by any of the
connected devices or can be provided externally. In some systems, SCK is also referred to as
the bit clock. For codecs that offer high signal fidelity, it is common for the SCK signal to be
derived from the crystal oscillator on the codec device. The protocol defines the edge of SCK on
which data is sampled. The master device generates the FS signal with respect to SCK.
The period of the FS signal delineates one data frame. This period is the same as the data
sample period. The number of SCK cycles that occur during the data frame will depend on the
type of codec that is selected. The ratio of the SCK frequency to the system sample rate is
expressed as a ratio of n, where n is the number of SCK periods per data frame.
One advantage of using a framed interface protocol is that multiple data words can be transferred
during each sample period, or data frame. Each division of the data frame is referred to as a time
slot. The time slots can be used for multiple codec data channels and/or control information. 22
Furthermore, multiple devices can be multiplexed on the same serial data pins. Each slave
device is programmed to place its data on the serial data connection during the proper time slot.
Data Converter
Interface (DCI)
The output of each slave device is tri-stated at all other times to permit other devices to use the
serial bus.
Some devices allow the FS signal to be daisy-chained via Frame Synchronization Output (FSO)
pins. A typical daisy-chained configuration is shown in Figure 22-1. When the transfer from the
first slave device has completed, a FS pulse is sent to the second device in the chain via its FSO
pin. This process continues until the last device in the chain has sent its data. The controller
(master) device should be programmed for a data frame size that accommodates all of the data
words that will be transferred.
The timing for a typical data transfer is shown in Figure 22-2. Most protocols begin the data
transfer one SCK cycle after the FS signal is detected. This example uses a 16 fs clock and
transfers four 4-bit data words per frame.
SCK
FS
SDI or SDO Time Slot 0 Time Slot 1 Time Slot 2 Time Slot 3
The timing for a typical data transfer with daisy-chained devices is shown in Figure 22-3. This
example uses a 16 fs SCK frequency and transfers two 8-bit data words per frame. After the FS
pulse is detected, the first device in the chain transfers the first 8-bit data word and generates the
FSO signal at the end of the transfer. The FSO signal begins the transfer of the second data word
from the second device in the chain.
SCK
FS
FSO
The FS pulse has a minimum active time of one SCK period so the slave device can detect the
start of the data frame. The duty cycle of the FS pulse may vary depending on the specific pro-
tocol that is used to mark certain boundaries in the data frame. For example, the I2S protocol
uses a FS signal that has a 50% duty cycle. The I2S protocol is optimized for the transfer of two
data channels (left and right channel audio information). The edges of the FS signal mark the
boundaries of the left and right channel data words. The AC-Link protocol uses a FS signal that
is high for 16 SCK periods and low for 240 SCK periods. The edges of the AC-Link FS signal
mark the boundaries of control information and data in the frame.
Note: Refer to Section 26. “Appendix” of this manual for additional information on codec
communication protocols.
BCG<11:0>
CSCKD
COFSD
WS<3:0> Frame
COFSG<3:0> Synchronization COFS
COFSM<1:0> Generator
16-bit Data Bus
Receive Registers w/
Buffer
Buffer Control
15 0
Transmit Registers w/
Buffer DCI Shift Register CSDI
CSDO
The CSCK pin provides the serial clock connection for the DCI. The CSCK pin may be configured
as an input or output using the CSCKD control bit, DCICON1<10>. When the CSCK pin is
configured as an output (CSCKD = 0), the serial clock is derived from the dsPIC30F system clock
source and supplied to external devices by the DCI. When the CSCK pin is configured as an input
(CSCKD = 1), the serial clock must be provided by an external device.
Data Converter
Interface (DCI)
enabled. The CSDO pin drives the serial bus whenever data is to be transmitted. The CSDO pin
can be tri-stated or driven to ‘0’ during serial clock periods when data is not transmitted, depend-
ing on the state of the CSDOM control bit (DCICON1<6>). The tri-state option allows other
devices to be multiplexed onto the CSDO connection.
The serial data input (CSDI) pin is configured as an input only pin when the module is enabled.
The frame synchronization (COFS) pin is used to synchronize data transfers that occur on the
CSDO and CSDI pins. The COFS pin may be configured as an input or an output. The data direc-
tion for the COFS pin is determined by the COFSD control bit (DCICON1<8>). When the COFSD
bit is cleared, the COFS pin is an output. The DCI module will generate frame synchronization
pulses to initiate a data transfer. The DCI is the master device for this configuration. When the
COFSD bit is set, the COFS pin becomes an input. Incoming synchronization signals to the
module will initiate data transfers. The DCI is a slave device when the COFSD control bit is set.
Note: The CSCK I/O pin will be controlled by the DCI module if the DCIEN bit is set OR
the bit clock generator is enabled by writing a non-zero value to BCG<11:0>. This
allows the bit clock generator to be operated independently of the DCI module.
When the CSCK pin is controlled by the DCI module, the corresponding PORT, LAT and TRIS
Control register values for the CSCK pin will be overridden and the data direction for the CSCK
pin will be controlled by the CSCKD control bit (DCICON1<10>).
If the serial clock for the DCI is to be provided by an external device, the BCG<11:0> bits should
be set to ‘0’ and the CSCKD bit set to ‘1’.
If the serial clock is to be generated by the DCI module, the BCG<11:0> control bits should be
set to a non-zero value (see Equation 22-1) and the CSCKD control bit should be set to zero.
The formula for the bit clock frequency is given in Equation 22-1.
Equation 22-1: DCI Bit Clock Generator Value
fCY
BCG<11:0> = –1
2 fCSCK
The required bit clock frequency will be determined by the system sampling rate and frame size.
Typical bit clock frequencies range from 16x to 512x the converter sample rate, depending on
the data converter and the communication protocol that is used.
Note: The BCG<11:0> bits have no effect on the operation of the DCI module when the
CSCK signal is provided externally (CSCKD = 1).
Note: The WS control bits are used only in the multi-channel and I2S modes. These bits
have no effect in AC-Link mode since the data slot sizes are fixed by the protocol.
Frame lengths up to 16 data words may be selected. The frame length in serial clock periods will
vary up to a maximum of 256 depending on the word size that is selected.
22
Data Converter
Note: The COFSG control bits will have no effect in AC-Link mode, since the frame length
Interface (DCI)
is set to 256 serial clock periods by the protocol.
Data values are always stored left-justified in the DCI registers, since audio PCM data is
represented as a signed 2’s complement fractional number. If the programmed DCI word size is
less than 16 bits, the unused LSbs in the Receive registers are set to ‘0’ by the module. Also, the
unused LSbs in the Transmit register are ignored by the module.
The Transmit and Receive registers each have a set of buffers that are not accessible by the
user. Effectively, each transmit and receive buffer location is double-buffered. The DCI transmits
data from the transmit buffers and writes received data to the receive buffers. The buffers allow
the user to read and write the RXBUF and TXBUF registers, while the DCI uses data from the
buffers.
TXBUF1 4 4 Transmit
Buffer
Select
TXBUF2
TXBUF3
BLEN
DCI
Buffer Control Shift Register
RXBUF1 4 4 Receive
Buffer
RXBUF2 Select
RXBUF3
During disabled transmit time slots, the CSDO pin can drive ‘0’s or can be tri-stated, depending
on the state of the CSDOM bit (DCICON1<6>). A given transmit time slot is disabled if its
corresponding TSEx bit is cleared in the TSCON register.
If the CSDOM bit is cleared (default), the CSDO pin will drive ‘0’s onto the CSDO pin during
disabled time slot periods. This mode is used when there are only two devices (1 master and 1
slave) attached to the serial bus.
If the CSDOM bit is set, the CSDO pin will be tri-stated during unused time slot periods. This
mode allows multiple dsPIC30F devices to share the same CSDO line in a multiplexed
application. Each device on the CSDO line is configured so that it will only transmit data during
specific time slots. No two devices should transmit data during the same time slot.
Data Converter
Interface (DCI)
The slot enable bits in the TSCON and RSCON registers function independently, with the
exception of the buffer control logic. For each time slot in a data frame, the buffer location is
advanced if either the TSEx or the RSEx bit is set for the current time slot. That is, the buffer con-
trol unit synchronizes the Transmit and Receive buffering so that the Transmit and Receive buffer
location will always be the same for each time slot in the data frame.
If the TSEx bit and the RSEx bit are both set for every time slot that is used in the data frame,
the DCI will Transmit and Receive equal amounts of data .
In some applications, the number of data words transmitted during a frame may not equal the
number of words received. As an example, assume that the DCI is configured for a 2-word data
frame, TSCON = 0x0001 and RSCON = 0x0003. This configuration would allow the DCI to
transmit one data word per frame and receive two data words per frame. Since two data words
are received for each data word that is transmitted, the user would write every other transmit
buffer location. Specifically, only TXBUF0 and TXBUF2 would be used to transmit data.
Figure 22-6: DCI Buffer Operation: TSCON = 0x0001, RSCON = 0x0003, BLEN<1:0> = 11b
TXBUF1 RXBUF1
Data Word #2
Note: User writes to TXBUF0 and TXBUF2. TXBUF1 and TXBUF3 not used by transmit logic.
22.5.1 How to Transmit and Receive Data Using the DCI Buffers, Status Bits and Interrupts
The DCI can buffer up to four data words between CPU interrupts depending on the setting of
the BLEN control bits. The buffered data can be transmitted and received in a single data frame,
or across multiple data frames, depending on the TSCON and RSCON register settings. For
example, assume BLEN<1:0> = 00b ( buffer one data word per interrupt) and TSCON = RSCON
= 0x0001. This particular configuration represents the most basic setup and would cause the
DCI to transmit/receive one data word at the beginning of every data frame. The CPU would be
interrupted after every data word transmitted/received since BLEN<1:0> = 00b.
For a second configuration example, assume BLEN<1:0> = 11b (buffer four data words per
22
interrupt) and TSCON = RSCON = 0x0001. This configuration would cause the DCI to
Data Converter
Interface (DCI)
transmit/receive one data word at the beginning of every data frame, but a CPU interrupt would
be generated after four data words were transmitted/received. This configuration would be useful
for block processing, where multiple data samples are processed at once.
For a third configuration example, assume BLEN<1:0> = 11b (buffer four data words per
interrupt) and TSCON = RSCON = 0x000F. This configuration would cause the DCI to
transmit/receive four data words at the beginning of every data frame. A CPU interrupt would be
generated every data frame in this case because the DCI was setup to buffer four data words in
a data frame. This configuration represents a typical multi-channel buffering setup.
The DCI can also be configured to buffer more than four data words per frame. For example,
assume BLEN<1:0> = 11b (buffer four data words per interrupt) and TSCON = RSCON =
0x00FF. In this configuration, the DCI will transmit/receive 8 data words per data frame. An
interrupt will be generated twice per data frame. To determine which portion of the data is in the
Transmit/Receive registers at each interrupt, the user will need to check the SLOT status bits
(DCISTAT <11:7>) in the Interrupt Service Routine to determine the current data frame position.
The Transmit and Receive registers are double-buffered, so the DCI module can work on one set
of Transmit and Receive data while the user software is manipulating the other set of data.
Because of the double-buffers, it will take three interrupt periods to receive the data, process that
data, and transmit the processed data. For each DCI interrupt, the CPU will process a data word
that was received during a prior interrupt period and generate a data word that will be transmitted
during the next interrupt period. The buffering and data processing time of the dsPIC device will
insert a two-interrupt period delay into the processed data. This data delay is negligible, in most
cases.
The DCI status flags and CPU interrupt indicate that a buffer transfer has taken place and that it
is time for the CPU to process more data. In a typical application, the following steps will occur
each time the DCI data is processed:
1. The RXBUF registers are read by the user software. The RFUL status bit (DCISTAT<2>)
will have been set by the module to indicate the Receive registers contain new data. The
RFUL bit is cleared automatically after all the active Receive registers have been read.
2. The user software will process the received data.
3. The processed data is written to the TXBUF registers. The TMPTY status bit
(DCISTAT<0>) will have been previously set to indicate that the Transmit registers are
ready for more data to be written.
For applications that are configured to Transmit and Receive data (TSCON and RSCON are
non-zero), the RFUL and TMPTY status bits can be polled in user software to determine when a
DCI buffer transfer takes place. If the DCI is only used to transmit data (RSCON = 0), then the
TMPTY bit can be polled to indicate a buffer transfer. If the DCI is configured to only receive data
(TSCON = 0), then the RFUL bit can be polled to indicate a buffer transfer.
The DCIIF status bit (IFS2<9>) is set each time a DCI buffer transfer takes place and generates
a CPU interrupt, if enabled. The DCIIF status bit is generated by the logical ORing of the RFUL
and TMPTY status bits.
Data transfers are begun by setting the DCIEN control bit (DCICON1<15>). Prior to this, the DCI
Control registers should have been initialized for the desired operating mode. (See Section
22.5.4 “Multi-Channel Operation”, Section 22.5.5 “I2S Operation”, and Section
22.5.6 “AC-Link Operation”)
A timing diagram for DCI startup is shown in Figure 22-7. In this example, the DCI is configured
for an 8-bit data word (WS<3:0> = 0111b) and an 8-bit data frame (COFSG<3:0> = 0000b). The
Multi-Channel mode (COFSM<1:0> = 00b) is used. The steps required to transmit and receive
data are described below.
1. The TXBUF registers should be pre-loaded with the first data to be transmitted before the
module is enabled. If the transmit data will be based on data received from the codec, then
the user can simply clear the TXBUF registers. This will transmit digital ‘silence’ until data
is first received into the RXBUF registers from the codec.
2. Enable the DCI module by setting the DCIEN bit (DCICON1<15>). If the DCI is the master
device, the data in the TXBUF registers will be transferred to the transmit buffers and
transmission of the first data frame will commence. Otherwise, the TXBUF data will be
held in the transmit buffers until a frame sync signal is received from the master device.
3. The TMPTY bit will be set immediately after the module is enabled and a DCI interrupt will
be generated, if enabled. At this time, the module is ready for the TXBUF registers to be
reloaded with data to be transferred on the second data frame. No data has been received
by the module at this time, so the TXBUF registers should be cleared again if the
transmitted data is calculated from the received data. The DCIIF status bit should be
cleared by the user in software if interrupts are enabled.
4. After the first data frame is transferred, the TMPTY bit will set, the RFUL status bit will be
set, and a DCI interrupt will occur, if enabled. This is the first data word received from the
device connected to the DCI.
5. The user reads the Receive register(s), automatically clearing the RFUL status bit. The
user software processes the received data at this time.
6. The Transmit register(s) is written with data to be transmitted during the next data frame.
The TMPTY status bit is cleared automatically when the write occurs. The write data may
be calculated from data that was received at the prior interrupt.
7. The next DCI interrupt occurs and the cycle repeats.
CSCK
Data 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6
Word 1 Word 2
COFS
DCIEN
TMPTY
RFUL
RXBUF RX Word 1
1 2 3 4 5 6 7
The DCI module is disabled by clearing the DCIEN control bit (DCICON1<15>). When the DCIEN
bit is cleared, the module will finish the current data frame transfer that is in progress. An interrupt
will be generated if the transmit/receive buffers need to be written/read before the end of the
frame.
The DCIEN bit must be cleared at least 3 CSCK cycles before the end of the frame disables the
module at that frame. If not, the module will disable on the next frame.
The DCI will not generate any further frame sync pulses after the DCIEN bit is cleared, nor will it
respond to an incoming frame sync pulse.
When the frame sync generator has reached the final time slot in the data frame, all state
machines associated with the DCI will be reset to their Idle state and control of the I/O pins asso- 22
ciated with the module will be released. The user may poll the SLOT<3:0> status bits
Data Converter
(DCISTAT<11:7>) after the DCIEN bit is cleared to determine when the module is Idle. The DCI
Interface (DCI)
is Idle when SLOT<3:0> = 0000b and DCIEN = 0.
When the module enters the Idle state, any data in the Receive Shadow registers will be
transferred to the RXBUF registers, and the RFUL and ROV status bits will be affected
accordingly.
FS pulse not
WS = 0011b COFSG = 0011b generated.
CSCK
Data 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
COFS
DCIEN
RFUL
Transmit Registers
TXBUF2
Data Converter
Interface (DCI)
CSCK
COFS
The steps required to configure the DCI for a codec using the Multi-Channel mode are provided
in this section. This Operating mode can be used for codecs with one or more data channels.
The setup is similar regardless of the number of channels.
For this setup example, a hypothetical codec will be considered. The single channel codec used
for this setup example will use a 256 fs serial clock frequency with a 16-bit data word transmitted
at the beginning of each frame.
The steps required for setup and operation are described below.
1. Determine the sample rate and data word size required by the codec. An 8 kHz sampling
rate is assumed for this example.
2. Determine the serial transfer clock frequency required by the codec. Most codecs require
a serial clock signal that is some multiple of the sampling frequency. The example codec
requires a frequency that is 256 fs, or 1.024 MHz. Therefore, a frame sync pulse must be
generated every 256 serial clock cycles to start a data transfer.
3. The DCI must be configured for the serial transfer clock. If the CSCK signal will be
generated by the DCI, clear the CSCKD control bit (DCICON1<10>) and write a value to
DCICON3 that will produce the correct clock frequency (See Section 22.4.3 “Bit Clock
Generator”). If the CSCK signal is generated by the codec or other external source, set
the CSCKD control bit and clear the DCICON3 register.
4. Clear the COFSM<1:0> control bits (DCICON1<1:0>) to set the frame synchronization
signal to Multi-Channel mode.
5. If the DCI will generate the frame sync signal (master), then clear the COFSD control bit
(DCICON1<8>). If the DCI will receive the frame sync signal (slave), then set the COFSD
control bit.
6. Clear the CSCKE control bit (DCICON1<9>) to sample incoming data on the falling edge
of CSCK. This is the typical configuration for most codecs. Refer to the codec data sheet
to ensure the correct sampling edge is used.
7. Write the WS<3:0> control bits (DCICON2<3:0>) for the desired data word size. The
example codec requires WS<3:0> = 1111b for a 16-bit data word size.
8. Write the COFSG<3:0> control bits (DCICON2<8:5>) for the desired number of data
words per frame. The WS and COFSG control bits will determine the length of the data
frame in CSCK cycles (see Section 22.4.7 “Frame Synchronization Generator”)
COFSG<3:0> = 1111b is used for this codec to provide the 256-bit data frame required
by the example codec.
9. Set the Output mode for the CSDO pin using the CSDOM control bit (DCICON1<6>). If a
single device is attached to the DCI, CSDOM can be cleared. This will force the CSDO pin
to ‘0’ during unused data time slots. You may need to set CSDOM if multiple devices are
attached to the CSDO pin.
10. Write the TSCON and RSCON registers to determine which data time slots in the frame
are to be transmitted and received, respectively. For this single channel codec, use
TSCON = RSCON = 0x0001 to enable transmission and reception during the first 16-bit
time slot of the data frame.
11. Set the BLEN control bits (DCICON2<11:10>) to buffer the desired amount of data words.
For the single channel codec, BLEN = 00 will provide an interrupt at each data frame. A
higher value of BLEN could be used for this codec to buffer multiple samples between
interrupts.
12. If interrupts are to be used, clear the DCIIF status bit (IFS2<9>) and set the DCIIE control
bit (IEC2<9>).
13. Begin operation as described in Section 22.5.1.1 “DCI Start-up and Data Buffering”.
CSCK
COFS
Note: A 5-bit transfer is shown here for illustration purposes. The I2S protocol does not specify
word length, this will be system dependent.
The DCI module is configured for I2S mode by writing a value of 01h to the COFSM<1:0> control
bits in the DCICON1 SFR. When operating in the I2S mode, the DCI module will generate frame
synchronization signals with a 50% duty cycle. Each edge of the frame synchronization signal
marks the boundary of a new data word transfer. Refer to the Appendix of this manual for more
information about the I2S protocol. The user must also select the frame length and data word size
using the COFSG and WS control bits in the DCICON2 SFR.
Data Converter
3. The DCI must be configured for the serial transfer clock. If the CSCK signal will be gener-
Interface (DCI)
ated by the DCI, clear the CSCKD control bit (DCICON1<10>) and write a value to
DCICON3 that will produce the correct clock frequency (see Section 22.4.3 “Bit Clock
Generator”). If the CSCK signal is generated by the codec or other external source, set
the CSCKD control bit and clear the DCICON3 register.
4. Next, set COFSM<1:0> = 01b to set the frame synchronization signal to I2S mode.
5. If the DCI will generate the frame sync signal (master), then clear the COFSD control bit
(DCICON1<8>). If the DCI will receive the frame sync signal (slave), then set the COFSD
control bit.
6. Set the CSCKE control bit (DCICON1<9>) to sample incoming data on the rising edge of
CSCK. This is the typical configuration for most I2S codecs.
7. Write the WS<3:0> control bits (DCICON2<3:0>) for the desired data word size. For the
example codec, use WS<3:0> = 1111b for a 16-bit data word size.
8. Write the COFSG<3:0> control bits (DCICON2<8:5) for the desired number of data words
per frame. The WS and COFSG control bits will determine the length of the data frame in
CSCK cycles (see Section 22.4.7 “Frame Synchronization Generator”). For this exam-
ple codec, set COFSG<3:0> = 0001b.
Note: In the I2S mode, the COFSG bits are set to the length of 1/2 of the data frame. For
this example codec, set COFSG<3:0> = 0001b (two data words per frame) to
produce a 32-bit frame. This will produce an I2S data frame that is 64 bits in length.
9. Set the Output mode for the CSDO pin using the CSDOM control bit (DCICON1<6>). If a
single device is attached to the DCI, CSDOM can be cleared. You may need to set
CSDOM if multiple devices are attached to the CSDO pin.
10. Write the TSCON and RSCON registers to determine which data time slots in the frame
are to be transmitted and received, respectively. For this codec, set TSCON = 0x0001
and RSCON = 0x0001 to enable transmission and reception during the first 16-bit time
slot of the 32-bit data frame. Adjacent time slots can be enabled to buffer data words
longer than 16 bits.
11. Set the BLEN<1:0> control bits (DCICON2<11:10>) to buffer the desired amount of data
words. For a two-channel I2S codec, BLEN<1:0> = 01b will generate an interrupt after
transferring two data words.
12. If interrupts are to be used, clear the DCIIF status bit (IFS2<9>) and set the DCIIE control
bit (IEC2<9>).
13. Begin operation as described in Section 22.5.1.1 “DCI Start-up and Data Buffering”. In
the I2S Master mode, the COFS pin will be driven high after the module is enabled and
begin transmitting the data loaded in TXBUF0.
Most I2S codecs support two channels of data and the level of the frame sync signal indicates
the channel that is transferred during that half of the data frame. The COFS pin can be polled in
software using its associated Port register to determine the present level on the pin in the DCI
Interrupt Service Routine. This will indicate which data is in the Receive register and which data
should be written to the Transmit registers for transfer on the next frame.
As per the I2S specification, a data word transfer will by default begin one serial clock cycle
following a transition of the frame sync signal. An ‘MSb left-justified’ option can be selected using
the DJST control bit (DCICON1<5>).
If DJST = 1, the I2S data transfers will be MSb left justified. The MSb of the data word will be
presented on the CSDO pin during the same serial clock cycle as the rising or falling edge of the
FS signal. After the data word has been transmitted, the state of the CSDO pin is dictated by the
CSDOM (DCICON1<6>) bit.
The left-justified data option allows two stereo codecs to be connected to the same serial bus.
Many I2S compatible devices have configuration options for left-justified or right-justified data.
The word size selection bits are set to twice the codec word length and data is read/written to the
DCI memory in a packed format. The connection details for a dual I2S codec system are shown
in Figure 22-12.
Timing diagrams for I2S mode are shown in Figure 22-13. For reference, these diagrams assume
an 8-bit word size (WS<3:0> = 0111b). Two data words per frame would be required to achieve
a 16-bit sub-frame (COFSG<3:0> = 0001b). The 3rd timing diagram in Figure 22-13 uses packed
data to read/write from two codecs. For this example, the DCI module is configured for a 16-bit
data word (WS<3:0> = 1111b). Two packed 8-bit words are written to each 16-bit location in the
DCI memory buffer.
Codec #1
®
SCK SCK
dsPIC
Device FS WS
SDO SDI
I2C™/SPI™
Codec #2
SCK
WS
SDI
I2C™/SPI™
CSCK
Data 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
Data Converter
Interface (DCI)
CSCK
Data 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
CSCK
COFS Channel #1 Transfer, Word 1 Channel #1 Transfer, Word 2 Channel #2 Transfer, Word 1 Channel #2 Transfer, Word 2
Data 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
The AC-Link data frame is 256 bits subdivided into one 16-bit control slot, followed by twelve
20-bit data slots. The AC-’97 codec usually provides the serial transfer clock signal which is
derived from a crystal oscillator as shown in Figure 22-14. The controller receives the serial clock
and generates the frame sync signal. The default data frame rate is 48 kHz. The frame sync
signal used for AC-Link systems is high for 16 CSCK periods at the beginning of the data frame
and low for 240 CSCK periods. The data transfer begins one CSCK period after the rising edge
of the frame sync signal as shown in Figure 22-16. Data is sampled by the receiving device on
the falling edge of CSCK. The control and data time slots in the AC-Link have defined uses in the
protocol as shown in Figure 22-15. Refer to the Appendix of this manual or the Intel® AC ‘97
Codec Specification, Rev 2.2 for a complete definition of the AC-Link protocol.
BIT_CLK
CSCK
24.576
SYNC MHz
COFS
dsPIC® SDATA_OUT
(AC ‘97 CSDO AC ‘97
Controller) Codec
SDATA_IN
CSDI
/RESET
I/O
256
16 20 20 20 20 20 20 20
SYNC
CSCK
COFS
The DCI module has two Operating modes for the AC-Link protocol to accommodate the 20-bit
data time slots. These Operating modes are selected by the COFSM<1:0> control bits
(DCICON1<1:0>). The first AC-Link mode is called ‘16-bit AC-Link mode’ and is selected by
setting COFSM<1:0> = 10b. The second AC-Link mode is called ‘20-bit AC-Link mode’ and is
selected by setting COFSM<1:0> = 11b.
In the 16-bit AC-Link mode, transmit and receive data word lengths are restricted to 16 bits to fit
the DCI Transmit and Receive registers. Note that this restriction only affects the 20-bit data time
slots of the AC-Link protocol. For received time slots, the incoming data will be truncated to 16
bits. For outgoing time slots, the 4 LSbs of the data word are set to ‘0’ by the module. This
Operating mode simplifies the AC-Link data frame by treating every time slot as a 16-bit time slot.
The frame sync generator maintains alignment to the time slot boundaries.
The 20-bit AC-Link mode allows all bits in the data time slots to be transmitted and received, but
does not maintain data alignment to the specific time slot boundaries defined in the AC-Link
protocol.
22
The 20-bit AC-Link mode functions similarly to the Multi-Channel mode of the DCI module,
Data Converter
Interface (DCI)
except for the duty cycle of the frame synchronization signal that is produced. The AC-Link frame
synchronization signal should remain high for 16 clock cycles and should be low for the following
240 cycles.
The 20-bit mode treats each 256-bit AC-Link frame as sixteen 16-bit time slots. In the 20-bit
AC-Link mode, the module operates as if COFSG<3:0> = 1111b and WS<3:0> = 1111b. The
data alignment for 20-bit data slots is not maintained in this Operating mode. For example, an
entire 256-bit AC-Link data frame can be transmitted and received in a packed fashion by setting
all bits in the TSCON and RSCON registers. Since the total available buffer length is 64 bits, it
would take 4 consecutive interrupts to transfer the AC-Link frame. The application software must
keep track of the current AC-Link frame segment by monitoring the SLOT<3:0> status bits
(DCISTAT<11:7>).
The module is enabled for AC-Link mode by writing 10h or 11h to the COFSM<1:0> control bits
in the DCICON1 SFR. The word size selection bits (WS<3:0>) and the frame synchronization
generator bits (COFSG<3:0>) have no effect for the 16 and 20-bit AC-Link modes since the
frame and word sizes are set by the protocol.
Most AC ‘97 codecs generate the clock signal that controls data transfers. Therefore, the CSCKD
control bit is set in software. The COFSD control bit is cleared because the DCI will generate the
FS signal from the incoming clock signal. The CSCKE bit is cleared so that data is sampled on
the rising edge.
The user must decide which time slots in the AC-Link data frame are to be buffered and set the
TSE and RSE control bits accordingly. At a minimum, it will be necessary to buffer the transmit
and receive TAG slots, so the TSCON<0> and RSCON<1> control bits should be set in software.
Note: Only the TSCON<12:0> control bits and the RSCON<12:0> control bits will have an
effect in the 16-bit AC-Link mode, since an AC-Link frame has 13 time slots.
1. The DCI must be configured to accept the serial transfer clock from the AC ’97 codec. Set
the CSCKD control bit and clear the DCICON3 register.
2. Next, set the COFSM<1:0> control bits (DCICON1<1:0>) to 10b or 11b to set the desired
AC-Link Frame Synchronization mode.
3. Clear the COFSD control bit (DCICON1<8>), so the DCI will output the frame sync signal.
4. Clear the CSCKE control bit (DCICON1<9>) to sample incoming data on the falling edge
of CSCK.
Note: The word size selection bits (WS<3:0>) and the frame synchronization generator
bits (COFSG<3:0>) have no effect for the 16- and 20-bit AC-Link modes, since the
frame and word sizes are set by the protocol.
DS70069C-page 22-29
Interface (DCI)
22
Data Converter
dsPIC30F Family Reference Manual
Question 1: Can the DCI support data word lengths greater than 16-bits?
Answer: Yes. A long data word can be transmitted and received using multiple Transmit and
Receive registers. See Section 22.5.3 “Data Packing for Long Data Word Support” for
details.
Note: Please visit the Microchip web site (www.microchip.com) for additional Application 22
Notes and code examples for the dsPIC30F Family of devices.
Data Converter
Interface (DCI)