AnsweredAssumed Answered

GPDMA, Timer, SRAM

Question asked by Tim Krebs on Aug 17, 2019
Latest reply on Aug 28, 2019 by Alice_Yang

Hi all,

 

I'm new to LPC and need some help. I wanna set up a Timer triggered DMA transfer to transfer data from pin to a defined adress in the SRAM1. Every time the MR0 matches the DMA transfer should start. I work with the LPC4088 Quickstart Board. I set the Board up to run at 120MHz. My Peripherals also run at 120MHz.  I studied the UM and wrote some code but when I compile nothing happens. The timer works fine and I see a 10MHz output on the defined pin.

 

I attached my simple code I wrote extra for this.

 

Hope anyone of you can help me.

 

Best Tim

#include "LPC407x_8x_177x_8x.h"

#define PERIPHSRAM1           0x20004000

char adcData[11] = {1,1,1,1,1,1,1,1,1,1,1};

volatile uint32_t DMATCCOUNT = 0;
volatile uint32_t DMAERRCOUNT = 0;




void DMA_IRQHandler(){
    uint32_t temp;
    DMATCCOUNT++;
    temp = LPC_GPDMA->IntTCStat;
    if(temp){
        DMATCCOUNT++;
        LPC_GPDMA->IntTCClear |= temp;
    }
    temp = LPC_GPDMA->IntErrStat;
    if(temp){
        DMAERRCOUNT++;
        LPC_GPDMA->IntErrClr |= temp;
    }
    return;
}

int main(){

    uint8_t size = sizeof(adcData);

    LPC_SC->PCONP |= (1 << 22);                     //Power & Clock  Timer 2

    LPC_TIM2->CTCR = (0 << 0);                      //Timer Mode
    LPC_TIM2->PR = 0;
    LPC_TIM2->TCR = (1 << 1);                       //Reset timer

    LPC_TIM2->TC = 0;              
    LPC_TIM2->MR0 = 5;                              //Match register to get 10MHz
    LPC_TIM2->MCR = (1 << 1)                        //Reset Timer
                    |(1 << 0);                      //Interrupt if MR matches
    LPC_TIM2->EMR = 0x31;                           //toggle pin to check wave output
    LPC_TIM2->TCR = (1 << 1);                       //reset timer again
   
    LPC_SC->PCONP |= (1 << 29);                     //Power & Clock DMA
    LPC_GPDMACH0->CConfig = 0;                      //disable CH0
    LPC_GPDMA->Config |= (1 << 0);                  //enable DMA Controller
    LPC_SC->DMAREQSEL = 0x010;                      //Set T2 MAT0 as DMA request

    LPC_GPDMA->IntErrClr |= 0x0FF;
    LPC_GPDMA->IntTCClear |= 0x0FF;

    LPC_GPDMACH0->CDestAddr = PERIPHSRAM1;
    LPC_GPDMACH0->CSrcAddr = (uint32_t) &adcData;
    LPC_GPDMACH0->CControl = size
                            |(0x03 << 12)           //Source Burst size:        16  (16bit?)
                            |(0x03 << 15)           //Destination Burst size:   16
                            |(0x01 << 18)           //Source width:     16 bit
                            |(0x01 << 21)           //Destination width:16 bit
                            |(0x01 << 26)           //Source increment: enabled
                            |(0x01 << 27)           //Destination increment: enabled
                            |(0x01 << 31);          //Terminal Count interrupt enabled
    LPC_GPDMACH0->CControl |= (4 << 1)              //Source peripheral: Timer2 MR0
                           |(0 << 11);              //Memory to memory trasnfer

    NVIC_SetVector(DMA_IRQn, (uint32_t) DMA_IRQHandler);
    NVIC_EnableIRQ(DMA_IRQn);

    LPC_GPDMACH0->CConfig |= 1;                     //Enable channel
    LPC_TIM2->IR |= 0x0FF;                  //CLear all timer interrupts
    LPC_TIM2->TCR = 0x01;                   //start Timer

    while(!DMATCCOUNT);                     //Wait till transfer Complete

    while(1){
       
    }
}

Outcomes