cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F1 Timer ADC Trigger Don't working

ferhatyol-23
Senior
Posted on June 16, 2017 at 11:12

Hello there

I am trying to trigger the ADC with Tim3. But I could not work it. My goal is to get a certain number of samples through ADC Timer and DMA

This is My ADC configuration code.

&sharpinclude 'stm32f10x.h'

&sharpinclude 'Adc.h'

uint16_t ADC_ConvertedValue[128];

/*ADC baslanagic ayarlari yuklenme islemini yapar */

void ADC1_Configuration(){

ADC_InitTypeDef ADC_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);

/* ADC pin analog input yapiliyor */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

GPIO_Init(GPIOB, &GPIO_InitStructure);

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_CC1;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC1, &ADC_InitStructure);

/* Ch8 PB0 */

ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_55Cycles5);

ADC_Cmd(ADC1, ENABLE);

ADC_DMACmd(ADC1,ENABLE);

ADC_ExternalTrigConvCmd(ADC1,ENABLE);

/* ADC1 Reset Kalibrasyonu yapilacak */

ADC_ResetCalibration(ADC1);

/* Kalibrasyon bekleniyor */

while(ADC_GetResetCalibrationStatus(ADC1));

/* ADC1 calibrasyonu yapilacak */

ADC_StartCalibration(ADC1);

/* Kalibrasyon bekleniyor */

while(ADC_GetCalibrationStatus(ADC1));

}

void DMA1_Configuration(void)

{

DMA_InitTypeDef DMA_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

/*DMA Clock Aktif Ediliyor*/

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);

/* DMA Ayarlar1 Yapiliyor */

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;

DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue[0];

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize = 1;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enable the DMA1 TC Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

/* DMA Transfer Complete interrupt Enable*/

DMA_ITConfig(DMA1_Channel1,DMA1_IT_TC1,ENABLE);

/* Enable DMA1 channel1 */

DMA_Cmd(DMA1_Channel1, ENABLE);

}

void TIM3_Configuration(void)

{

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_OCInitTypeDef TIM_OCInitStructure;

/*Enable TIM3 Clock*/

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

TIM_DeInit(TIM3);

TIM_TimeBaseStructure.TIM_Period = 999;

TIM_TimeBaseStructure.TIM_Prescaler = 35;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 1;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;

TIM_OC1Init(TIM3, &TIM_OCInitStructure);

TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_OC1);

TIM_ARRPreloadConfig(TIM3, ENABLE);

TIM_Cmd(TIM3, ENABLE);

}

void ADC_init(void)

{

DMA1_Configuration();

ADC1_Configuration();

TIM3_Configuration();

}

DMA needs to create continuous interrupt.  But there is only one interrupt occurs

What can be the problem?

Thank you

#adc #stm32-adc-timer-trigger #stm32-timer-trigger-adc #trigger #dma #timer
1 REPLY 1
ferhatyol-23
Senior
Posted on June 16, 2017 at 13:16

There's just a problem with interrupt, 

Because Timer ADC and DMA is working. But the DMA TC interrupt occurs only once. I did not understand the problem.