UG-549
ADuCM310 Hardware Reference Manual
Rev. C | Page 150 of 192
Example Code to Set Up UART Receive DMA Channel
void UARTRXDMAINIT(void)
{
NVIC_EnableIRQ(DMA_UART_RX_IRQn);
// UArt Tx DMA interrupt enable
pADI_UART->COMLCR = COMLCR_WLS_EIGHTBITS | COMLCR_STOP;
// 8-data bits + 1 Stop bit.
pADI_UART->COMDIV = 0x41;
// Set UART Baud rate
pADI_UART->COMFBR = COMFBR_FBEN_EN | 0x803;
// DIVM = 1, DIVN = 3.
pADI_GP1->GPCON = 0x5;
// Configure P1.0/P1.1 for UART
Dma_Init();
pADI_DMA->DMACFG = 0x1;
UARTDMAREAD(uxUARTRXData, 4);
// Enable DMA mode in DMA controller
pADI_DMA->DMAENSET = 0x20;
// Enable UART_RX_DMA Channel
pADI_UART->COMIEN = 0x20;
// Enable DMA Rx transfers
}
void UARTDMAREAD(unsigned char *pucRX_DMA, unsigned int iNumVals)
{
DmaDesc Desc;
// Common configuration of all the descriptors used here
Desc.ctrlCfg.bits.cycle_ctrl = DMA_BASIC;
desc.ctrlcfg.bits.next_useburst = 0x0;
desc.ctrlcfg.bits.r_power = 0;
Desc.ctrlCfg.Bits.src_prot_ctrl = 0x0;
Desc.ctrlCfg.Bits.dst_prot_ctrl = 0x0;
Desc.ctrlCfg.Bits.src_size = DMA_SIZE_BYTE;
Desc.ctrlCfg.Bits.dst_size = DMA_SIZE_BYTE;
// RX Primary Descriptor
Desc.srcEndPtr = (unsigned int)(&pADI_UART->COMRX);
Desc.destEndPtr = (unsigned int)(puc (iNumVals - 0x1) );
Desc.ctrlCfg.Bits.n_minus_1 = iNumRX - 0x1;
Desc.ctrlCfg.Bits.src_inc = DMA_SRCINC_NO;
Desc.ctrlCfg.Bits.dst_inc = DMA_DSTINC_BYTE;
*Dma_GetDescriptor(UARTRX_C) = Desc;
}
// UART DMA Rx IRQ handler
void DMA_UART_RX_Int_Handler()
{
NVIC_DisableIRQ(DMA_UART_RX_IRQn);
// Clear Interrupt source
}