13.4.9.2 Fixed to Block
In Fixed to Block mode, the source address remains unchanged throughout the transfer, but the destination address is incremented or decremented (depending on the DAMODEx setting). This works well for receiving data from the single-word buffer of a serial communication peripheral and filling a block of addresses designated as a buffer.
Code for Fixed to Block Continuous Transfer (Peripheral to Memory) shows sample code for Fixed to Block Addressing. The source address (UART receive) generates an interrupt when the UART buffer has received four bytes; the UART Receive Interrupt Flag (U2RIF) will trigger the transfer.
Code for Fixed to Block Continuous Transfer (Peripheral to Memory)
void UartInit(void);
unsigned char Array[1000];
int i;
int main()
{
ANSELA = 0;
UartInit();
for (i = 0; i < 100; i++)
{
Array[i] = 0; //fill array with 0
}
DMA0CH = 0;
IFS2bits.DMA0IF = 0;
DMACONbits.ON = 1; //Enables DMA module
DMAHIGH = 0x5000; //sets lower and upper address limit
DMALOW = 0x4000;
DMA0SRC = (unsigned int) &U2RXREG; //load source address
DMA0DST = (unsigned int) & Array; // load destination address
DMA0CNT = 4; //4 bytes are transferred per trigger
DMA0CHbits.SIZE = 0; //Per count 1 byte is transferred
DMA0CHbits.SAMODE = 0; //Source address increment mode,
DMA0CHbits.DAMODE = 1; //Destination address increment mode,
//increment 1
DMA0CHbits.TRMODE = 3; //Transfer mode Continuous
DMA0SELbits.CHSEL = 17; //Trigger on UART2 Receive
DMA0CHbits.CHEN = 1; //Channel enable
while (!DMA0STATbits.DONE); //DONE=1,DMA0IF=1 and
//transfer complete with one trigger
IFS2bits.DMA0IF = 0; //Disable interrupt flag
while(1);
}
void UartInit(void)
{
RPINR9bits.U2RXR = 10; //U2RX
U2BRG = 100; //BAUDRATEREG2;
U2CON = 0;
U2STAT = 0;
U2CONbits.BRGS = 1; //High Baud Rate Select
U2CONbits.MODE = 0; //Asynchronous 8-bit UART
U2STATbits.RXWM = 3; //Interrupt after 4 transfers
U2CONbits.UARTEN = 1;
U2CONbits.URXEN = 1;
U2CONbits.TXEN = 1;
IFS2bits.U2RXIF = 0;
}