Content originally posted in LPCWare by Lean966 on Wed Jul 06 14:23:36 MST 2011
Hi everyone. I´m trying, without success, working with LPC1768's DMA and DAC. I want to do a infinitive loop with a sine array in RAM. Next, I write a little part of my code. I hope that someone could help me. Thank you. Regards.
static uint32_t Seno_10a[DMA_SIZE];
void init_DMA(uint32_t Ch)
{
GPDMA_Channel_CFG_Type GPDMACfg;
GPDMA_LLI_Type DMA_LLI_StructA;
/* GPDMA block section -------------------------------------------- */
/* Disable GPDMA interrupt */
NVIC_DisableIRQ(DMA_IRQn);
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01));
/* Initialize GPDMA controller */
DMA_LLI_StructA.SrcAddr= (uint32_t)&Seno_10a[0];
DMA_LLI_StructA.DstAddr= (uint32_t)&(LPC_DAC->DACR);
DMA_LLI_StructA.NextLLI= (uint32_t)&DMA_LLI_StructA;
DMA_LLI_StructA.Control= DMA_SIZE | (2<<18) //source width 32 bit
| (2<<21) //dest. width 32 bit
| (1<<26); //source increment
GPDMA_Init();
/* Setup GPDMA channel --------------------------------*/
/* channel 0 */
GPDMACfg.ChannelNum = 0;
/* Source memory */
GPDMACfg.SrcMemAddr = (uint32_t)(&Seno_10a[0]);
/* Destination memory */
GPDMACfg.DstMemAddr = 0;
/* Transfer size */
GPDMACfg.TransferSize = DMA_SIZE;
/* Transfer width */
GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD;
/* Transfer type */
GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P;
/* Source connection - unused */
GPDMACfg.SrcConn = 0;
/* Destination connection - unused */
GPDMACfg.DstConn = GPDMA_CONN_DAC;
/* Linker List Item - unused */
GPDMACfg.DMALLI = (uint32_t)&DMA_LLI_StructA;
/* Setup channel with given parameter */
GPDMA_Setup(&GPDMACfg);
// Enable GPDMA channel 0
Channel0_TC = 0;
Channel0_Err = 0;
NVIC_EnableIRQ(DMA_IRQn);
DAC_ConverterConfigStruct.CNT_ENA = SET; //Time-out counter operation is enabled.
DAC_ConverterConfigStruct.DMA_ENA = SET; //DMA Burst Request Input 7 is enabled for the DAC
DAC_ConfigDAConverterControl(LPC_DAC, &DAC_ConverterConfigStruct);
//DAC Counter Value register. This register contains the reload value for the DAC DMA/Interrupt timer.//
DAC_SetDMATimeOut(LPC_DAC,1000);
}
void init_DAC()
{
PINSEL_CFG_Type PinCfg;
PinCfg.Funcnum = 2;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 26;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
DAC_Init(LPC_DAC);
DAC_UpdateValue (LPC_DAC, 0);
}
void DMA_IRQHandler(void)
{
if(GPDMA_IntGetStatus(GPDMA_STAT_INT, 0) == SET)
{
if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0) == SET)
{
Channel0_TC++;
GPDMA_ClearIntPending(GPDMA_STATCLR_INTTC, 0);
FlagTC = !FlagTC;
}
if(GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0) == SET)
{
Channel0_Err++;
GPDMA_ClearIntPending(GPDMA_STATCLR_INTERR, 0);
GPIO_SetValue(2, GPIO_Pin_3);
}
}
}