Section 20. Data Converter Interface (DCI) - dsPIC33F FRM

Section 20. Data Converter Interface (DCI)
HIGHLIGHTS
This section of the manual contains the following topics:
20.1 Introduction .................................................................................................................. 20-2
20.2 Control Register Descriptions ...................................................................................... 20-2
20.3 Codec Interface Basics and Terminology..................................................................... 20-8
20.4 DCI Operation ............................................................................................................ 20-11
20.5 Using the DCI Module................................................................................................ 20-27
20.6 DCI Configuration Code Example.............................................................................. 20-41
20.7 Data Transfer to DCI Module Buffers Using DMA...................................................... 20-43
20.8 Operation in Power-Saving Modes ............................................................................ 20-46
20.9 Registers Associated with DCI................................................................................... 20-47
20.10 Related Application Notes.......................................................................................... 20-48
20.11 Revision History ......................................................................................................... 20-49
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-1
dsPIC33F/PIC24H Family Reference Manual
Note:
This family reference manual section is meant to serve as a complement to device
data sheets. Depending on the device variant, this manual section may not apply to
all dsPIC33F/PIC24H devices.
Please consult the note at the beginning of the “Data Converter Interface (DCI)”
chapter in the current device data sheet to check whether this document supports
the device you are using.
Device data sheets and family reference manual sections are available for
download from the Microchip Worldwide Web site at: http://www.microchip.com
20.1
INTRODUCTION
The Data Converter Interface (DCI) module allows simple interfacing between dsPIC33F devices
and audio devices, such as audio coder/decoders (codecs), Analog-to-Digital Converters (ADC),
and Digital-to-Analog Converters (DAC).
Note:
The Data Converter Interface (DCI) module is not available in PIC24H devices.
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 module.
The data word length for the DCI is programmable up to 16 bits to match the data size of the
audio application. However, many codecs have data word sizes greater than 16 bits. The DCI
can support long data word lengths. The DCI is configured to transmit or receive the long word
in multiple 16-bit time slots. This operation is transparent to the user application. 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.
Control bits for each time slot in the data frame determine whether the DCI transmits or receives
during the time slot.
The dsPIC33F/PIC24H DMA module allows for direct transfer of data between the dual port
SRAM and DCI transmit and receive registers.
20.2
CONTROL REGISTER DESCRIPTIONS
The DCI has five Control registers and one Status register:
• DCICON1: Data Converter Interface Module Control Register 1
This register controls the DCI module enable and mode bits.
• DCICON2: Data Converter Interface Module Control Register 2
This register controls the DCI module word length, data frame length and buffer setup.
• DCICON3: Data Converter Interface Module Control Register 3
This register controls the DCI module bit clock generator setup.
• DCISTAT: Data Converter Interface Module Status Register
This register provides the DCI module status information.
• RSCON: Receive Slot Enable Register
This register enables the active frame time slot control for data reception.
• TSCON: Transmit Slot Enable Register
This register enables the active frame time slot control for data transmission.
In addition to these Control and Status registers, there are four transmit registers, TXBUF0
through TXBUF3, and four receive registers, RXBUF0 through RXBUF3.
DS70288C-page 20-2
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Register 20-1:
DCICON1: Data Converter Interface Module Control Register 1
R/W-0
U-0
R/W-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
DCIEN
—
DCISIDL
—
DLOOP
CSCKD
CSCKE
COFSD
bit 15
bit 8
R/W-0
R/W-0
R/W-0
U-0
U-0
U-0
UNFM
CSDOM
DJST
—
—
—
R/W-0
R/W-0
COFSM<1: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
bit 15
DCIEN: DCI Module Enable bit
1 = Module is enabled
0 = Module is disabled
bit 14
Unimplemented: Read as ‘0’
bit 13
DCISIDL: DCI Stop in Idle Control bit
1 = Module halts in CPU Idle mode
0 = Module continues to operate in CPU Idle mode
bit 12
Unimplemented: 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 is 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 begins during the same serial clock cycle as the frame
synchronization pulse
0 = Data transmission/reception begins one serial clock cycle after frame synchronization pulse
bit 4-2
Unimplemented: 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
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
20
DS70288C-page 20-3
dsPIC33F/PIC24H Family Reference Manual
Register 20-2:
DCICON2: Data Converter Interface Module Control Register 2
U-0
U-0
U-0
U-0
—
—
—
—
R/W-0
R/W-0
U-0
R/W-0
—
COFSG3
BLEN<1:0>
bit 15
bit 8
R/W-0
R/W-0
R/W-0
U-0
R/W-0
—
COFSG<2:0>
R/W-0
R/W-0
R/W-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
bit 15-12
Unimplemented: Read as ‘0’
bit 11-10
BLEN<1:0>: Buffer Length control bits
11 = Four data words are buffered between interrupts
10 = Three data words are buffered between interrupts
01 = Two data words are buffered between interrupts
00 = One data word is buffered between interrupts
bit 9
Reserved: Read as ‘0’
bit 8-5
COFSG<3:0>: Frame Sync Generator control bits
1111 = Data frame has 16 words
•
•
•
0010 = Data frame has 3 words
0001 = Data frame has 2 words
0000 = Data frame has 1 word
bit 4
Unimplemented: Read as ‘0’
bit 3-0
WS<3:0>: DCI Data Word Size bits
1111 = Data word size is 16 bits
•
•
•
0100 = Data word size is 5 bits
0011 = Data word size is 4 bits
0010 = Invalid Selection. Do not use, unexpected results may occur
0001 = Invalid Selection. Do not use, unexpected results may occur
0000 = Invalid Selection. Do not use, unexpected results may occur
DS70288C-page 20-4
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Register 20-3:
DCICON3: Data Converter Interface Module Control Register 3
U-0
U-0
U-0
U-0
—
—
—
—
R/W-0
R/W-0
R/W-0
R/W-0
BCG<11:8>
bit 15
bit 8
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
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
bit 15-12
Unimplemented: Read as ‘0’
bit 11-0
BCG<11:0>: DCI Bit Clock Generator Control bits
x = Bit is unknown
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-5
dsPIC33F/PIC24H Family Reference Manual
Register 20-4:
DCISTAT: Data Converter Interface Module Status Register
U-0
U-0
U-0
U-0
—
—
—
—
R-0
R-0
R-0
R-0
SLOT<3:0>
bit 15
bit 8
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
bit 15-12
Unimplemented: Read as ‘0’
bit 11-8
SLOT<3:0>: DCI Slot Status bits
1111 = Slot 15 is currently active
•
•
•
0010 = Slot 2 is currently active
0001 = Slot 1 is currently active
0000 = Slot 0 is currently active
bit 7-4
Unimplemented: Read as ‘0’
bit 3
ROV: Receive Overflow Status bit
1 = A receive overflow has occurred for at least one receive register
0 = A receive overflow has not occurred
bit 2
RFUL: Receive Buffer Full Status bit
1 = New data is available in the receive registers
0 = The receive registers have old data
bit 1
TUNF: Transmit Buffer Underflow Status bit
1 = A transmit underflow has occurred for at least one transmit register
0 = A transmit underflow has not occurred
bit 0
TMPTY: Transmit Buffer Empty Status bit
1 = The transmit registers are empty
0 = The transmit registers are not empty
DS70288C-page 20-6
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Register 20-5:
RSCON: Receive Slot Enable Register
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
RSE15
RSE14
RSE13
RSE12
RSE11
RSE10
RSE9
RSE8
bit 15
bit 8
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
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
bit 15-0
x = Bit is unknown
RSE15:RSE0: Receive Slot Enable bits
1 = CSDI data is received during the individual time slot n
0 = CSDI data is ignored during the individual time slot n
Register 20-6:
TSCON: Transmit Slot Enable Register
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
TSE15
TSE14
TSE13
TSE12
TSE11
TSE10
TSE9
TSE8
bit 15
bit 8
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
bit 15-0
x = Bit is unknown
TSE15:TSE0: Transmit Slot Enable Control bits
1 = Transmit buffer contents are sent during the individual time slot n
0 = CSDO pin is tri-stated or driven to logic ‘0’, during the individual time slot, depending on the state
of the CSDOM bit
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-7
dsPIC33F/PIC24H Family Reference Manual
20.3
CODEC INTERFACE BASICS AND TERMINOLOGY
At a minimum, every codec application has a controller and a codec device. The interface
protocols supported by the DCI require the use of a Frame Synchronization (FS) signal (COFS
on dsPIC33F/PIC24H devices) to initiate a data transfer between the two devices. In most cases,
the rising edge of FS starts a new data transfer. Either device can produce FS. The device that
generates FS is the master device. Conceptually, the master device is not required to be the
transmitting or receiving device.
Figure 20-1 shows codec connection examples. The frequency of the FS signal is usually the
system sampling rate, fs.
Note:
Figure 20-1:
The details given in this section are not specific to the DCI module. This discussion
provides some background and terminology related to the digital serial interface
protocols found in most of the codec devices.
Codec Connection Example
CSCK
CSCK
SCK
CO
dsPIC33F/
PIC24H
Codec
CSDO
SDI
CSDI
SDO
Codec
dsPIC33F/
CSDO
PIC24H
SDI
CSDI
Controller is Master
SDO
Codec is Master
SCK
CSCK
CO
dsPIC33F/
PIC24H
SCK
CO
Codec
CSDO
SDI
CSDI
SDO
(See Note)
Codec Generates SCK
SCK
CSCK
dsPIC33F/
PIC24H
CO
Codec
SDO
CSDI
O
SCK
Codec
Daisy-Chained Configuration
SDO
To Other Devices
O
Controller
CSCK
SCK
CO
dsPIC33F/
PIC24H
Codec
CSDO
SDI
CSDI
SDO
External Controller is Master
Note: Codec oscillator circuit generates the SCK signal.
DS70288C-page 20-8
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.3.1
Serial Transfer Clock
All interfaces have a serial transfer clock, SCK (CSCK pin on dsPIC33F/PIC24H devices). The
SCK signal can 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 from 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 depends on the type
of codec 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.
20.3.2
Data Transfer and Time Slots
Data is transferred via the Serial Data Out (SDO) and Serial Data Input (SDI) signals (the CSDO
and CSDI pins on dsPIC33F/PIC24H devices). One advantage of using a framed interface
protocol is that multiple data words can be transferred during each sample period, or data frame.
For example, consider a 16-bit codec with four input channels. The codec would need to transmit
four 16-bit words within one FS period. This results in 64 SCK cycles per FS period and n = 64.
Time slots can be used for multiple codec data channels or control information. 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. 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. Figure 20-1 shows a typical daisy-chained configuration. When the transfer from the first
slave device is complete, 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 sends data. The controller (master)
device should be programmed for a data frame size that accommodates the largest of the data
words to be transferred.
20.3.2.1
DATA TRANSFER TIMING
Figure 20-2 shows the timing for a typical data transfer. Most protocols begin the data transfer
one SCK cycle after the FS signal is detected. This example uses a 16-fs clock (fs is the sampling
frequency) and transfers four 4-bit data words per frame.
Figure 20-2:
Framed Data Transfer Example
Data Frame Period (1/)
CSCK
CO
CSDI or CSDO
Time Slot 0
Time Slot 1
Time Slot 2
Time Slot 3
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-9
dsPIC33F/PIC24H Family Reference Manual
Figure 20-3 shows the timing for a typical data transfer with daisy-chained devices. 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.
Figure 20-3:
Daisy-Chained Data Transfer Example
Data Frame Period (1/)
CSCK
CO
O
CSDI or CSDO
Time Slot 0
20.3.3
Time Slot 1
FS Pulse
The FS pulse has a minimum active time of one SCK period so that the slave device can detect
the start of the data frame. The duty cycle of the FS pulse can vary depending on the specific
protocol used to mark certain boundaries in the data frame.
As an 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-channel and right-channel data words.
As another example, 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.
DS70288C-page 20-10
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.4
DCI OPERATION
Figure 20-4 shows a simplified block diagram of the DCI module. The DCI module consists of a
transmit/receive shift register connected to a small range of memory buffers via a buffer control
unit. This arrangement allows the DCI to support various codec serial protocols. The DCI shift
register is 16 bits wide. Data is transmitted and received by the DCI Most Significant bit (MSb)
first.
Figure 20-4:
DCI Module Block Diagram
BCG<11:0>
CSCKD
TCY
Clock Generator
CSCK
COD
16-bit Data Bus
WS<3:0>
COG<3:0>
COM<1:0>
Frame
Synchronization
Generator
CO
Receive Registers with
Buffer
Buffer Control
0
15
Transmit Registers with
Buffer
DCI Shift Register
CSDI
CSDO
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-11
dsPIC33F/PIC24H Family Reference Manual
20.4.1
DCI Pins
Four I/O pins (CSCK, CSDO, CSDI and COFS) are associated with the DCI module. The DCI
module, when enabled, controls the data direction of each of the four pins.
20.4.1.1
CSCK PIN
The CSCK pin provides the serial clock connection for the DCI. The CSCK pin can 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 dsPIC33F/PIC24H 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
20.4.1.2
CSDO PIN
The Serial Data Output (CSDO) pin is configured as an output-only pin when the module is
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,
depending on the state of the Serial Data Output Mode control bit, CSDOM (DCICON1<6>). The
tri-state option allows other devices to be multiplexed onto the CSDO connection.
20.4.1.3
CSDI PIN
The Serial Data Input (CSDI) pin is configured as an input-only pin when the module is enabled.
20.4.1.4
COFS PIN
The Frame Synchronization (COFS) pin is used to synchronize data transfers that occur on the
CSDO and CSDI pins. The COFS pin is bidirectional and can be configured as an input or an
output. The data direction 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 generates FS
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 initiate data transfers. The DCI is a slave device when the COFSD
control bit is set.
20.4.2
Module Enable
The DCI module is enabled or disabled by setting or clearing the DCI Module Enable control bit,
DCIEN (DCICON1<15>). Clearing the DCIEN control bit resets the module. All counters
associated with serial clock generation, FS and the buffer control logic are reset. For additional
information, refer to 20.5.1.1 “DCI Start-up and Data Buffering” and 20.5.1.2 “DCI Disable”.
When enabled, the DCI controls the data direction for the CSCK, CSDI, CSDO and COFS I/O
pins associated with the module. The PORT, LAT and TRIS register values for these I/O pins are
overridden by the DCI module when the DCIEN bit (DCICON1<15>) is set.
DS70288C-page 20-12
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.4.3
Bit Clock Generator
The DCI module has a dedicated 12-bit time base that produces the bit clock. The bit clock rate
(period) is set by writing a non-zero 12-bit value to the DCI Bit Clock Generator control bits,
BCG<11:0> (DCICON3<11:0>). When the BCG<11:0> bits are set to zero, the bit clock is
disabled.
Note:
The CSCK I/O pin is 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 DCICON3<11:0>. This
allows the BCG 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 are overridden and the data direction for the CSCK pin
is controlled by the CSCKD control bit (DCICON1<10>).
• If the serial clock for the DCI is provided by an external device, set the BCG<11:0> bits
(DCICON3<11:0>) to ‘0’ and the CSCKD bit to ‘1’
• If the serial clock is generated by the DCI module, set the BCG<11:0> control bits
(DCICON3<11:0>) to a non-zero value (refer to Equation 20-1) and set the CSCKD control
bit (DCICON1<10>) to ‘0’
Equation 20-1 provides the formula for the bit clock frequency.
Equation 20-1:
DCI Bit Clock Generator Value
BCG<11:0> =
FCY
2 FCSCK
–1
The required bit clock frequency is determined by the system sampling rate and frame size.
Typical bit clock frequencies range from 16 to 512 times the converter sample rate, depending
on the data converter and the communication protocol used.
As an example, consider a dsPIC33F device running at 40 MIPS. The DCI module is required to
interface with a 16-bit codec, which is configured for a sampling rate of 8 kHz. Therefore, the FS
Period = 1/8 kHz = 125 microseconds.
The codec sends two 16-bit words in every frame and the frame occurs at the sampling
frequency. Two 16-bit words in a frame requires the bit period to be (125 microseconds/(2 x 16))
= 3.960625 microseconds. Therefore, the clock frequency for this codec is FCSCK = (1/3.960625
microseconds) = 256 kHz.
The Bit Clock Generator (BCG) value for the DCI module using Equation 20-1 is BCG =
[40000000/(2 x 256000)] – 1 = 77.
20.4.4
Sample Clock Edge Selection
The Sample Clock Edge (CSCKE) control bit (DCICON1<9>) determines the sampling edge for
the serial clock signal.
• If the CSCKE bit is cleared (default), data is sampled on the falling edge of the CSCK
signal. The AC-Link protocols and most multi-channel formats require that data be sampled
on the falling edge of the CSCK signal
• If the CSCKE bit is set, data is sampled on the rising edge of the CSCK. The I2S protocol
requires that data is sampled on the rising edge of the serial clock signal
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-13
dsPIC33F/PIC24H Family Reference Manual
20.4.5
Frame Synchronization Mode Control Bits
The type of interface protocol supported by the DCI is selected using the FS mode control bits,
COFSM<1:0> (DCICON1<1:0>). Table 20-1 provides a selection of operating modes.
Table 20-1:
Operating Modes
Mode
Multi-channel
I2S
AC-Link (16-bit)
AC-Link (20-bit)
20.4.6
DCICON1<1:0>
Value
For Information, See Section...
20.5.4 “Multi-Channel Operation”
20.5.5 “I2S Operation”
00
01
10
11
20.5.6 “AC-Link Operation”
Word-Size Selection Bits
The DCI Data Word Size bits, WS<3:0> (DCICON2<3:0>), determine the number of bits in each
DCI data word. This is the length of each time slot in the frame. Any data length from 4 to 16 bits
can be selected. Word size greater than 16 bits can be processed by enabling multiple time slots.
For additional information, refer to 20.5.3 “Data Packing for Long Data Word Support”.
Note:
20.4.7
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 Synchronization Generator
The Frame Synchronization Generator (FSG) is a 4-bit counter that sets the frame length in data
words. The period for the FSG is set by writing the Frame Synchronization Generator control bits,
COFSG<3:0> (DCICON2<8:5>). Equation 20-2 provides the FSG period (in serial clock cycles)
determined by the formula.
Equation 20-2:
Frame Length In CSCK Cycles
FrameLength = (WS<3:0> + 1) • (COFSG<3:0> + 1)
A data frame may include time slots during which no data is transferred. As an example, a 16-bit
codec requires a control word to be received 16 clock cycles (Time Slot 2) after receiving the
16-bit data word (Time Slot 0). The codec also transmits a data word on its output line in Time
Slot 0 (refer to Figure 20-5).
The total frame length is three words or 48 clock cycles (16 clock cycles per word x 3 words). To
communicate with this codec, these DCICON register bits must be set as follows:
• Word Size: WS<3:0> (DCICON2<3:0) = 1111 (16-bit)
• Frame Synchronization Generator: COFSG (DCICON2<8:5>) = 0010 (three words)
Even though no data is transmitted during time slot 1, the frame length must accommodate for
the disabled time slot (a time slot during which no data is transmitted or received).
Frame lengths up to 16 data words can be selected. The frame length in serial clock periods vary
up to a maximum of 256 depending on the word size selected.
Note:
Figure 20-5:
The COFSG<3:0> control bits have no effect in AC-Link mode, since the frame
length is set to 256 serial clock periods by the protocol.
DCI Timing with WS<3:0> = 1111 and COFSG<3:0> = 0010
1 FRAME
16 Clock Cycles
16 Clock Cycles
16 Clock Cycles
CSCK
CO
CSDO
Time Slot 0 – 16-bit Data Word
CSDI
Time Slot 0 – 16-bit Data Word
DS70288C-page 20-14
Time Slot 2 – 16-bit Control Word
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.4.8
Transmit and Receive Registers
The DCI has four transmit registers, TXBUF0 through TXBUF3, and four receive registers,
RXBUF0 through RXBUF3. All of the transmit and receive registers are memory mapped.
20.4.8.1
BUFFER DATA ALIGNMENT
Data values are always stored left justified in the TXBUF and RXBUF 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 Least Significant bits (LSb) in the receive registers are set
to ‘0’ by the module. The module ignores the unused LSbs in the transmit register.
20.4.8.2
TRANSMIT AND RECEIVE BUFFERS
The transmit and receive registers each have a set of buffers that are not accessible by the user
software. 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 software to read and write the RXBUF and TXBUF registers, while the DCI
uses data from the buffers.
Note:
20.4.9
The TXBUF0 through TXBUF3 registers are write-only registers and should not be
read by the user application.
DCI Buffer Control Unit
The DCI module contains a buffer control unit that transfers data between the buffer memory and
the serial shift register. The buffer control unit also transfers data between the buffer memory and
the TXBUF and RXBUF registers. The buffer control unit allows the DCI to queue the
transmission and reception of multiple data words without CPU overhead.
The DCI generates an interrupt each time a transfer between the buffer memory and the TXBUF
and RXBUF registers takes place. The number of data words buffered between interrupts is
determined by the Buffer Length control bits, BLEN<1:0> (DCICON2<11:10>). The size of the
transmit and receive buffering can vary from 1 to 4 data words using the BLEN<1:0> control bits.
Each time a data transfer takes place between the DCI shift register and the buffer memory, the
DCI buffer control unit is incremented to point to the next buffer location. If the number of
transmitted or received data words is equal to the BLEN<1:0> value + 1, the following occurs:
1.
2.
3.
4.
The buffer control unit is reset to point to the first buffer location.
The received data held in the receive buffer is transferred to the RXBUF registers.
The data in the TXBUF registers is transferred to the buffer.
A CPU interrupt is generated.
The DCI buffer control unit always accesses the same relative location in the transmit and
receive buffers. For example, if the DCI is transmitting data from TXBUF3, any data received
during that time slot is written to RXBUF3.
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-15
dsPIC33F/PIC24H Family Reference Manual
Figure 20-6:
DCI Buffer Control Unit
Transmit Registers
TXBUF0
TXBUF1
Transmit Buffer
4
Transmit
Buffer
Select
4
TXBUF2
TXBUF3
Buffer Transfer Signal
BLEN<1:0>
2
CSDO
DCI
Shift
Register
Buffer Control
Receive Registers
CSDI
Receive Buffer
RXBUF0
RXBUF1
4
4
RXBUF2
Receive
Buffer
Select
RXBUF3
20.4.10 Transmit Slot Enable Bits
The Transmit Slot Enable (TSCON) register has the Transmit Slot Enable control bits,
TSE15:TSE0 (TSCON<15:0>), that can enable up to 16 time slots for transmission. The size of
each time slot is determined by the DCI Data Word Size bits, WS<3:0> (DCICON2<3:0>), and
can vary up to 16 bits.
If a transmit time slot is enabled via one of the TSEx bits (TSEx = 1), the content of the current
transmit buffer location is loaded into the CSDO shift register and the DCI buffer control unit
increments to point to the next buffer location. At least one transmit time slot must be enabled for
data to be transmitted. If a disabled time slot is encountered, the buffer pointer increments
without transmitting the contents of the corresponding TXBUFx register.
Not all TSEx control bits affect the module operation if the selected frame size has less than 16
data slots. The Most Significant TSEx control bits are not used. For example, if COFSG<3:0> =
0111 (8 data slots per frame), TSE8 through TSE15 have no effect on the DCI operation.
20.4.10.1 CSDO MODE CONTROL
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 (DCICON1<6>) is cleared (default), the CSDO pin drives 0’s onto the
CSDO pin during disabled time slot periods. This mode is used when there are only two
devices (one master and one slave) attached to the serial bus
• If the CSDOM bit (DCICON1<6>) is set, the CSDO pin is tri-stated during unused time slot
periods. This mode allows multiple dsPIC33F devices to share the same CSDO line in a
multiplexed application. Each device on the CSDO line is configured so that it transmits
data only during specific time slots. No two devices should transmit data during the same
time slot
DS70288C-page 20-16
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.4.11 Receive Slot Enable Bits
The Receive Slot Enable (RSCON) register contains the Receive Slot Enable control bits,
RSE15:RSE0 (RSCON<15:0>), used to enable up to 16 time slots for reception. The size of each
receive time slot is determined by the WS control bits (DCICON2<3:0>) and can vary from 4 to
16 bits.
If a receive time slot is enabled via one of the RSEx bits (RSEx = 1), the shift register contents
are written to the current DCI receive buffer location and the buffer control logic advances to the
next available buffer location. At least one receive time slot must be enabled for data to be
received. If a disabled time slot is encountered, the buffer pointer increments without receiving
the contents of the corresponding RXBUFx register.
Data is not packed in the receive memory buffer locations if the selected word size is less than
16 bits. Each received slot data word is stored in a separate 16-bit buffer location. Data is always
stored in a left-justified format in the receive memory buffer. Therefore, if the word size is 8-bit,
the received data is stored in bit 15 through bit 8 of the RXBUFx register.
20.4.12 DCI Buffer Control Unit Operation
The DCI module allows read and write operations while it is in the process of transmitting or
receiving data. Data is written to the TXBUFx registers and read from the RXBUFx registers. The
following shows an example of internal DCI read/write operation, for the case of BLEN<1:0> = 01
(Buffer length = 2). Figure 20-7 shows that when the DCI module is disabled, no data is received
or transmitted.
Figure 20-7:
DCI Module Disabled
Transmit Buffer Select
Transmit Registers
Transmit Buffer
Shift Register
Buffer Control
CSDO
CSDI
0x0000
0x0000
0x0000
Receive Buffer
Receive Registers
Receive Buffer Select
Figure 20-8 shows the state of the transmit registers after the application has written data to the
TXBUF0 and TXBUF1 registers.
Figure 20-8:
User Application Writes to TXBUF0 and TXBUF1
Transmit Buffer Select
Transmit Registers
0x8123
0x9ACC
Shift Register
Buffer Control
0x0000
0x0000
0x0000
Receive Registers
© 2007-2012 Microchip Technology Inc.
Receive Buffer Select
DS70288C-page 20-17
20
Data Converter
Interface (DCI)
CSDO
CSDI
dsPIC33F/PIC24H Family Reference Manual
When the DCI module is enabled, the CPU receives the DCI interrupt after three clock cycles.
When this occurs, data in TXBUF0 shifts to the shift register and data in TXBUF1 is shifted to the
transmit Buffer, see Figure 20-9. The DCI module will start shifting data out on the CSDO pin.
The contents of the receive buffers are shifted to the RXBUF receive registers. Since no data was
received when the module was disabled, these values read as ‘0’. The RXBUFx registers read
‘0’ until the next interrupt, at which time data from the receive buffers is transferred to these
registers. The module will start overwriting data in the receive buffer with data received on the
CSDI pin.
Figure 20-9:
DCI Module Enabled
Transmit Buffer Select
Transmit Registers
0x8123
0x9ACC
Transmit Buffer
0x9ACC
Interrupt
Buffer Control
Shift Register
0x0000
See Note 1
0x0000
0x0000
CSDO
CSDI
Receive Buffer
Receive Registers
Receive Buffer Select
Note 1: CSDI is receiving data.
The user application writes new data to TXBUF0 and TXBUF1. Note that writing data to the
TXBUFx register does not affect the current transmit operation.The second data word is shifted
to the shift register. Figure 20-10 shows a new data word is received over the CSDI line into the
receive buffers.
Figure 20-10: User Application Writes to TXBUF0 and TXBUF1, DCI Module Starts Transmitting Second Word
Transmit Buffer Select
Transmit Registers
0xAAAC
Transmit Buffer
0x9ACC
0xDCBA
Shift Register
Buffer Control
0000
0x0012
0000
See Note 1
CSDO
CSDI
Receive Buffer
Receive Registers
Receive Buffer Select
Note 1: CSDI is receiving data.
DS70288C-page 20-18
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
The DCI module has completed transmit/receive operations of BLEN + 1 words, which causes
an interrupt. The data in the receive buffer is copied to the RXBUFx registers. Figure 20-11
shows the data in the TXBUF0 is shifted to the shift register and the contents of the TXBUF1
register is copied to the transmit buffer. This cycle repeats with every DCI interrupt.
Figure 20-11:
DCI Module Transmit/Receives Two Words
Transmit Buffer Select
Transmit Registers
0xAAAC
Transmit Buffer
0xDCBA
0xDCBA
Shift Register
Buffer Control
Interrupt
0x0012
See Note 1
0x0013
0x0013
CSDO
CSDI
Receive Buffer
Receive Registers
Receive Buffer Select
Note 1: 0x0012 data is overwritten by data received on CSDI.
20.4.13 TSCON and RSCON Operation with Buffer Control Unit
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
control unit synchronizes the transmit and receive buffering, so that the transmit and receive
buffer location is always the same for each time slot in the data frame.
If the TSEx and the RSEx bits are set for every time slot 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 to the
number of words received. Consider an example where the DCI is configured for a 2-word data
frame, with Transmit Slot 0 enabled (TSCON = 0x0001) and Receive Slots 0 and 1 enabled
(RSCON = 0x0003). The DCI module is configured to interrupt on four words (BLEN<1:0> = 11).
The frame size is set to 2 data words per frame (COFSG = 0001) and the data word size is set
to 8 bits (WS<3:0> = 0111). Figure 20-12 shows the timing diagram for this example, and
Figure 20-13 shows the corresponding DCI buffer operation. This configuration allows 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 transmitted, the user software writes to every other transmit
buffer location. Specifically, only TXBUF0 and TXBUF2 are used to transmit data.
Figure 20-12: DCI Timing with TSCON = 0x0001 and RSCON = 0x0003
1 FRAME
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
CSCK
CO
CSDO
(TXBUF2)
Time Slot 0 – Data Word
(TXBUF0)
Time Slot 0 – Data Word
Time Slot 0 – Data Word Time Slot 1 – Data Word Time Slot 0 – Data Word Time Slot 1 – Data Word Time Slot 1 – Data Word
(RXBUF0)
(RXBUF1)
(RXBU2)
(RXBUF3)
(RXBUF0)
DCIIF
Cleared by user software
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-19
20
Data Converter
Interface (DCI)
CSDI
(TXBUF0)
Time Slot 0 – Data Word
dsPIC33F/PIC24H Family Reference Manual
Figure 20-13:
DCI Buffer Operation: TSCON = 0x0001, RSCON = 0x0003, BLEN<1:0> = 11
Transmit Registers
TXBUF0
Data Word 1
(Time Slot 0)
TXBUF1
TXBUF2
TXBUF3
Data Word 2
(Time Slot 0)
Receive Registers
RXBUF0
Data Word 1
(Time Slot 0)
RXBUF1
Data Word 2
(Time Slot 1)
RXBUF2
Data Word 3
(Time Slot 0)
RXBUF3
Data Word 4
(Time Slot 1)
Note: User software writes to TXBUF0 and TXBUF2. TXBUF1 and TXBUF3 are not used by transmit logic.
The buffer control resets to point to the first buffer location when BLEN<1:0> + 1 buffers are
written to and a CPU interrupt is generated, or TXBUF3 and RXBUF3 are processed and the
buffer pointer must jump to the first buffer location.
The buffer control increments the buffer pointer when all bits in an enabled time slot have been
processed, or the bits in the time slot exceed 16 bits. The pointer to the TXBUF increments in
synchronization with the RXBUF pointer.
20.4.14 TSCON and RSCON operation with DMA
The DMA module on dsPIC33F devices can be configured to transfer data directly between the
dual port SRAM and the DCI TXBUF0 and RXBUF0 registers, without CPU intervention. The
BLEN<1:0> bits (DCICON2<11:10>) should be set to ‘00’ for correct operation. Although the DCI
module uses only TXBUF0 and RXBUF0 for operation in this mode, it is still possible to have
multi-word frames and multiple time slots. The user application must ensure that data stored in
memory corresponds to the enabled time slots.
Figure 20-12 is an example of the DCI codec communication. The DCI module has 1 transmit
time slot (TS0) enabled, and 2 receive time slots (RS0 and RS1) enabled. The word length is 8
bits (WS<3:0> = 0111) and the frame size is 2 words (COFSG<3:0> = 0001). With BLEN<1:0>
= 00, the DCI module requests for a DMA transfer on every word. The DCI module is configured
for 8-bit word size and transmits data MSb first. Therefore, the data in DPSRAM should be
organized such that the 8-bit data to be transmitted is placed in the Most Significant Byte (MSB)
of the 16-bit word. To meet the timing criteria shown in Figure 20-12, the transmit data memory
in DPSRAM must additionally be organized such that every other word represents data to be
transmitted.
• Transfer 1
The DMA module places the contents of DPSRAM in TXBUF0 and the contents of RXBUF0
into DPSRAM. TXBUF0 and RXBUF0 data corresponds to time slot 0. The DMA pointer will
increment. Since the data word size is 8-bits, the received data is stored in the upper 8 bits of
the DPSRAM word (refer to Figure 20-14).
• Transfer 2
The DMA module will place the contents of DPSRAM in TXBUF0 and the contents of
RXBUF0 into DPSRAM. This data corresponds to time slot 1. Since transmit time slot 1 is disabled, the DCI module will not transmit the data. However, because receive time slot 1 is
enabled, the RXBUF0 register will contain data received on CSDI pin (refer to Figure 20-15).
The data is placed in DPSRAM and the DMA pointer will increment.
• Transfer 3
Since the frame length is 2 words, the DCI module will assert the COFS signal. The DMA
module places the contents of DPSRAM in TXBUF0 and the contents of RXBUF0 into
DPSRAM. TXBUF0 and RXBUF0 data corresponds to time slot 0. The DMA pointer will increment. Since the data word size is 8-bits, the received data is stored in the upper 8 bits of the
DPSRAM word (refer to Figure 20-16).
• Transfer 4
The DMA module places the contents of DPSRAM in TXBUF0 and the contents of RXBUF0
into DPSRAM. This data corresponds to time slot 1. Since transmit time slot 1 is disabled, the
DCI module will not transmit the data. However, because receive time slot 1 is enabled, the
RXBUF0 register will contain data received on the CSDI pin (refer to Figure 20-17). The data
is placed in DPSRAM and the DMA pointer will increment.
DS70288C-page 20-20
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Figure 20-14: Transfer 1: Time Slot 0
&_DMA_BASE
&_DMA_BASE+DMA0STA+0
D<15:8>
XXXX
Transfer 1
DCI Module
XXXX
&_DMA_BASE+DMA0STA+2
DMA Channel 0
&_DMA_BASE+DMA0STA+4
D<15:8>
&_DMA_BASE+DMA0STA+6
&_DMA_BASE+DMA0STA+8
TXBUF0
XXXX
XXXX
D<15:8>
XXXX
D<15:8>
XXXX
&_DMA_BASE
&_DMA_BASE+DMA1STA+0
Transfer 1
DCI Module
&_DMA_BASE+DMA1STA+2
XXXX
&_DMA_BASE+DMA1STA+4
XXXX
&_DMA_BASE+DMA1STA+6
XXXX
DMA Channel 1
RXBUF0
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-21
dsPIC33F/PIC24H Family Reference Manual
Figure 20-15: Transfer 2: Time Slot 1
&_DMA_BASE
&_DMA_BASE+DMA0STA+0
&_DMA_BASE+DMA0STA+2
D<15:8>
XXXX
XXXX
DCI Module
Transfer 2
DMA Channel 0
&_DMA_BASE+DMA0STA+4
&_DMA_BASE+DMA0STA+6
D<15:8>
XXXX
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+0
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+2
D<15:8>
XXXX
&_DMA_BASE+DMA0STA+8
TXBUF0
XXXX
&_DMA_BASE
DCI Module
Transfer 2
DMA Channel 1
&_DMA_BASE+DMA1STA+4
XXXX
&_DMA_BASE+DMA1STA+6
XXXX
DS70288C-page 20-22
RXBUF0
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Figure 20-16: Transfer 3: Time Slot 0
&_DMA_BASE
&_DMA_BASE+DMA0STA+0
D<15:8>
XXXX
DCI Module
XXXX
&_DMA_BASE+DMA0STA+2
Transfer 3
&_DMA_BASE+DMA0STA+4
D<15:8>
TXBUF0
XXXX
&_DMA_BASE+DMA0STA+6
&_DMA_BASE+DMA0STA+8
DMA Channel 0
XXXX
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+0
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+2
D<15:8>
XXXX
&_DMA_BASE
DCI Module
Transfer 3
&_DMA_BASE+DMA1STA+4
D<15:8>
&_DMA_BASE+DMA1STA+6
DMA Channel 1
RXBUF0
XXXX
XXXX
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-23
dsPIC33F/PIC24H Family Reference Manual
Figure 20-17: Transfer 4: Time Slot 1
&_DMA_BASE
&_DMA_BASE+DMA0STA+0
&_DMA_BASE+DMA0STA+2
&_DMA_BASE+DMA0STA+4
&_DMA_BASE+DMA0STA+6
D<15:8>
XXXX
DCI Module
XXXX
D<15:8>
XXXX
DMA Channel 0
TXBUF0
XXXX
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+0
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+2
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+4
D<15:8>
XXXX
&_DMA_BASE+DMA1STA+6
D<15:8>
XXXX
&_DMA_BASE+DMA0STA+8
Transfer 4
&_DMA_BASE
DCI Module
Transfer 4
DMA Channel 1
RXBUF0
20.4.15 Receive Status Bits
The two receive status bits, Receive Buffer Full, RFUL (DCISTAT<2>), and Receive Overflow,
ROV (DCISTAT<3>), indicate the status only for register locations that are enabled for use by the
module. This is a function of the BLEN<1:0> control bits (DCICON2<11:10>). If the buffer length
is set to less than four words, the unused buffer locations do not affect the receive status bits.
The RFUL status bit (DCISTAT<2>) is read-only and indicates that new data is available in the
receive registers. The RFUL bit is cleared automatically when all RXBUF registers in use have
been read by the user software.
The ROV status bit (DCISTAT<3>) is read-only and indicates that a receive overflow has
occurred for at least one of the receive register locations. A receive overflow occurs when the
RXBUF register location is not read by the user software before new data is transferred from the
buffer memory. When a receive overflow occurs, the old contents of the register are overwritten.
The ROV status bit is cleared automatically when the register that caused the overflow is read.
DS70288C-page 20-24
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.4.16 Transmit Status Bits
The two transmit status bits, Transmit Buffer Empty bit, TMPTY (DCISTAT<0>), and Transmit
Buffer Underflow bit, TUNF (DCISTAT<1>), indicate the status only for register locations that are
used by the module. If the buffer length is set to less than four words, for example, the unused
register locations do not affect the transmit status bits.
The TMPTY bit (DCISTAT<0>) is read-only and is set when the contents of the active TXBUF
registers are transferred to the transmit buffer registers. The TMPTY bit can be polled in software
to determine when the transmit registers can be written. The TMPTY bit is cleared automatically
by the hardware when a write to any of the TXBUF registers in use occurs.
The TUNF bit (DCISTAT<1>) is read-only and indicates that a transmit underflow has occurred
for at least one of the transmit registers in use. The TUNF bit is set when the TXBUF register
contents are transferred to the transmit buffer memory and the user software did not write all of
the TXBUF registers in use since the last buffer transfer. The TUNF status bit clears automatically
when the TXBUF register that underflowed is written by the user software.
20.4.17 SLOT Status Bits
The SLOT<3:0> status bits (DCISTAT<11:8>) indicate the current active time slot in the data
frame. These bits are useful when more than four words per data frame need to be transferred.
The user software can poll these status bits when a DCI interrupt occurs to determine what time
slot data was last received and which time slot data should be loaded into the TXBUF registers.
20.4.18 Digital Loopback Mode
Digital Loopback mode is enabled by setting the Digital Loopback mode control bit, DLOOP
(DCICON1<11>). When the DLOOP bit is set, the module internally connects the CSDO signal
to CSDI. The actual data input on the CSDI pin is ignored in Digital Loopback mode.
20.4.19 Underflow Mode Control Bit
When a transmit underflow occurs, one of two actions can occur depending on the state of the
Underflow Mode control bit, UNFM (DCICON1<7>).
• If the UNFM bit is cleared (default), the module transmits 0’s on the CSDO pin during the
active time slot for the buffer location. In this operating mode, the codec device attached to
the DCI module is simply fed digital “silence”.
• If the UNFM control bit is set, the module transmits the last data written to the buffer
location. This operating mode permits the user software to send a continuous data value to
the codec device without consuming software overhead.
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-25
dsPIC33F/PIC24H Family Reference Manual
20.4.20 Data Justification Control
In most applications, the data transfer begins one serial clock cycle after the FS signal is sampled
active (refer to Figure 20-18). This is the DCI module default.
Figure 20-18: Default Data Transfer
1 FRAME
16 Clock Cycles
16 Clock Cycles
16 Clock Cycles
CSCK
CO
CSDO
Time Slot 0 – 16-bit Data Word
CSDI
Time Slot 0 – 16-bit Data Word
Time Slot 2 – 16-bit Control Word
An alternate data alignment can be selected by setting the DJST control bit (DCICON1<5>).
When DJST = 1, data transfers begin during the same serial clock cycle as the FS signal (refer
to Figure 20-19).
Figure 20-19: Data Transfer Selection Using the DJST Control Bit
1 FRAME
16 Clock Cycles
16 Clock Cycles
16 Clock Cycles
CSCK
CO
CSDO
Time Slot 0 – 16-bit Data Word
CSDI
Time Slot 0 – 16-bit Data Word
Time Slot 2 – 16-bit Control Word
20.4.21 DCI Module Interrupts
The frequency of DCI module interrupts depends on the BLEN<1:0> control bits. An interrupt is
generated when the buffer length has been reached. If interrupts are enabled before the DCI
module is enabled, an interrupt is generated three CSCK cycles after the module is enabled.
The DCI module also features an error interrupt. The error interrupt, if enabled, causes the CPU
to interrupt when a transmit underflow or when a receive overflow event occurs.
DS70288C-page 20-26
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.5
USING THE DCI MODULE
This section explains how to configure and use the DCI module with specific kinds of data converters.
20.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<1:0> 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.
Following are four configuration examples:
1.
Assume BLEN<1:0> = 00 (buffer one data word per interrupt) and TSCON = RSCON =
0x0001. This configuration represents the most basic setup and causes the DCI to transmit or receive one data word at the beginning of every data frame. The CPU is interrupted
after every data word transmitted or received since BLEN<1:0> = 00. For details, refer to
Figure 20-20.
Figure 20-20: DCI Timing with BLEN = 00 and TSCON = RSCON = 0x0001
1 FRAME
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
(TXBUF0)
Time Slot 0 – Data Word
(TXBUF0)
Time Slot 0 – Data Word
(TXBUF0)
Time Slot 0 – Data Word
(TXBUF0)
Time Slot 0 – Data Word
Time Slot 0 – Data Word
(RXBUF0)
Time Slot 0 – Data Word
(RXBUF0)
Time Slot 0 – Data Word
(RXBUF0)
Time Slot 0 – Data Word
(RXBUF0)
CSCK
CO
CSDO
CSDI
DCIIF
Cleared by user software
2.
Assume BLEN<1:0> = 11 (buffer four data words per interrupt) and TSCON = RSCON =
0x0001. This configuration causes the DCI to transmit or receive one data word at the
beginning of every data frame. A CPU interrupt is generated after four data words are
transmitted or received. This configuration is useful for block processing, where multiple
data samples are processed at once. For details, refer to Figure 20-21.
Figure 20-21: DCI Timing with BLEN = 11 and TSCON = RSCON = 0x0001
1 FRAME
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
CSCK
CO
Time Slot 0 – Data Word
(TXBUF0)
Time Slot 0 – Data Word
(TXBUF1)
(TXBUF2)
Time Slot 0 – Data Word
(TXBUF3)
Time Slot 0 – Data Word
CSDI
Time Slot 0 – Data Word
(RXBUF0)
Time Slot 0 – Data Word
(RXBUF1)
Time Slot 0 – Data Word
(RXBUF2)
Time Slot 0 – Data Word
(RXBUF3)
DCIIF
Cleared by user software
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-27
20
Data Converter
Interface (DCI)
CSDO
dsPIC33F/PIC24H Family Reference Manual
3.
Assume BLEN<1:0> = 11 (buffer four data words per interrupt) and TSCON = RSCON =
0x000F. This configuration causes the DCI to transmit/receive four data words at the
beginning of every data frame. A CPU interrupt is generated every data frame in this case
because the DCI was set up to buffer four data words in a data frame. This configuration
represents a typical multi-channel buffering setup. For details, refer to Figure 20-22.
Figure 20-22: DCI Timing with BLEN = 11 and TSCON = RSCON = 0x000F
1 FRAME
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
8 Clock Cycles
CSCK
CO
CSDO
Time Slot 0 – Data Word
(TXBUF0)
Time Slot 1 – Data Word
(TXBUF1)
(TXBUF2)
Time Slot 2 – Data Word
(TXBUF3)
Time Slot 3 – Data Word
CSDI
Time Slot 0 – Data Word
(RXBUF0)
Time Slot 1 – Data Word
(RXBUF1)
Time Slot 2 – Data Word
(RXBUF2)
Time Slot 3 – Data Word
(RXBUF3)
DCIIF
Cleared by user software
4.
The DCI can also be configured to buffer more than four data words per frame. For
example, assume BLEN<1:0> = 11 (buffer four data words per interrupt) and TSCON =
RSCON = 0x00FF. In this configuration, the DCI transmits/receives 8 data words per data
frame. An interrupt is generated twice per data frame. To determine which portion of the
data is in the transmit or receive registers at each interrupt, the user software must check
the SLOT<3:0> status bits (DCISTAT <11:8>) in the Interrupt Service Routine (ISR) to
determine the current data frame position. Figure 20-23 shows a 4-bit example for this
case.
Figure 20-23: DCI Timing with BLEN = 11 and TSCON = RSCON = 0x00FF
1 FRAME
4 Clock Cycles 4 Clock Cycles 4 Clock Cycles 4 Clock Cycles 4 Clock Cycles 4 Clock Cycles 4 Clock Cycles 4 Clock Cycles
CSCK
CO
CSDO
TXBUF0
TXBUF1
TXBUF2
TXBUF3
TXBUF0
TXBUF1
TXBUF2
TXBUF3
CSDI
RXBUF0
RXBUF1
RXBUF2
RXBUF3
RXBUF0
RXBUF1
RXBUF2
RXBUF3
0000
0001
0010
0011
0100
0101
0110
0111
DCIIF
SLOT
<3:0>
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 takes three interrupt periods to receive the data, process that
data, and transmit the processed data. For each DCI interrupt, the CPU processes a data word
received during a prior interrupt period and generates a data word transmitted during the next
interrupt period. The buffering and data processing time of the dsPIC33F device inserts a
two-interrupt period delay into the processed data. In most cases, this data delay is negligible.
DS70288C-page 20-28
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
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 occurs each time
the DCI data is processed:
1.
2.
3.
4.
5.
6.
RXBUF registers are read by the user software.
RFUL status bit (DCISTAT<2>) is set by the module to indicate that the receive registers
contain new data.
RFUL bit is cleared automatically after all the active receive registers have been read.
User software processes the received data.
TMPTY status bit (DCISTAT<0>) is set to indicate that the transmit registers are ready for
more data to be written.
Processed data is written to the TXBUF registers.
For applications that are configured to transmit and receive data (TSCON and RSCON are
non-zero), the RFUL (DCISTAT<2>) and TMPTY (DCISTAT<0>) status bits can be polled in user
software to determine when a DCI buffer transfer takes place.
• If the DCI is used only to transmit data (RSCON = 0), the TMPTY bit can be polled to
indicate a buffer transfer
• If the DCI is configured to only receive data (TSCON = 0), 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
(DCISTAT<2>) and TMPTY (DCISTAT<0>) status bits.
20.5.1.1
DCI START-UP AND DATA BUFFERING
For DCI start-up, first initialize the DCI control registers for the desired operating mode. Data
transfers are begun by setting the DCIEN control bit (DCICON1<15>). Refer to
20.5.4 “Multi-Channel Operation”, 20.5.5 “I2S Operation”, and 20.5.6 “AC-Link Operation”.
Figure 20-24 shows a timing diagram for DCI start-up. In this example, the DCI is configured for
an 8-bit data word (WS<3:0> = 0111) and an 8-bit data frame (COFSG<3:0> = 0000). The buffer
length is set to 1 buffer (BLEN = 00), the transmit time slot 0 is enabled (TSCON = 0x1), and the
receive time slot 0 is enabled (RSCON = 0x1). In addition, the Multi-Channel mode
(COFSM<1:0> = 00) is used. The steps required to transmit and receive data are described as:
1.
2.
3.
4.
6.
7.
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-29
20
Data Converter
Interface (DCI)
5.
Preload the TXBUF registers with the first data to be transmitted before the module is
enabled. If the transmit data is based on data received from the codec, the user software
can simply clear the TXBUF registers. This transmits digital “silence” until data is first
received into the RXBUF registers from the codec.
Enable the DCI module by setting the DCIEN bit (DCICON1<15>). If the DCI is the master
device, the data in the TXBUF registers is transferred to the transmit buffers and
transmission of the first data frame commences. Otherwise, the TXBUF data is held in the
transmit buffers until a FS signal is received from the master device.
The TMPTY bit (DCISTAT<0>) is set 3 clock cycles after the module is enabled and a DCI
interrupt is 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, so the TXBUF registers are cleared again if the transmitted data
is calculated from the received data. If interrupts are enabled, clear the DCIIF status bit in
user software.
After the first data frame is transferred, the TMPTY bit (DCISTAT<0>) is set, the RFUL
status bit is set, and a DCI interrupt occurs, if enabled. This is the first data word received
from the device connected to the DCI.
The user software reads the receive register, automatically clearing the RFUL status bit.
The user software also processes the received data.
The transmit register is written with data to be transmitted during the next data frame. The
TMPTY status bit (DCISTAT<0>) is cleared automatically when the write occurs. The write
data can be calculated from data received at the prior interrupt.
The next DCI interrupt occurs and the cycle repeats.
dsPIC33F/PIC24H Family Reference Manual
Figure 20-24: DCI Start-up and Data Buffering Example
CSCK
Data
7
6
5
4
3
2
1
0
7
6
5
Word 1
4
3
2
1
0
7
6
Word 2
CO
DCIEN
TMPTY
TXBUF
TX Word 1
TX Word 2
TX Word 3
RFUL
RXBUF
RX Word 1
Cleared by user software
DCIIF
1
2
3
20.5.1.2
DCI DISABLE
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 finishes the data frame transfer in progress. An interrupt is generated
if the transmit/receive buffers need to be written or read before the end of the frame.
The DCIEN bit must be cleared at least three CSCK cycles before the end of the frame for the
module to be disabled in that frame. If the bit is not cleared in time, the module is disabled on the
next frame.
Once disabled, the DCI will not generate any further FS pulses, nor will it respond to an incoming
FS pulse.
When the FSG has reached the final time slot in the data frame, all state machines associated
with the DCI are reset to their Idle state and control of the I/O pins associated with the module is
released. The user software can poll the SLOT<3:0> status bits (DCISTAT<11:8>) after the
DCIEN bit (DCICON1<15>) is cleared to determine when the module is idle. The DCI is idle when
SLOT<3:0> = 0000 and DCIEN = 0.
When the module enters an Idle state, any data in the receive shadow registers is transferred to
the RXBUF registers, and the RFUL and ROV status bits are affected accordingly.
DS70288C-page 20-30
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Figure 20-25: DCI Timing, Module Disable
WS = 0011
pulse not generated
COG = 0011
CSCK
Data
3
2
1
0
3
2
1
0
3
2
1
0
3
2
1
0
3
2
1
0
CO
DCIEN
SLOT<3:0>
0011
0000
0001
0010
0011
0000
RFUL
Receive buffer contents transferred to RXBUF
20.5.2
Master vs. Slave Operation
The DCI can be configured for master or slave operation. The master device generates the FS
signal to initiate a data transfer. The operating mode (Master or Slave) is selected by the COFSD
control bit (DCICON1<8>).
When the DCI module is operating as a master device (COFSD = 0), the COFSM<1:0> mode
bits (DCICON1<1:0>) determine the type of FS pulse that is generated by the FSG logic. A new
FS signal is generated when the FSG resets and is output on the COFS pin.
When the DCI module is operating as a FS slave (COFSD = 1), data transfers are controlled by
the device attached to the DCI module. The COFSM<1:0> control bits (DCICON1<1:0>) control
how the DCI module responds to incoming FS signals.
In the Multi-Channel mode, a new data frame transfer begins one serial clock cycle after the
COFS pin is sampled high. The pulse on the COFS pin resets the FSG logic.
In the I2S mode, a new data word is transferred one serial clock cycle after a low-to-high or a
high-to-low transition is sampled on the COFS pin. A rising or falling edge on the COFS pin resets
the FSG logic.
In AC-Link mode, the tag slot and subsequent data slots for the next frame is transferred one
serial clock cycle after the COFS pin is sampled high.
The COFSM<1:0> (DCICON1<1:0>) and WS<3:0> (DCICON2<3:0>) bits must be configured to
provide the expected frame length when the module is operating in Slave mode. Once a valid FS
pulse is sampled by the module on the COFS pin, an entire data frame transfer takes place. The
module will not respond to further FS pulses until the current data frame transfer has fully completed.
20.5.3
Data Packing for Long Data Word Support
Many codecs have data word lengths in excess of 16 bits. The DCI natively supports word
lengths up to 16 bits, but longer word lengths can be supported by enabling multiple transmit and
receive slots and packing data into multiple transmit and receive buffer locations.
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-31
20
Data Converter
Interface (DCI)
For example, assume that a particular codec transmits or receives 24-bit data words. This data
could be transmitted and received by setting BLEN<1:0> = 01 (two data words per interrupt) and
setting TSCON = 0x0003 and RSCON = 0x0003. This enables transmission and reception during
the first two time slots of the data frame. The 16 MSbs of the transmit data are written to TXBUF0.
The 8 LSbs of the transmit data are written left justified to TXBUF1, as shown in Figure 20-26.
The value of the 8 LSbs of TXBUF1 can be written to ‘0’. The 24-bit data received from the codec
is loaded into RXBUF0 and RXBUF1 with the same format as the transmit data. In this case, the
FS signal is generated at the 32-bit intervals.
dsPIC33F/PIC24H Family Reference Manual
Any combination of word size and enabled time slots can be used to transmit and receive long
data words in multiple transmit and receive registers. For example, the 24-bit data word example
shown in Figure 20-26 could be transmitted or received in three consecutive registers by setting
WS<3:0> = 0111 (word size = 8 bits), BLEN<1:0> = 10 (buffer three words between interrupts),
and TSCON = RSCON = 0x0007 (transmit or receive during the first three time slots of the data
frame). Each transmit and receive register would contain 8 bits of the data word (refer to
Figure 20-27). If COFSG<3:0> = 0010 (3 words per frame), the FS signal would be generated at
24-bit intervals.
Figure 20-26: Data Packing Example for Long Data Words
Transmit Registers
TXBUF0
Data Word bits 23:8
bits 7:0
TXBUF1
0 00 0 0 000
TXBUF2
TXBUF3
TSCON = RSCON = 0x0003
BLEN<1:0> = 01
Figure 20-27: Data Packing Example for Long Data Words with WS<3:0> = 0111, and
TSCON = RSCON = 0x0007
Transmit Registers
TXBUF0
bits 23:16
0 00 0 0 000
TXBUF1
bits 15:8
0 00 0 0 000
TSCON = RSCON = 0x0007
TXBUF2
bits 7:0
0 00 0 0 000
TXBUF3
20.5.4
Multi-Channel Operation
Multi-Channel mode (COFSM<1:0> = 00) is used for codecs that require a FS pulse that is driven
high for one serial clock period to initiate a data transfer. One or more data words can be transferred in the data frame. The number of clock cycles between successive FS pulses depends on
the device connected to the DCI module. Figure 20-28 is a timing diagram for the FS signal in
Multi-Channel mode. Figure 20-2 is a timing example indicating a 4-bit word data transfer.
Figure 20-28: Frame Synchronization Timing, Multi-Channel Mode
Frame Synch Sampled Here
First Data Bit Sampled Here
CSCK
CO
Data
DS70288C-page 20-32
MSb
LSb
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.5.4.1
MULTI-CHANNEL SETUP DETAILS
This section provides the steps required to configure the DCI for a codec using Multi-Channel
mode. 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 is assumed. The single channel codec used for this
setup example uses 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.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Determine the sample rate and data word size required by the codec. An 8 kHz sampling
rate is assumed for this example.
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 FS pulse must be
generated every 256 serial clock cycles to start a data transfer.
Configure the DCI for the serial transfer clock:
• If the CSCK signal is generated by the DCI, clear the CSCKD control bit
(DCICON1<10>) and write a value to DCICON3 that produces the correct clock
frequency (refer to 20.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.
Clear the COFSM control bits (DCICON1<1:0>) to set the FS signal to Multi-Channel
mode.
If the DCI is generating the FS signal (master), clear the COFSD control bit
(DCICON1<8>). If the DCI is receiving the FS signal (slave), set the COFSD control bit.
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.
Write the WS control bits (DCICON2<3:0>) for the desired data word size. The example
codec requires WS<3:0> = 1111 for a 16-bit data word size.
Write the COFSG control bits (DCICON2<8:5>) for the desired number of data words per
frame. The WS and COFSG control bits determine the length of the data frame in CSCK
cycles (refer to 20.4.7 “Frame Synchronization Generator”). COFSG<3:0> = 1111 is
used to provide the 256-bit data frame required by the example codec.
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 forces 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.
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.
Set the BLEN<1:0> control bits (DCICON2<11:10>) to buffer the desired amount of data
words. For the single-channel codec, BLEN<1:0> = 00 provides an interrupt at each data
frame. A higher value of BLEN<1:0> could be used for this codec to buffer multiple
samples between interrupts.
If interrupts are to be used, clear the DCIIF status bit (IFS2<9>) and set the DCIIE control
bit (IEC2<9>).
Begin operation as described in 20.5.1.1 “DCI Start-up and Data Buffering”.
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-33
dsPIC33F/PIC24H Family Reference Manual
20.5.4.2
MULTI-CHANNEL SETUP WITH DMA
The Multi-Channel DCI Setup with DMA is similar to the
20.5.4.1 “Multi-Channel Setup Details” with the following exceptions:
setup
described
in
• BLEN<1:0> must be ‘00’. Setting BLEN<1:0> to any other value results in unpredictable
behavior
• The DMA channels must be configured to read/write to the RXBUF0/TXBUF0 registers. For
more details on configuring the DMA module, refer to “Section 22. Direct Memory
Access (DMA)” (DS70182) of the “dsPIC33F/PIC24H Family Reference Manual”.
To use the DMA:
• One DMA channel must be configured to read from Dual Port SRAM (DPSRAM) and write
to the TXBUF0 register
• A second DMA channel is configured to read from the RXBUF0 register and write to the
DPSRAM
• The DMA channels must be enabled before enabling the DCI module. This ensures that
the first DCI interrupt is processed by the DMA module
Figure 20-29 shows the DPSRAM organization for this example. The 16-bit data to be
transmitted must be stored at consecutive locations in DPSRAM since only one time slot is
enabled in the DCI module. The received data will be stored at consecutive locations in
DPSRAM.
Figure 20-29: DPSRAM Organization for Multi-Channel Mode
&_DMA_BASE
&_DMA_BASE+DMA0STA+0
D<15:0>
&_DMA_BASE+DMA0STA+2
D<15:0>
&_DMA_BASE+DMA0STA+4
D<15:0>
&_DMA_BASE+DMA0STA+6
D<15:0>
Transfer 1
DCI Module
Transfer 2
DMA Channel 0
TXBUF0
Transfer 3
Transfer 4
&_DMA_BASE
&_DMA_BASE+DMA1STA+0
D<15:0>
&_DMA_BASE+DMA1STA+2
D<15:0>
&_DMA_BASE+DMA1STA+4
D<15:0>
Transfer 1
Transfer 2
DCI Module
DMA Channel 1
RXBUF0
Transfer 3
Transfer 4
&_DMA_BASE+DMA1STA+6
DS70288C-page 20-34
D<15:0>
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.5.5
I2S Operation
The I2S operating mode is used for codecs that require a FS signal that has a 50% duty cycle.
The period of the I2S FS signal in serial clock cycles is determined by the word size of the codec
connected to the DCI module. Figure 20-30 shows the start of a new word boundary is marked
by a high-to-low or a low-to-high transition edge on the COFS pin. I2S codecs are generally
stereo or two-channel devices, with one data word transferred during the low time of the FS
signal and the other data word transmitted during the high time.
Figure 20-30: I2S Interface Frame Synchronization Timing
Frame Synch Edge Sampled
First Data Bit Sampled
CSCK
Data
MSb
LSb MSb
LSb
CO
Note: A 5-bit transfer is shown here for illustration purposes. The I2S protocol does not specify word
length; this is system dependent.
The DCI module is configured for I2S mode by writing a value of 0x01 to the COFSM<1:0> control
bits in the DCICON1 SFR. When operating in the I2S mode, the DCI module generates FS
signals with a 50% duty cycle. Each edge of the FS signal marks the boundary of a new data
word transfer. The user software must also select the frame length and data word size using the
COFSG<3:0> and WS<3:0> control bits in the DCICON2 register.
20.5.5.1
I2S SETUP DETAILS
This section provides the steps required to configure the DCI for an I2S codec. For this example,
a hypothetical I2S codec is assumed.
The I2S codec in this setup example uses a 64 fs serial clock frequency, with two 16-bit data
words during the data frame. Therefore, the frame length is 64 CSCK cycles, with the COFS
signal high for 32 cycles and low for 32 cycles. The first data word is transmitted one CSCK cycle
after the rising edge of COFS, and the second data word is transmitted one CSCK cycle after the
falling edge of COFS.
1.
2.
3.
4.
5.
7.
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-35
20
Data Converter
Interface (DCI)
6.
Determine the sample rate used by the codec to determine the CSCK frequency. It is
assumed in this example that fs is 48 kHz.
Determine the serial transfer clock frequency required by the codec. The example codec
requires a frequency that is 64 fs, or 3.072 MHz.
The DCI must be configured for the serial transfer clock. If the CSCK signal is generated
by the DCI, clear the CSCKD control bit (DCICON1<10>) and write a value to DCICON3
that produces the correct clock frequency (refer to 20.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.
Set COFSM<1:0> = 01 to set the FS signal to I2S mode.
If the DCI is generating the FS signal (master), clear the COFSD control bit
(DCICON1<8>). If the DCI is receiving the FS signal (slave), set the COFSD control bit.
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.
Write the WS control bits (DCICON2<3:0>) for the desired data word size. For the
example codec, use WS<3:0> = 1111 for a 16-bit data word size.
dsPIC33F/PIC24H Family Reference Manual
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 determine the length of the data frame in
CSCK cycles, refer to 20.4.7 “Frame Synchronization Generator”. For this example
codec, set COFSG<3:0> = 0001.
Note:
9.
10.
11.
12.
13.
In the I2S mode, the COFSG bits are set to the length of half of the data frame. For
this example codec, set COFSG<3:0> = 0001 (two data words per frame) to
produce a 32-bit frame. This produces an I2S data frame that is 64 bits in length.
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.
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.
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> = 01 generates an interrupt after transferring two data words.
If interrupts are to be used, clear the DCIIF status bit (IFS2<9>) and set the DCIIE control
bit (IEC2<9>).
Begin operation as described in 20.5.1.1 “DCI Start-up and Data Buffering”. In the I2S
Master mode, the COFS pin is driven high after the module is enabled and begins
transmitting the data loaded in TXBUF0.
20.5.5.2
I2S SETUP WITH DMA.
The I2S DCI setup with DMA is similar to the setup described in 20.5.5.1 “I2S Setup Details”
with following exceptions:
• BLEN<1:0> must be ‘00’. Setting BLEN<1:0> to any other value results in unpredictable
behavior
• The DMA channels must be configured to read or write to the RXBUF0/TXBUF0 registers.
For more details on configuring the DMA module, refer to “Section 22. Direct Memory
Access (DMA)” (DS70182) of the “dsPIC33F/PIC24H Family Reference Manual”.
To use the DMA:
• One DMA channel must be configured to read from Dual Port SRAM (DPSRAM) and write
to the TXBUF0 register
• A second DMA channel is configured to read from RXBUF0 register and write to the
DPSRAM
• The DMA channels must be enabled before enabling the DCI module. This ensures that
the first DCI Interrupt is processed by the DMA module.
Figure 20-31 shows the DPSRAM organization for this setup. The transmit data is organized as
the first data word (which is transmitted at the falling edge of the COFS signal) followed by the
second data word (which is transmitted at the rising edge of the COFS signal).
DS70288C-page 20-36
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Figure 20-31: DPSRAM Organization for I2S Mode
&_DMA_BASE
D<15:0>
&_DMA_BASE+DMA0STA+0
Transfer 1
&_DMA_BASE+DMA0STA+2
D<15:0>
&_DMA_BASE+DMA0STA+4
D<15:0>
&_DMA_BASE+DMA0STA+6
D<15:0>
DCI Module
Transfer 2
DMA Channel 0
TXBUF0
Transfer 3
Transfer 4
&_DMA_BASE
&_DMA_BASE+DMA1STA+0
D<15:0>
&_DMA_BASE+DMA1STA+2
D<15:0>
Transfer 1
D<15:0>
&_DMA_BASE+DMA1STA+4
Transfer 2
DCI Module
DMA Channel 1
RXBUF0
Transfer 3
Transfer 4
D<15:0>
&_DMA_BASE+DMA1STA+6
20.5.5.3
HOW TO DETERMINE THE I2S CHANNEL ALIGNMENT
Most I2S codecs support two channels of data, and the level of the FS signal indicates the channel 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 (ISR). This indicates which data is in the receive register and which data should be
written to the transmit registers for transfer on the next frame.
20.5.5.4
I2S DATA JUSTIFICATION
As per the I2S specification, a data word transfer by default begins one serial clock cycle
following a transition of the FS signal. An “MSb left-justified” option can be selected using the
DJST control bit (DCICON1<5>).
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-37
20
Data Converter
Interface (DCI)
If DJST = 1, the I2S data transfers are MSb left-justified. The MSb of the data word is 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.
dsPIC33F/PIC24H Family Reference Manual
Figure 20-32: I2S Data Justification Options
1. Standard I2S Data Alignment
CSCK
Channel 1 Transfer
CO
Data
7 6
5 4 3
2 1
Channel 2 Transfer
7 6
0
5 4 3
2 1
0
2. Left-Justified Data Alignment
CSCK
CO
Data
Channel 1 Transfer
7 6
5 4 3
2 1
20.5.6
Channel 2 Transfer
7 6
0
5 4 3
2 1
0
AC-Link Operation
This section describes how to use the DCI in the AC-Link modes. The AC-Link modes
communicate with AC-’97 compliant codec devices.
20.5.6.1
AC-LINK DATA FRAME
The AC-Link data frame is 256 bits subdivided into one 16-bit control slot, followed by twelve
20-bit data slots. Figure 20-33 shows the AC-’97 codec usually provides the serial transfer clock
signal, which is derived from a crystal oscillator.
The controller receives the serial clock and generates the FS signal. The default data frame rate
is 48 kHz. The FS 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.
Figure 20-35 shows the data transfer begins one CSCK period after the rising edge of the FS
signal. Data is sampled by the receiving device on the falling edge of CSCK. Figure 20-34 shows
the control and data time slots in the AC-Link have defined uses in the protocol.
Figure 20-33: AC-Link Signal Connections
CSCK
CO
dsPIC33F
(AC ‘97 CSDO
Controller)
CSDI
I/O
DS70288C-page 20-38
BIT_CLK
24.576
MHz
SYNC
SDATA_OUT
SDATA_IN
AC ‘97
Codec
RESET
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Figure 20-34: AC-Link Data Frame
256
16 bits
20 bits
20 bits
20 bits
20 bits
20 bits
20 bits
20 bits
SYNC
SDATA_OUT
Tag
Frame
Command
Address
Command
Data
Slot 3
Left PCM
Data
Slot 4
Right PCM
Data
Slot 10
Line 2
DAC
Slot 11
Handset
DAC
Slot 12
Codec I/O
Control
SDATA_IN
Tag
Frame
Status
Address
Status
Data
Slot 3
Left PCM
Data
Slot 4
Right PCM
Data
Slot 10
Line 2
ADC
Slot 11
Handset
ADC
Slot 12
Codec I/O
Status
Figure 20-35: Frame Synchronization Timing, AC-Link Start of Frame
Frame Synch Edge Sampled
First bit of Data Frame Sampled
CSCK
S12
bit 2
Data
S12
bit 1
S12
LSb
Tag
Tag Tag
MSb bit 14 bit 13
CO
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 using the COFSM<1:0> control bits
(DCICON1<1:0>).
• To select the first AC-Link mode, called “6-bit AC-Link mode, set COFSM<1:0> = 10
• To select the second AC-Link mode, called 20-bit AC-Link mode, set COFSM<1:0> = 11
20.5.6.2
16-BIT AC-LINK MODE
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. This restriction only affects the 20-bit data time slots of
the AC-Link protocol. For received time slots, the incoming data is truncated to 16 bits. For
outgoing time slots, the module sets the 4 LSbs of the data word to ‘0’. This operating mode
simplifies the AC-Link data frame by treating every time slot as a 16-bit time slot. The FSG
maintains alignment to the time slot boundaries.
20.5.6.3
20-BIT AC-LINK MODE
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.
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> = 1111 and WS<3:0> = 1111. The data
alignment for 20-bit data slots is not maintained in this operating mode.
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-39
Data Converter
Interface (DCI)
The 20-bit AC-Link mode functions similarly to the Multi-Channel mode of the DCI module,
except for the duty cycle of the FS signal that is produced. The AC-Link FS signal should remain
high for 16 clock cycles and should be low for the following 240 cycles.
20
dsPIC33F/PIC24H Family Reference Manual
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 takes four 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:8>).
20.5.6.4
AC-LINK SETUP DETAILS
To enable AC-Link mode, write 10h or 11h to the COFSM<1:0> control bits in the DCICON1
SFR. The word size selection bits (WS<3:0>) and the FSG bits (COFSG<3:0>) have no effect for
the 16-bit 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 generates 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
TSEx and RSEx control bits in software accordingly. At a minimum, it is necessary to buffer the
transmit and receive tag slots. Therefore, set the TSCON<0> and RSCON<1> control bits in
software.
Note:
Only the TSCON<12:0> control bits and the RSCON<12:0> control bits have an
effect in the 16-bit AC-Link mode, since an AC-Link frame has 13 time slots.
To set up the module for AC-Link mode:
1.
2.
3.
4.
Configure the DCI to accept the serial transfer clock from the AC’97 codec. Set the
CSCKD control bit and clear the DCICON3 register.
Set the COFSM<1:0> control bits (DCICON1<1:0>) to ‘10b’ or ‘11b’ to set the desired
AC-Link Frame Synchronization mode.
Clear the COFSD control bit (DCICON1<8>), so the DCI outputs the FS signal.
Clear the CSCKE control bit (DCICON1<9>) to sample incoming data on the falling edge
of CSCK.
Note:
5.
6.
7.
8.
9.
DS70288C-page 20-40
The word size selection bits (WS<3:0>) and the FSG bits (COFSG<3:0>) have no
effect for the 16-bit and 20-bit AC-Link modes, since the frame and word sizes are
set by the protocol.
Clear the CSDOM control bit (DCICON1<6>).
Write the TSCON and RSCON registers to determine which data time slots in the frame
are to be transmitted and received, respectively. This depends on which data time slots in
the AC-Link protocol is used. At a minimum, communication on slot 0 (tag slot) is required.
For additional information, refer to 20.5.6.2 “16-bit AC-Link Mode”, 20.5.6.3 “20-bit
AC-Link Mode”.
Set the BLEN<1:0> control bits (DCICON2<11:10>) to buffer the desired amount of data
words. For the single channel codec, BLEN = 00 provides an interrupt at each data frame.
A higher value of BLEN<1:0> could be used for this codec to buffer multiple samples
between interrupts.
If interrupts are to be used, clear the DCIIF status bit (IFS2<9>) and set the DCIIE control
bit (IEC2<9>).
Begin operation as described in 20.5.1.1 “DCI Start-up and Data Buffering”.
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.6
DCI CONFIGURATION CODE EXAMPLE
This section describes the configuration of the DCI module for operation in Slave mode with a
16-bit codec. Figure 20-36 shows the timing diagram for the codec. The control registers of the
codec can be accessed by inputting a control word 16 clock cycles after the data word is
received. The codec also outputs a status word 16 clock cycles after the data word is transmitted.
The codec is configured to be a master and will drive the COFS and CSCK pins of the DCI
module.
Figure 20-36: Codec Timing Diagram for DCI Configuration Code Example
1 FRAME
16 Clock Cycles
16 Clock Cycles
16 Clock Cycles
SCK
SDO
Time Slot 0 – 16-bit Data Word
Time Slot 2 – 16-bit Status Word
SDI
Time Slot 0 – 16-bit Data Word
Time Slot 2 – 16-bit Control Word
Since the codec transmits and receives the same number of time slots in a frame
(TSCON = RSCON), the user application can write to successive TXBUF registers to transmit
data and read from successive RXBUF registers.
Example 20-1 shows the code example for configuring the DCI module to interface with this
codec. The code example sets up the DCI module to interrupt at two-word intervals
(BLEN<1:0> = 1). The application must write to two buffers or read from two buffers per interrupt
in this scheme.
Alternatively, the user application could set up the module to interrupt at one-word intervals
(BLEN<1:0> = 0). This results in two interrupts per frame and requires the user application to
process only one buffer per interrupt.
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-41
dsPIC33F/PIC24H Family Reference Manual
Example 20-1:
DCI Configuration Code Example
#include "p33Fxxxx.h"
/* Device configuration registers */
_FGS(GWRP_OFF & GCP_OFF);
_FOSCSEL(FNOSC_PRIPLL);
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
_FWDT(FWDTEN_OFF);
int main(void)
{
RSCONbits.RSE2=1;
RSCONbits.RSE0=1;
/* Enable Receive Time Slot 2 */
/* Enable Receive Time Slot 0 */
TSCONbits.TSE2=1;
TSCONbits.TSE0=1;
/* Enable Transmit Time Slot 2 */
/* Enable Transmit Time Slot 0 */
DCICON1bits.COFSM = 0;
DCICON1bits.DJST = 0;
DCICON1bits.CSCKE = 0;
DCICON1bits.COFSD = 1;
DCICON1bits.CSCKD = 1;
/*
/*
/*
/*
/*
Multichannel Frame Sync mode */
Data TX/RX is begun one serial clock cycle after frame sync pulse */
Data changes on rising edge sampled on falling edge of CSCK */
Frame sync driven by codec */
Clock is input to DCI from codec */
DCICON2bits.BLEN = 1; /* Two data words will be buffered between interrupts */
DCICON2bits.COFSG = 2; /* Data frame has 3 words */
DCICON2bits.WS = 15;
/* Data word size is 16 bits*/
DCICON3 = 0;
/* BCG value is zero since clock is driven by codec */
IPC15bits.DCIIP=6;
IFS3bits.DCIIF=0;
IEC3bits.DCIIE=0;
/* Enable the interrupts */
TXBUF0= 0x0001;
TXBUF1= 0x0002;
/* This is the data word */
/* This is the control word */
DCICON1bits.DCIEN = 1;/* Enable the module */
while(1);
}
void __attribute__((__interrupt__, no_auto_psv)) _DCIInterrupt(void)
{
int dataWord;
int statusWord;
IFS3bits.DCIIF = 0;
TXBUF0 = 0x0001;
TXBUF1 = 0x0002;
/* Write some data */
/* This is the control word */
dataWord = RXBUF0;
statusWord = RXBUF1;
/* Read the data word */
/* Read the status word */
}
DS70288C-page 20-42
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.7
DATA TRANSFER TO DCI MODULE BUFFERS USING DMA
The Direct Memory Access (DMA) module on dsPIC33F devices can be used to transfer data
from DPSRAM to the DCI module buffers without user application intervention. Minimum two
DMA channels are required for this purpose: one DMA channel reads data from the receive
registers while the other channel writes data to the transmit registers. Both DMA channels use
the DCI Transfer Done interrupt.
Since the DCI RXBUF and TXBUF registers are 16-bit registers, the DMA channels should be
set up for word transfer. To write byte values to the DCI module, user software must left-shift them
to the upper byte of the word.
Example 20-2 shows the code that configures the DMA for continuous Ping-Pong Buffer mode.
Figure 20-37 shows the timing diagram of the DCI codec communication. In Ping-Pong Buffer
mode, the DMA module alternates the memory locations where the data frames are stored. This
mechanism facilitates processing on one data frame while a processed data frame is being
transmitted and a new data frame is being received. The DCI module requests the DMA module
for a transfer on every transfer complete interrupt.
For additional information on the DMA module, refer to Section 22. “Direct Memory Access
(DMA)” (DS70182).
Figure 20-37: Codec Timing Diagram for DCI-DMA Code Example
1 FRAME
16 Clock Cycles
16 Clock Cycles
SCK
SDO
Time Slot 0 – 16-bit Data Word (TXBUF0)
Time Slot 0 – 16-bit Status Word (TXBUF0)
SDI
Time Slot 0 – 16-bit Data Word (RXBUF0)
Time Slot 0 – 16-bit Control Word (RXBUF0)
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-43
dsPIC33F/PIC24H Family Reference Manual
Example 20-2:
Data Transfer to DCI Module Buffers Using DMA Code Example
#include "p33Fxxxx.h"
/* Device configuration registers */
_FGS(GWRP_OFF & GCP_OFF);
_FOSCSEL(FNOSC_PRIPLL);
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
_FWDT(FWDTEN_OFF);
#define
#define
#define
#define
int
int
int
int
FCY 40000000
CODEC_SAMPLE_RATE 8000
DCI_BCG_VALUE( ( (FCY/32) / CODEC_SAMPLE_RATE ) - 1 )
FRAME 80
txBufferA[FRAME]
txBufferB[FRAME]
rxBufferA[FRAME]
rxBufferB[FRAME]
__attribute__((space(dma)));
__attribute__((space(dma)));
__attribute__((space(dma)));
__attribute__((space(dma)));
volatile int rxBufferIndicator = 0;
void DCIInit(void);
void processRxData(int * sourceBuffer, int * targetBuffer);
void DMAInit(void);
int main (void)
{
CLKDIV = 0;
/* Set up for 40 MIPS */
PLLFBD = 30;
while (!OSCCONbits.LOCK);
DMAInit();
DCIInit();
while(1);
}
void DCIInit(void)
{
TSCON = 0x0001;
RSCON = 0x0001;
/* Only one transmit time slot */
/* Only one receive time slot */
DCICON1 = 0;
DCICON1bits.DCIEN = 1;
DCICON1bits.DCISIDL = 0;
DCICON1bits.DLOOP = 0;
DCICON1bits.CSCKD = 0;
DCICON1bits.CSCKE = 0;
DCICON1bits.COFSD = 0;
DCICON1bits.UNFM = 0;
DCICON1bits.CSDOM = 0;
DCICON1bits.DJST = 1;
DCICON1bits.COFSM = 0;
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
DCICON2 = 0;
DCICON2bits.BLEN = 0;
DCICON2bits.COFSG = 0;
DCICON2bits.WS = 0xF;
/* Interrupt on one buffer */
/* Data frame has one word */
/* Word size is 16 bits */
Module is enabled */
Continue operation in idle */
Loopback mode is disabled */
DCI is master - CSCK is output */
Data is sampled on falling edge */
DCI is master - COFS is output */
Transmit zeroes on TX underflow */
Transmit 0 on disabled time slots */
COFS and CSDO start together */
DCI mode is multi-channel FS mode */
DCICON3 = DCI_BCG_VALUE;
_DCIIE = 0;
/* Disabled since DMA is used */
}
void DMAInit(void)
{
/* DMA 0 - DPSRAM to DCI */
DS70288C-page 20-44
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
Example 20-2:
Data Transfer to DCI Module Buffers Using DMA Code Example (Continued)
DMA0CONbits.SIZE = 0;
/*
DMA0CONbits.DIR = 1;
/*
DMA0CONbits.AMODE = 0;
/*
DMA0CONbits.MODE = 2;
/*
DMA0CONbits.HALF = 0;
/*
DMA0CONbits.NULLW = 0;
DMA0REQbits.FORCE = 0;
/*
DMA0REQbits.IRQSEL = 0x3C;/*
Word transfers */
From DPSRAM to DCI */
Register Indirect with post-increment mode */
Continuous ping pong mode enabled */
Interrupt when all the data has been moved */
Automatic transfer */
Codec transfer done */
DMA0STA =__builtin_dmaoffset(txBufferA);
DMA0STB =__builtin_dmaoffset(txBufferB);
DMA0PAD = (int)&TXBUF0;
DMA0CNT = FRAME-1;
/* DMA 2 - DCI to DPSRAM */
DMA2CONbits.SIZE = 0;
DMA2CONbits.DIR = 0;
DMA2CONbits.HALF = 0;
DMA2CONbits.NULLW = 0;
DMA2CONbits.AMODE = 0;
DMA2CONbits.MODE = 2;
/*
/*
/*
/*
/*
/*
Word transfers */
From DCI to DPSRAM */
Interrupt when all the data has been moved */
No NULL writes - Normal Operation */
Register Indirect with post-increment mode */
Continuous mode ping pong mode enabled */
DMA2REQbits.FORCE = 0;
/* Automatic transfer */
DMA2REQbits.IRQSEL = 0x3C;/* Codec transfer done */
DMA2STA =__builtin_dmaoffset(rxBufferA);
DMA2STB =__builtin_dmaoffset(rxBufferB);
DMA2PAD = (int)&RXBUF0;
DMA2CNT = FRAME-1;
_DMA2IP = 5;
_DMA2IE = 1;
DMA0CONbits.CHEN = 1;
DMA2CONbits.CHEN = 1;
/* Enable the channel */
}
void processRxData(int * sourceBuffer, int * targetBuffer)
{
/* This procedure loops back the received data to the */
/* the codec output. The user application could process */
/* this data as per application requirements. */
int index;
for(index = 0;index < FRAME;index ++)
{
targetBuffer[index] = sourceBuffer[index];
}
}
void __attribute__((__interrupt__,no_auto_psv)) _DMA2Interrupt(void)
{
_DMA2IF = 0;
/* Received one frame of data */
if(rxBufferIndicator == 0)
{
processRxData(rxBufferA,txBufferA);
}
else
{
processRxData(rxBufferB,txBufferB);
}
rxBufferIndicator ^= 1;
/* Toggle the indicator */
20
Data Converter
Interface (DCI)
}
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-45
dsPIC33F/PIC24H Family Reference Manual
20.8
OPERATION IN POWER-SAVING MODES
20.8.1
CPU Idle Mode
The DCI module can optionally continue to operate while the CPU is in Idle mode. The DCISIDL
control bit (DCICON1<13>) determines whether the DCI module operates when the CPU is in
Idle mode.
• If the DCISIDL control bit is cleared (default), the module continues to operate normally in
Idle mode
• If the DCISIDL bit is set, the module halts when the CPU enters Idle mode
20.8.2
Sleep Mode
The DCI will not operate while the device is in Sleep mode if the CSCK signal is derived from the
device instruction clock, TCY.
However, the DCI module can operate while in Sleep mode and wake the CPU when the CSCK
signal is supplied by an external device (CSCKD = 1). The DCI Interrupt Enable bit, DCIIE, must
be set to allow a wake-up event from Sleep mode. When the DCI Interrupt Flag, DCIIF, is set, the
device wakes up from Sleep mode. If the DCI interrupt priority level is greater than the current
CPU priority, program execution resumes from the DCI ISR. Otherwise, execution resumes with
the instruction following the PWRSAV instruction that previously entered Sleep mode.
20.8.3
Doze Mode
The DCI module is not affected by Doze mode. However, the processor may not have sufficient
time to respond to a DCI interrupt while in Doze mode.
DS70288C-page 20-46
© 2007-2012 Microchip Technology Inc.
© 2007-2012 Microchip Technology Inc.
20.9
REGISTERS ASSOCIATED WITH DCI
Table 20-2 lists the registers associated with the DCI module.
Table 20-2:
Name
DCI Register Map
Bit 15
Bit 14
Bit 13
Bit 12
Bit 11
Bit 10
Bit 9
Bit 8
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
DCICON1
DCIEN
—
DCISIDL
—
DLOOP
CSCKD
CSCKE
COFSD
UNFM
CSDOM
DJST
—
—
—
DCICON2
—
—
—
—
DCICON3
—
—
—
—
BLEN<1:0>
—
COFSG<3:0>
—
Bit 1
Bit 0
COFSM<1:0>
WS<3:0>
0000
0000
BCG<11:0>
0000
—
—
—
—
—
—
—
—
ROV
RFUL
TUNF
TMPTY
0000
TSCON
TSE15
TSE14
TSE13
TSE12
TSE11
TSE10
TSE9
TSE8
TSE7
TSE6
TSE5
TSE4
TSE3
TSE2
TSE1
TSE0
0000
RSCON
RSE15
RSE14
RSE13
RSE12
RSE11
RSE10
RSE9
RSE8
RSE7
RSE6
RSE5
RSE4
RSE3
RSE2
RSE1
RSE0
0000
DCISTAT
SLOT<3:0>
All
Resets
Receive 0 Data Register
0000
RXBUF1
Receive 1 Data Register
0000
RXBUF2
Receive 2 Data Register
0000
RXBUF3
Receive 3 Data Register
0000
TXBUF0
Transmit 0 Data Register
0000
TXBUF1
Transmit 1 Data Register
0000
TXBUF2
Transmit 2 Data Register
0000
TXBUF3
Transmit 3 Data Register
0000
Legend:
— = unimplemented, read as ‘0’. Reset values are shown in hexadecimal.
DS70288C-page 20-47
Section 20. Data Converter Interface (DCI)
RXBUF0
20
Data Converter
Interface (DCI)
dsPIC33F/PIC24H Family Reference Manual
20.10
RELATED APPLICATION NOTES
This section lists Application Notes that are related to this section of the manual. These
application notes may not be written specifically for the dsPIC33F/PIC24H device family, but the
concepts are pertinent and could be used with modification and possible limitations. The current
application notes related to the DCI module are:
Title
Application Note #
No related application notes at this time.
Note:
DS70288C-page 20-48
For additional Application Notes and code examples for the dsPIC33F/PIC24H
device family, visit the Microchip web site (www.microchip.com).
© 2007-2012 Microchip Technology Inc.
Section 20. Data Converter Interface (DCI)
20.11
REVISION HISTORY
Revision A (May 2007)
This is the initial released version of this document.
Revision B (September 2008)
This revision incorporates the following content updates:
• Figures:
- Data Packing Example for Long Data Words (see Figure 20-26): TXBUF0 contents
reads the Data Word as 23:8.
• Additional minor corrections such as language and formatting updates are incorporated in
the entire document.
Revision B (March 2012)
This revision includes the following updates:
•
•
•
•
•
•
Updated the I2S Interface Frame Synchronization Timing diagram (see Figure 20-30)
Updated the second paragraph in 20.5.5.1 “I2S Setup Details”
Removed the IFS2, IEC2, and IPC10 SFRs from the DCI Register Map (see Table 20-2)
Removed 20.10 “Design Tips”
References to the PIC24H device family were added
Additional updates to text and formatting were incorporated throughout the document
20
Data Converter
Interface (DCI)
© 2007-2012 Microchip Technology Inc.
DS70288C-page 20-49
dsPIC33F/PIC24H Family Reference Manual
NOTES:
DS70288C-page 20-50
© 2007-2012 Microchip Technology Inc.
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC,
KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART,
PIC32 logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor,
MXDEV, MXLAB, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip
Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, chipKIT,
chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net,
dsPICworks, dsSPEAK, ECAN, ECONOMONITOR,
FanSense, HI-TIDE, In-Circuit Serial Programming, ICSP,
Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB,
MPLINK, mTouch, Omniscient Code Generation, PICC,
PICC-18, PICDEM, PICDEM.net, PICkit, PICtail, REAL ICE,
rfLAB, Select Mode, Total Endurance, TSHARC,
UniWinDriver, WiperLock and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2007-2012, Microchip Technology Incorporated, Printed in
the U.S.A., All Rights Reserved.
Printed on recycled paper.
ISBN: 978-1-62076-127-4
QUALITY MANAGEMENT SYSTEM CERTIFIED BY DNV == ISO/TS 16949 == © 2007-2012 Microchip Technology Inc.
Microchip received ISO/TS-16949:2009 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
DS70288C-page -51
Worldwide Sales and Service
AMERICAS
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://www.microchip.com/
support
Web Address:
www.microchip.com
Asia Pacific Office
Suites 3707-14, 37th Floor
Tower 6, The Gateway
Harbour City, Kowloon
Hong Kong
Tel: 852-2401-1200
Fax: 852-2401-3431
India - Bangalore
Tel: 91-80-3090-4444
Fax: 91-80-3090-4123
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Japan - Osaka
Tel: 81-66-152-7160
Fax: 81-66-152-9310
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Cleveland
Independence, OH
Tel: 216-447-0464
Fax: 216-447-0643
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Indianapolis
Noblesville, IN
Tel: 317-773-8323
Fax: 317-773-5453
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8569-7000
Fax: 86-10-8528-2104
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
China - Chongqing
Tel: 86-23-8980-9588
Fax: 86-23-8980-9500
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
China - Hangzhou
Tel: 86-571-2819-3187
Fax: 86-571-2819-3189
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
Malaysia - Kuala Lumpur
Tel: 60-3-6201-9857
Fax: 60-3-6201-9859
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
Taiwan - Hsin Chu
Tel: 886-3-5778-366
Fax: 886-3-5770-955
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-330-9305
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
China - Xiamen
Tel: 86-592-2388138
Fax: 86-592-2388130
China - Zhuhai
Tel: 86-756-3210040
Fax: 86-756-3210049
DS70288C-page 20-52
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
11/29/11
© 2007-2012 Microchip Technology Inc.