3.2 Data Transfer from Ping-Pong Buffers to External Memory

Data stored in the ping-pong buffers by the ADC can be seamlessly transferred to external memory using DMA and SPI. 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-2.
Table 3-2. DMA Setup Configuration (DMA4)
DMA4 Setup
SSASource AddressBeginning of ping buffer OR pong buffer (reconfigured in software)
SSZSource Size256 (1 bank for ping buffer OR pong buffer)
SMRSource Memory RegionGPR
SMODESource Address ModeSPTR is incremented
DSADestination Address&SPI1TXB
DSZDestination Size1
DMODEDestination Address ModeDPTR remains unchanged
SIRQENStart Trigger EnableYes
SIRQStart TriggerSPI1TX (SPI1 TX FIFO is not full)
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 that the microcontroller and the external memory are ready to transmit and receive 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. Send the write enable command to the Flash module.
    2. Pull the chip select line low and send the Page Program command to the Flash module.
    3. Send the write address (the address to write to in the external memory) to the Flash module.
    4. Set SPI to operate in Transmit-only mode in PIC18F57Q43. This allows the device to send bursts of data without waiting for any data in return.
    5. Set SPI transmit counter to 256.
  2. Set SSA to the beginning of the ping buffer (or pong buffer, whichever is appropriate).
  3. Enable the DMA and SIRQEN. This will kick off DMA transfers until the SPI transmit counter becomes zero. At the same time, the SCNT reloads and SIRQEN is cleared by the hardware, preventing further transfers.
  4. After the entire ping (or pong) buffer is transferred out through SPI, the write operation can be closed by following these steps:
    1. Reset SPI to operate in Full-duplex mode.
    2. Update the next source register to pong (or ping). This ensures the SSA is loaded with the correct buffer address for the next transaction.
    3. Release the chip select line.
    4. Update write address location and number of pages written in the metadata.
  5. Wait for another buffer full signal in software to transfer another buffer.