cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 TIM15 ADC DMA, no DMA transfer

mike2001
Associate II
Posted on September 23, 2013 at 14:34

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:

#define SAMPLING_FREQUENCY 1000

#define LEN 128

#define ADC1_DR_Address 0x40012440

volatile uint16_t ADC_value;

volatile uint16_t ADC_tbl[LEN];

volatile uint16_t idx = 0;

void

ADCgo(

void

)

{

ADC_InitTypeDef ADC_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

DMA_InitTypeDef DMA_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

/* DMA1 clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);

/* ADC1 Periph clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

/* TIM15 Periph clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15 , ENABLE);

/* GPIOC Periph clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

/* Configure ADC Channel0 and 1 as analog input */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* DMA1 Channel1 Config */

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_tbl;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize = LEN;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* DMA1 Channel1 enable */

DMA_Cmd(DMA1_Channel1, ENABLE);

/* Enable DMA1 Channel1 Transfer Complete interrupt */

DMA_ITConfig(DMA1_Channel1, DMA_IT_TC);

/* ADC DMA request in one shot mode */

ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_OneShot);

/* Enable ADC_DMA */

ADC_DMACmd(ADC1, ENABLE);

/* ADCs DeInit */

ADC_DeInit(ADC1);

/* Initialize ADC structure */

ADC_StructInit(&ADC_InitStructure);

/* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits */

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T15_TRGO;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;

ADC_Init(ADC1, &ADC_InitStructure);

/* Convert the ADC1 Channel 0 with 5 Cycles as sampling time */

ADC_ChannelConfig(ADC1, ADC_Channel_0 , ADC_SampleTime_13_5Cycles);

// microphone

ADC_DiscModeCmd(ADC1, DISABLE);

/* Set synchronous clock mode */

ADC_JitterCmd(ADC1, ADC_JitterOff_PCLKDiv2, ENABLE);

/* ADC Calibration */

ADC_GetCalibrationFactor(ADC1);

/* Enable ADCperipheral */

ADC_Cmd(ADC1, ENABLE);

/* Wait the ADCEN falg */

while

(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));

// TIMER 15:

TIM_DeInit(TIM15);

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = SystemCoreClock/SAMPLING_FREQUENCY - 1;

TIM_TimeBaseStructure.TIM_Prescaler = 0;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);

/* TIM15 TRGO selection */

TIM_SelectOutputTrigger(TIM15, TIM_TRGOSource_Update);

/* TIM1 enable counter */

TIM_Cmd(TIM15, ENABLE);

/* Configure and enable DMA1 interrupt */

NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

/* ADC1 regular Software Start Conv */

ADC_StartOfConversion(ADC1);

}

void

DMA1_Channel1_IRQHandler(

void

)

{

/* Test on DMA1 Channel1 Transfer Complete interrupt */

if

(DMA_GetITStatus(DMA1_IT_TC1))

{

/* Clear DMA1 Channel1 Half Transfer, Transfer Complete and Global interrupt pending bits */

DMA_ClearITPendingBit(DMA1_IT_TC1);

}

printf_(

''*''

);

// BREAKPOINT

}

#stm32f0-tim-adc-dma

1 REPLY 1
mike2001
Associate II
Posted on September 23, 2013 at 15:12

The problem has solved!

ADC_DeInit(ADC1) must be moved upper, before all ADC_xxx functions.