static void App_DMA_Test(void) { uint16_t dataADC; /* Initialize GPDMA controller */ Chip_GPDMA_Init(LPC_GPDMA); /* Setting GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); NVIC_SetPriority(DMA_IRQn, ((0x01 << 3) | 0x01)); NVIC_EnableIRQ(DMA_IRQn); /* Setting ADC interrupt, ADC Interrupt must be disable in DMA mode */ NVIC_DisableIRQ(_LPC_ADC_IRQ); Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE); /* Get the free channel for DMA transfer */ dmaChannelNum = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, _GPDMA_CONN_ADC); /* Enable burst mode if any, the AD converter does repeated conversions at the rate selected by the CLKS field in burst mode automatically */ if (Burst_Mode_Flag) { Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE); } /* Get adc value until get 'x' character */ while (DEBUGIN() != 'x') { /* Start A/D conversion if not using burst mode */ if (!Burst_Mode_Flag) { Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING); } channelTC = 0; Chip_GPDMA_Transfer(LPC_GPDMA, dmaChannelNum, _GPDMA_CONN_ADC, (uint32_t) &DMAbuffer, GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA, 1); /* Waiting for reading ADC value completed */ while (channelTC == 0) {} /* Get the ADC value fron Data register*/ dataADC = ADC_DR_RESULT(DMAbuffer); App_print_ADC_value(dataADC); } /* Disable interrupts, release DMA channel */ Chip_GPDMA_Stop(LPC_GPDMA, dmaChannelNum); NVIC_DisableIRQ(DMA_IRQn); /* Disable burst mode if any */ if (Burst_Mode_Flag) { Chip_ADC_SetBurstCmd(_LPC_ADC_ID, DISABLE); } } |