13.4.8.2 One-Shot Mode

In One-Shot mode (TRMODE[1:0] = 00), a single transfer (from DMAxSRC to DMAxDST) is performed for each trigger event. By default, the Reset value of DMAxCNT is 0001h. When a single One-Shot transfer occurs, DMAxCNT is decremented to 0000h; this disables the channel and requires the channel to be re-enabled to perform the next transaction. Of course, it is also possible to store a larger value in DMAxCNT and then conduct a defined number of One-Shot transfers.

Typical Code Sequence for a One-Shot Transfer shows a typical code sequence for a One-Shot transfer.

Typical Code Sequence for a One-Shot Transfer

unsigned int SRC[4];
unsigned int DEST[4];
int main()
{
    for (int i=0;i<4;i++)
    {
        SRC[i]=i+1; 					//fill with i+1
        DEST[i]=0; 					 //fill with 0
    }
    DMACONbits.ON=1;
    DMACONbits.PRIORITY=1;
    IFS2bits.DMA0IF=0;
    DMALOW=0x4000;
    DMAHIGH=0x7FFF; 					 //set lower and upper address limit
    DMA0SRC=(unsigned int)& SRC; 			 //load the source address
    DMA0DST=(unsigned int)& DEST; 			//load destination address
    DMA0CNT=4; //Four Transfer to be done
    DMA0CH=0;
    DMA0CHbits.SAMODE=1; 				  //Source address increment mode
    DMA0CHbits.DAMODE=1; 				  //Destination address increment mode
    DMA0CHbits.TRMODE=0; 				  //One-Shot Transfer mode
    DMA0CHbits.SIZE = 2; 				  //32-bit transfer per count
    DMA0CHbits.CHEN=1; 				    //Enable channel
    DMA0CHbits.CHREQ=1; 				   //First trigger
    while(DMA0CHbits.CHREQ);
    DMA0CHbits.CHREQ=1; 				   //Second trigger
    while(DMA0CHbits.CHREQ);
    DMA0CHbits.CHREQ =1; 				  //Third trigger
    while(DMA0CHbits.CHREQ); 			    //HALF=1 since DMACNT is
    							   //at halfway point
    DMA0CHbits.CHREQ=1; 				  //Fourth trigger DMACNT=0
    						   	//and transfer complete
    while(DMA0CHbits.CHREQ);
    while(!DMA0STATbits.DONE); 			 //Transfer Complete
    							  //DMA0IF=1 ,DONE=1, CHEN=0;
    IFS2bits.DMA0IF=0;
    DMA0STATbits.DONE=0;
    DMA0STATbits.HALF=0;
    while(1);
}