13.4.8.5 Repeated Continuous Mode

Repeated Continuous mode (TRMODE[1:0] = 11) can be thought of as a combination of Continuous and Repeated One-Shot modes; data transfers keep occurring as long as triggers are provided, and multiple transfers can occur with each trigger. Like Continuous mode, each transfer decrements DMAxCNT. When it reaches 0000h, the address and count registers are reloaded, and the process is repeated.

Like Repeated One-Shot mode, ending the sequence requires disabling the channel, either by disabling the trigger source or clearing the CHEN bit in software.

Typical Code Sequence for a Repeated Continuous Transfer (Memory to Memory, RELOADS = 1, RELOADD = 1) shows a typical code sequence for a Repeated Continuous mode transfer.

Typical Code Sequence for a Repeated Continuous Transfer (Memory to Memory, RELOADS = 1, RELOADD = 1)

unsigned int Array1[100];
unsigned int Array2[100];
int i;
int main()
{
   ANSA=0;
   TRISA=0;
   LATA=0x70;
   for (i=0;i<100;i++)
   {
      Array1[i]=i+1;	              //fill with i+1
      Array2[i]=0;	                //fill with 0
   }
   DMACONbits.ON=1;
   DMACONbits.PRIORITY=1;
   DMALOW=0x4000;
   DMAHIGH=0x7FFF;	                //set lower and upper address limit
   DMA0SRC=(unsigned int)& Array1;	// load the source address
   DMA0DST=(unsigned int)& Array2;	// load destination address
   DMA0CNT=100;	                   // 100 Transaction per trigger
   DMA0CH=0;
   DMA0CHbits.SAMODE=1; 	          //Source address increment mode
   DMA0CHbits.DAMODE=1; 	          //Destination address increment mode
   DMA0CHbits.TRMODE=3; 	          //Transfer mode Repeat continous
   DMA0CHbits.RELOADS=1; 	         //Reload Source Address
   DMA0CHbits.RELOADD=1; 	         //Reload Destination Address
   DMA0CHbits.CHEN=1;  	           //Channel enable
   IFS3bits.DMA0IF=0;
   while(1)
   {
      DMA0CHbits.CHREQ=1;  	       //TRIGGER
      while(!IFS3bits.DMA0IF);
      for (i=0;i<100;i++)	         //Clear the Destination Memory
      {
         Array2[i]=0;	             //fill with 0
      }
      IFS3bits.DMA0IF=0;
      PORTAbits.RA0=0;
      DMA0STATbits.DONE=0;
      DMA0STATbits.HALF=0;
   }
}