Care must be taken if the transmitter expects a
frame sync from an external device. After the transmitter comes out of reset (XRST =
1), the transmitter waits for a frame sync from the external device. If the first
frame sync arrives very shortly after the transmitter is enabled, the CPU or DMA
controller cannot have a chance to service DXR. In this case, the transmitter shifts
out the default data in XSR instead of the desired value, which has not yet arrived
in DXR. This causes problems in some applications, as the first data element in the
frame is invalid. The data stream appears element-shifted (the first data word can
appear in the second channel instead of the first).
To make sure of proper operation when the external
device is the frame master,
you must verify that DXR is already serviced with the first word when a frame sync
occurs. To do so, you can keep the transmitter in reset until the first frame sync
is detected. Upon detection of the first frame sync, the McBSP generates an
interrupt to the CPU. Within the interrupt service routine, the transmitter is taken
out of reset (XRST = 1). This verifies that the transmitter does not begin data
transfers at the data pin during the first frame sync period. This also provides
almost an entire frame period for the DSP to service DXR with the first word before
the second frame sync occurs. The transmitter only begins data transfers upon
receiving the second frame sync. At this point, DXR is already serviced with the
first word.
The interrupt service
routine must first be setup, then follow this modified procedure for proper
initialization:
- Make sure that no portion of
the McBSP is using the internal sample rate generator signal CLKG and the
internal frame sync generator signal FSG (GRST = FRST = 0). The respective
portion of the McBSP needs to be in reset (XRST = 0 and/or RRST = 0).
- Program SRGR and other
control registers as required. Make sure the internal sample rate generator
and the internal frame sync generator are still in reset (GRST = FRST = 0).
Also make sure the respective portion of the McBSP is still in reset in this
step (XRST = 0 and/or RRST = 0).
- Program the XINTM bits to 2h
in SPCR to generate an interrupt to the CPU upon detection of a transmit
frame sync. Do not enable the XINT interrupt in the interrupt enable
register (IER) in this step.
- Wait for proper internal
synchronization. If the external device provides the bit clock, wait for two
CLKR or CLKX cycles. If the McBSP generates the bit clock as a master clock, wait
for two CLKSRG cycles. In this case, the clock source to the sample rate
generator (CLKSRG) is selected by the CLKSM bit in SRGR.
- Skip this step if the bit
clock is provided by the external device. This step only applies if the
McBSP is the bit master clock and the internal sample rate generator is used.
- Start the sample rate
generator by setting the GRST bit to 1. Wait two CLKG bit clocks for
synchronization. CLKG is the output of the sample rate
generator.
- On the next rising
edge of CLKSRG, CLKG transitions to 1 and starts clocking with a
frequency equal to 1/(CLKGDV + 1) of the sample rate generator
source clock CLKSRG.
- A transmit sync error
(XSYNCERR) can occur when enabled for the first time after device reset. The
purpose of this step is to clear any potential XSYNCERR that occurs on the
transmitter at this time:
- Set the XRST bit to 1
to enable the transmitter.
- Wait for any
unexpected frame sync error to occur. If the external device
provides the bit clock, wait for two CLKR or CLKX cycles. If the
McBSP generates the bit clock as a master
clock, wait for two CLKG cycles. The unexpected frame sync error
(XSYNCERR), if any, occurs within this time period.
- Disable the
transmitter (XRST = 0). This clears any outstanding XSYNCERR.
- Setup data acquisition as
required:
- If the DMA controller
is used to service the McBSP, setup data acquisition as desired and
start the DMA controller in this step, before the McBSP is taken out
of reset.
- If CPU interrupt is
used to service the McBSP, no action is required in this step.
- If CPU polling is
used to service the McBSP, no action is required in this step.
- Enable the XINT interrupt by
setting the corresponding bit in the interrupt enable register (IER). In
this step, the McBSP transmitter is still in reset. Upon detection of the
first transmit frame sync from the external device, the McBSP generates an
interrupt to the CPU and the DSP enters the interrupt service routine (ISR).
The ISR needs to perform these tasks in this order:
- Modify the XINTM bits
to the value desired for normal McBSP operations. If CPU interrupt
is used to service the McBSP in normal operations, make sure that
the XINTM bits are modified to 0 to detect the McBSP XRDY event. If
no McBSP interrupt is desired in normal operations, disable future
McBSP-to-CPU interrupt in the interrupt enable register (IER).
- Set the XRST bit
and/or the RRST bit to 1 to enable the respective portion of the
McBSP. The McBSP is now ready to transmit and/or receive.
- Service the McBSP:
- If CPU polling is
used to service the McBSP in normal operations, CPU polling can do
so upon exit from the ISR.
- If CPU interrupt is
used to service the McBSP in normal operations, upon XRDY interrupt
service routine is entered. The ISR must be setup to verify that
XRDY = 1 and service the McBSP accordingly.
- If DMA controller is
used to service the McBSP in normal operations, the DMA controller
services the McBSP automatically upon receiving the XEVT and/or
REVT.
- Upon detection of the second
frame sync, DXR is already serviced and the transmitter is ready to transmit
the valid data. The receiver is also serviced properly by the DSP.