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 1. DMA Setup Configuration (DMA3)
DMA3 Setup
SSA Source Address &SPI1RXB
SSZ Source Size 256 (1 page data from external memory)
SMR Source Memory Region SFR
SMODE Source Address Mode SPTR remains unchanged
DSA Destination Address &DAC1DATL
DSZ Destination Size 1
DMODE Destination Address Mode DPTR remains unchanged
SIRQEN Start Trigger Enable Yes
SIRQ Start Trigger TMR0 (sampling timer)
SSTP Source Counter Reload Stop Yes - SIRQEN is cleared when source counter reloads
DSTP Destination Counter Reload Stop No - SIRQEN not cleared
AIRQEN Abort Trigger Enable No (stops when DCNT reloads)
AIRQ Abort Trigger N/A
How It Works:
  1. 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. 1.1.Pull the chip select line low and send the Read command to the flash module.
    2. 1.2.Send the read address (the address to read from the external memory) to the flash module.
    3. 1.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. 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. 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.