cancel
Showing results for 
Search instead for 
Did you mean: 

ADC1 + DMA + TIMER2

ASSAAD.ASSAAD
Associate II
Posted on March 04, 2015 at 11:42

Hello ;

We are trying to read ADC1 channel 10 with DMA triggered by TIMER2 at 1khz sample , We tried all the compination to make it work but it never words the ADC always read 3,3volt full scale ; here our code please could you check the settings of our DMA and ADC ; what did we miss here ; and thank you inadvancced

void TIM2_Configuration(void) 
{ 
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); 

/* Time base configuration */ 
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); 
TIM_TimeBaseStructure.TIM_Period = 42000-1;//(84000000 / 200000) - 1; // 200 KHz, from 84 MHz TIM2CLK (ie APB1 = HCLK/4, TIM2CLK = HCLK/2) 
TIM_TimeBaseStructure.TIM_Prescaler = 0; 
TIM_TimeBaseStructure.TIM_ClockDivision = 0; 
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); 
/* TIM2 TRGO selection */ 
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); // ADC_ExternalTrigConv_T2_TRGO 
/* TIM2 enable counter */ 
TIM_Cmd(TIM2, ENABLE); 
} 
//--- 
void ADC_Configuration(void) 
{ 
ADC_CommonInitTypeDef ADC_CommonInitStructure; 
ADC_InitTypeDef ADC_InitStructure; 
/* ADC Common Init */ 
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; 
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; 
ADC_CommonInitStructure.ADC_DMAAccessMode =ADC_DMAAccessMode_Disabled; 
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles ; 
ADC_CommonInit(&ADC_CommonInitStructure); 
//--------------------------------------------------------- 
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; 
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // 1 Channel 
ADC_InitStructure.ADC_ContinuousConvMode =DISABLE; // Conversions Triggered ENABLE;// 
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; 
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; 
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 
ADC_InitStructure.ADC_NbrOfConversion = 1; 
ADC_Init(ADC1, &ADC_InitStructure); 
/* ADC1 regular channel 11 configuration */ 
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1,ADC_SampleTime_15Cycles ); // PC0 
/* Enable DMA request after last transfer (Single-ADC mode) */ 
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); 
/* Enable ADC1 DMA */ 
ADC_DMACmd(ADC1, ENABLE); 
/* Enable ADC1 */ 
ADC_Cmd(ADC1, ENABLE); 
} 
//------------------- 
static void DMA_Configuration(void) 
{ 
DMA_InitTypeDef DMA_InitStructure; 
DMA_InitStructure.DMA_Channel = DMA_Channel_0; 
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCConvertedValues[0]; 
DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)&ADC1->DR;// (uint32_t)0x40012308; // CDR_ADDRESS; 
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; 
DMA_InitStructure.DMA_BufferSize = 80;//BUFFERSIZE; // Count of 16-bit words 
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_Circular; 
DMA_InitStructure.DMA_Priority = DMA_Priority_High; 
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;//**** 
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; 
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; 
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; 
DMA_Init(DMA2_Stream0, &DMA_InitStructure); 
/* Enable DMA Stream Half / Transfer Complete interrupt */ 
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC | DMA_IT_HT, ENABLE); 
/* DMA2_Stream0 enable */ 
DMA_Cmd(DMA2_Stream0, ENABLE); 
} 
//---

1 REPLY 1
Posted on March 04, 2015 at 18:46

On the STM32F4-DISCO PC0 is pulled to 3V, remove R46 if you want to use this pin.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..