3.4 Data Transfer from External Memory to DAC

Data stored in the external memory can be seamlessly transferred to DAC using DMA and SPI. The SPI can be configured to operate at an appropriate frequency (about 1 MHz) and in mode 0 (active high clock, active to idle clock edge, input data sampled at the end). The DMA setup configurations are listed in Table 3-4.

Table 3-4. DMA Setup Configuration (DMA3)
DMA3 Setup
SSASource Address&SPI1RXB
SSZSource Size256 (1 page data from external memory)
SMRSource Memory RegionSFR
SMODESource Address ModeSPTR remains unchanged
DSADestination Address&DAC1DATL
DSZDestination Size1
DMODEDestination Address ModeDPTR remains unchanged
SIRQENStart Trigger EnableYes
SIRQStart TriggerTMR0 (sampling timer)
SSTPSource Counter Reload StopYes - SIRQEN is cleared when source counter reloads
DSTPDestination Counter Reload StopNo - SIRQEN not cleared
AIRQENAbort Trigger EnableNo (stops when DCNT reloads)
AIRQAbort TriggerN/A
How It Works:
  1. Before starting the DMA transfer, ensure the microcontroller and external memory are ready to receive and transmit data. To prepare the PIC18F57Q43 microcontroller and SST26VF064B Flash module on Flash 2 Click Board™, the following steps are required (refer to Hardware Setup Using Curiosity Nano Evaluation Kit for hardware connection between the microcontroller and the Flash module):
    1. Pull the chip select line low and send the Read command to the Flash module.
    2. Send the read address (the address to read from the external memory) to the Flash module.
    3. Set SPI to operate in Receive-only mode in PIC18F57Q43. This allows the device to receive bursts of data without sending any data in return.
  2. Set SPI transmit counter to 256. This immediately kicks off the SPI. Enable SIRQEN to kick off DMA at the next timer overflow. The DMA and SPI transmit stop when SPI transmit counter depletes to zero (and coincidentally SCNT reloads, clearing SIRQEN). The address pointer in the external memory module is incremented automatically. Repeat this step to read as many pages of stored audio data.
  3. To close out the read operation, restore SPI to Full-duplex mode and release the chip select line.
Important: In Receive-only mode, SPI operations are suspended when the RXFIFO becomes full. In this application, the SPI operation resumes only when RXFIFO is read by the DMA (at the next TMR0 overflow event). This enables the playback and the data transfer rate from external memory to match the sampling rate.