AnsweredAssumed Answered

STM32F0 TIM15 ADC DMA, no DMA transfer

Question asked by Michal Lankosz on Sep 23, 2013
Latest reply on Sep 23, 2013 by Michal Lankosz
Hello!
I want to get defined number of samples at constant sample rate. I used ADC1 triggered by TIM15 TRGO signal and DMA in normal (not circular) mode with interrupt on transfer complete. Something is wrong, DMA interrupt is not generated.
When I remove DMA configuration and configure ADC interrupt on conversion complete - it works, and sampling frequency is OK. uC: STM32F051R8T6
Code:

001.#define SAMPLING_FREQUENCY 1000
002.#define LEN 128
003.#define ADC1_DR_Address    0x40012440
004.volatile uint16_t ADC_value;
005.volatile uint16_t ADC_tbl[LEN];
006.volatile uint16_t idx = 0;
007. 
008.void ADCgo(void)
009.{
010.    ADC_InitTypeDef         ADC_InitStructure;
011.    GPIO_InitTypeDef        GPIO_InitStructure;
012.    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
013.    DMA_InitTypeDef         DMA_InitStructure;
014.    NVIC_InitTypeDef        NVIC_InitStructure;
015. 
016.    /* DMA1 clock enable */
017.    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
018.    /* ADC1 Periph clock enable */
019.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
020.    /* TIM15 Periph clock enable */
021.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15 , ENABLE);
022.    /* GPIOC Periph clock enable */
023.    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
024. 
025.    /* Configure ADC Channel0 and 1 as analog input */
026.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
027.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
028.    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
029.    GPIO_Init(GPIOA, &GPIO_InitStructure);
030. 
031.    /* DMA1 Channel1 Config */
032.    DMA_DeInit(DMA1_Channel1);
033.    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;
034.    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_tbl;
035.    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
036.    DMA_InitStructure.DMA_BufferSize = LEN;
037.    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
038.    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
039.    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
040.    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
041.    DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
042.    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
043.    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
044.    DMA_Init(DMA1_Channel1, &DMA_InitStructure);
045.    /* DMA1 Channel1 enable */
046.    DMA_Cmd(DMA1_Channel1, ENABLE);
047.    /* Enable DMA1 Channel1 Transfer Complete interrupt */
048.    DMA_ITConfig(DMA1_Channel1, DMA_IT_TC);
049. 
050.    /* ADC DMA request in one shot mode */
051.    ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_OneShot);
052. 
053.    /* Enable ADC_DMA */
054.    ADC_DMACmd(ADC1, ENABLE);
055. 
056.    /* ADCs DeInit */
057.    ADC_DeInit(ADC1);
058. 
059.    /* Initialize ADC structure */
060.    ADC_StructInit(&ADC_InitStructure);
061. 
062.    /* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits  */
063.    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
064.    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
065.    ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
066.    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T15_TRGO;
067.    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
068.    ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
069.    ADC_Init(ADC1, &ADC_InitStructure);
070. 
071.    /* Convert the ADC1 Channel 0 with 13.5 Cycles as sampling time */
072.    ADC_ChannelConfig(ADC1, ADC_Channel_0 , ADC_SampleTime_13_5Cycles);     // microphone
073. 
074.    ADC_DiscModeCmd(ADC1, DISABLE);
075. 
076.    /* Set synchronous clock mode */
077.    ADC_JitterCmd(ADC1, ADC_JitterOff_PCLKDiv2, ENABLE);
078. 
079.    /* ADC Calibration */
080.    ADC_GetCalibrationFactor(ADC1);
081. 
082.    /* Enable ADCperipheral */
083.    ADC_Cmd(ADC1, ENABLE);
084. 
085.    /* Wait the ADCEN falg */
086.    while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
087. 
088.    // TIMER 15:
089.    TIM_DeInit(TIM15);
090.    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
091.    /* Time base configuration */
092.    TIM_TimeBaseStructure.TIM_Period = SystemCoreClock/SAMPLING_FREQUENCY - 1;
093.    TIM_TimeBaseStructure.TIM_Prescaler = 0;
094.    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
095.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
096.    TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);
097. 
098.    /* TIM15 TRGO selection */
099.    TIM_SelectOutputTrigger(TIM15, TIM_TRGOSource_Update);
100. 
101.    /* TIM1 enable counter */
102.    TIM_Cmd(TIM15, ENABLE);
103. 
104.    /* Configure and enable DMA1 interrupt */
105.    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
106.    NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
107.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
108.    NVIC_Init(&NVIC_InitStructure);
109. 
110.    /* ADC1 regular Software Start Conv */
111.    ADC_StartOfConversion(ADC1);
112.}
113. 
114.void DMA1_Channel1_IRQHandler(void)
115.{
116.  /* Test on DMA1 Channel1 Transfer Complete interrupt */
117.  if(DMA_GetITStatus(DMA1_IT_TC1))
118.  {
119.    /* Clear DMA1 Channel1 Half Transfer, Transfer Complete and Global interrupt pending bits */
120.    DMA_ClearITPendingBit(DMA1_IT_TC1);
121.  }
122.  printf_("*");    // BREAKPOINT
123.}

Outcomes