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 DMA Setup Configuration (DMA4).
Table 1. DMA Setup Configuration (DMA4)
DMA4 Setup
SSA Source Address Beginning of ping buffer OR pong buffer (reconfigured in software)
SSZ Source Size 256 (1 bank for ping buffer OR pong buffer)
SMR Source Memory Region GPR
SMODE Source Address Mode SPTR is incremented
DSA Destination Address &SPI1TXB
DSZ Destination Size 1
DMODE Destination Address Mode DPTR remains unchanged
SIRQEN Start Trigger Enable Yes
SIRQ Start Trigger SPI1TX (SPI1 TX FIFO is not full)
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 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. 1.1.Send the write enable command to the flash module.
    2. 1.2.Pull the chip select line low and send the Page Program command to the flash module..
    3. 1.3.Send the write address (the address to write to in the external memory) to the flash module
    4. 1.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. 1.5.Set SPI transmit counter to 256.
  2. 2.Set SSA to the beginning of the ping buffer (or pong buffer, whichever is appropriate).
  3. 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. 4.After the entire ping (or pong) buffer is transferred out through SPI, the write operation can be closed by following these steps:
    1. 4.1.Reset SPI to operate in Full-duplex mode.
    2. 4.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. 4.3.Release chip select line.
    4. 4.4.Update write address location and number of pages written in the metadata.
  5. 5.Wait for another buffer full signal in software to transfer another buffer.