Dac + dma + lpc1768 + cmsis

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dac + dma + lpc1768 + cmsis

2,058 Views
lpcware
NXP Employee
NXP Employee
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);
        }
    }
}
0 Kudos
Reply
3 Replies

1,504 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lean966 on Fri Jul 08 04:54:12 MST 2011
[LIST]
[*]I could find the problem after to speed so  many hours. The issue is the optimization option in GCC compiler :mad:. The only way that it  works is in optimization level 3 (max).
I wrote DMA configuration in a funtion (init_DMA();) and before to  enter in the "while(1)" I called the init_DMA(). I replace the call of  the funtion by the funtion code and still not working. After I changed  the optimization option until nivel 3 and works.


[/LIST]
0 Kudos
Reply

1,504 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lean966 on Thu Jul 07 06:37:45 MST 2011
Lamentably didn't work. I was trying with this AN. I'm using a GCC compiler with CooCox IDE (www.coocox.org). I don't know what happens, if you've got another idea, I will thank you.
In lpc17xx.cmsis.driver.library.zip has a few examples, and DMA-DAC too, but it doesn't work too. And the example use a funtion that there is not in the lpc17xx_gpdma.h :mad:...
0 Kudos
Reply

1,504 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kendwyer on Wed Jul 06 16:57:58 MST 2011
Have you seen this link:
AN10917 Memory to DAC data transfers using the LPC1700's DMA
http://ics.nxp.com/support/documents/microcontrollers/zip/an10917.zip
0 Kudos
Reply