Skip to main content
jgalea
Associate III
February 5, 2009
Question

DMA Channel Timer1 configuration

  • February 5, 2009
  • 3 replies
  • 979 views
Posted on February 05, 2009 at 04:49

DMA Channel Timer1 configuration

    This topic has been closed for replies.

    3 replies

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:56

    Hello everyone,

    My name is Johann Galea from Malta, and this is my first time in a forum. Right now Im using the STM32F101C. Im trying to convert 7 analogue channels with DMA1, as I will have only one interrupt at the end of the 7 conversions. Im setting the parameters as shown in examples. However, Im not getting a DMA intrerrupt. Timer 1 is working at the desired frequency. Can you please forward any suggestions. These are my codes:

    void TIM1_UP_IRQHandler(void)

    {

    //checks if interrupt occured

    if (TIM_GetITStatus(TIM1,TIM_IT_Update) == SET)

    { TIM_ClearITPendingBit(TIM1, TIM_IT_Update);

    //Start by software the ADC1 Conversion

    //ADC_Cmd should be called twice, once to wake from powerdown, second to start conversion; manual RM0008 section 10.12.3 ADON not sure

    ADC_Cmd(ADC1, ENABLE); //enable ADC

    ADC_Cmd(ADC1, ENABLE); //enable ADC

    ADC_SoftwareStartConvCmd(ADC1, ENABLE);

    }

    void DMA1_Channel1_IRQHandler(void)

    { //channel 1 includes ADC1

    SUPPLY_LED_ON; //this is not turning ON

    //DMA1_IT_TC1 DMA1 Channel1 transfer complete interrupt

    //checks wether specified DMA Channel interrupt occured or not.

    //DMA Channel1 transfer/half complete

    if (DMA_GetITStatus(DMA1_IT_HT1)==SET)

    { DMA_ClearITPendingBit(DMA1_IT_HT1);//clear DMA channel transfer complete bit

    }

    if(DMA_GetITStatus(DMA1_IT_TC1)==SET)

    { DMA_ClearITPendingBit(DMA1_IT_TC1);//clear DMA channel1 transfer complete bit

    }

    L1v_value = ADC_result[0];

    }

    void Init_ADC(void)

    { //RM0008 pg 135, low density have DMA1 with 7 channels

    ADC_InitTypeDef ADC_InitStructure;

    DMA_InitTypeDef DMA_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    ADC_DeInit(ADC1); //resets ADC1

    //Initialisation of DMA channel 1

    DMA_DeInit(DMA1_Channel1);//pg 125

    DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//peripheral base address

    DMA_InitStructure.DMA_MemoryBaseAddr =

    (u32)ADC_result;//memory base address

    DMA_InitStructure.DMA_DIR =

    DMA_DIR_PeripheralSRC;//peripheral is the source

    DMA_InitStructure.DMA_BufferSize =

    ADC_nbrElement;//number of DMA buffers

    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//peripheral address unchanged

    DMA_InitStructure.DMA_MemoryInc =

    DMA_MemoryInc_Enable;//current memory register incremented

    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//16 bits

    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//16 bits

    DMA_InitStructure.DMA_Mode =

    DMA_Mode_Circular;//circular buffer mode

    DMA_InitStructure.DMA_Priority = DMA_Priority_High;//high priority

    DMA_InitStructure.DMA_M2M =

    DMA_M2M_Disable;//not from memory to memory transfer

    DMA_Init(DMA1_Channel1, &DMA_InitStructure);

    DMA_ClearFlag (DMA1_FLAG_GL1 | DMA1_FLAG_TC1 | DMA1_FLAG_HT1);//clears DMA1 channel 1 transfer complete

    //Enables DMA channel interrupt when transfer is completed

    //transfer complete or half complete

    //DMA_ITConfig( DMA1_Channel1, (DMA1_FLAG_TC1 | DMA1_FLAG_HT1) , ENABLE);

    /* Enable the DMAChannel1 Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQChannel;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    /* Enable DMA1 Channel1 complete transfer interrupt */

    DMA_ITConfig(DMA1_Channel1, (DMA_IT_TC | DMA_IT_HT), ENABLE);

    DMA_Cmd(DMA1_Channel1, ENABLE);//enable DMA channel 1

    //ADC1 Configuration pg 59

    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//ADCs operate in independent mode

    ADC_InitStructure.ADC_ScanConvMode

    = ENABLE;//conversion done in Scan

    ADC_InitStructure.ADC_ContinuousConvMode

    = DISABLE;//only one pass of conversions

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//conversion started by software

    ADC_InitStructure.ADC_DataAlign

    = ADC_DataAlign_Right;//ADC data right aligned

    ADC_InitStructure.ADC_NbrOfChannel

    = ADC_nbrElement;//no of ADC channels to convert in a group

    ADC_Init(ADC1, &ADC_InitStructure);

    //regular ADC channel configuration

    ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1 , ADC_SampleTime_13Cycles5 );//VL1

    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2 , ADC_SampleTime_13Cycles5 );//VL2

    ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3 , ADC_SampleTime_13Cycles5 );//VT1

    ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4 , ADC_SampleTime_13Cycles5 );//VT2

    ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 5 , ADC_SampleTime_13Cycles5 );//VT3

    ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 6 , ADC_SampleTime_13Cycles5 );//L3 ref

    ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 7 , ADC_SampleTime_13Cycles5 );//Shunt

    ADC_DMACmd(ADC1, ENABLE);//enables ADC1 DMA transfer

    ADC_Cmd(ADC1, ENABLE); //enable ADC

    //Resets the selected ADC calibration registers.

    ADC_ResetCalibration(ADC1);

    while(ADC_GetResetCalibrationStatus(ADC1));

    //start ADC1 calibration

    ADC_StartCalibration(ADC1);

    while(ADC_GetCalibrationStatus(ADC1) == SET);

    }

    Im suspecting that I have something wrong in the order of the code

    Many thanks

    Johann

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:56

    Many thanks. I placed my code on this forum link:

    http://www.st.com/mcu/forums-cat-7925-23.html

    Johann

    jki79ros81
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:56

    Do you set RCC?

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    or

    Value of ADC_nbrElement ?

    If it transmited not as ADC_nbrElement, interrupt not generated.

    Hope help.