13.4.8.4 Continuous Mode

In Continuous mode (TRMODE[1:0] = 10), a single trigger starts a sequence of back-to-back transfers; these continue with each transfer decrementing DMAxCNT until it reaches 0000h. At this point, like One-Shot mode, the channel is disabled.

One-Shot and Continuous modes are similar in that each mode performs a certain number of transfers for one time. The difference is that One-Shot mode requires a trigger for each transfer, while Continuous mode allows many transfers for each trigger. In addition, DMAxCNT is controlled by the number of individual transactions, not the number of triggers.

Typical Code Sequence for a Continuous Transfer shows a typical code sequence for a Continuous transfer.

Typical Code Sequence for a Continuous Transfer

unsigned int Array1[100];
unsigned int Array2[100];

int main()
{
    for (int i=0; i<100; i++)
    {
        Array1[i]=i+1;         //fill with i+1
        Array2[i]=0;           //fill with 0
    }
    
    DMACONbits.ON=1;           //Enable DMA
    
    //Set lower and upper address limit
    DMAHIGH=0x5000;
    DMALOW=0x4000;
    
    DMA0SRC=(unsigned int)& Array1;        // load the source address
    DMA0DST=(unsigned int)& Array2;        // load destination address
    DMA0CNT=100;                           // 100 Transactions per trigger
    
    DMA0CH=0;
    DMA0CHbits.SAMODE=1;                   //Source address increment mode
    DMA0CHbits.DAMODE=1;                   //Destination address increment mode
    DMA0CHbits.TRMODE=2;                   //Transfer mode Continuous
    DMA0CHbits.DONEEN=1;                   //Enable interrupt on DONE being set
    DMA0CHbits.SIZE=2;                     //One 32-bit word transferred at a time
    DMA0CHbits.CHEN=1;                     //Channel enable
    
    IFS2bits.DMA0IF=0; 
    DMA0CHbits.CHREQ=1;                    //Enable the transfer by software trigger
    while(!DMA0STATbits.HALF);             //HALF=1 is set when DMA0CNT reaches halfway
    while(!IFS2bits.DMA0IF);               //DONE=1;CHAEN=0,DMA0IF=1 
    //100 (DMAXCNT=100) transfers complete with one trigger
    
    IFS2bits.DMA0IF=0;
    
    while(1);
}