This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem ADC with DMA of STM32F303

Hi,

I want to test my ADC1 with DMA but doesn't work and i don't know why. I spent a lot of time to debug but no success, can you please help me on this. I m working with STM32f3 discovery.

The code i have written is below:

#include "main.h"
#include <stdio.h>

int main()
{ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file*/

/* ADCs with DMA configuration ------------------------------------------------------*/ ADC12_Config();

/*start the conversion --------------------------------------------*/ ADC_StartConversion(ADC1);

while(1) { ADC1ConvertedVoltage = ADC1ConvertedValue *2938/0x3FF; // Vref=2.938v

if (i < 256) { buffer[i] = ADC1ConvertedVoltage ; i++; } else { // printf("valeur rien"); i = 0; } }
}

void ADC12_Config(void)

{

ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure;

DMA_InitTypeDef DMA_InitStruct; GPIO_InitTypeDef GPIO_InitStructure;

/* Enable ADC1,ADC2,DMA and GPIOC clockS */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12|RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_DMA1, ENABLE);

// this line is optionnal to permits us to return the system clock clockValue=RCC_GetSYSCLKSource();

/* Configures the AHB clock (HCLK) ***/ RCC_HCLKConfig(RCC_SYSCLK_Div1); // RCC_AHB_Clock_Source

/* Configure the ADC clock */ //RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);

/* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStruct.DMA_PeripheralBaseAddr=(uint32_t)(&(ADC1->DR));//peripheral(source) address (DMA1_Channel1->CPAR=(uint32_t)(&(ADC1->DR)); Addr) DMA_InitStruct.DMA_PeripheralBaseAddr=(uint32_t)&ADC1ConvertedValue;// memory (desination) address( DMA1_Channel1->CMAR = (uint32_t)ADC1ConvertedValue; DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStruct.DMA_BufferSize = 1; DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStruct.DMA_Mode = DMA_Mode_Circular; DMA_InitStruct.DMA_Priority = DMA_Priority_High; DMA_InitStruct.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStruct); //Initializes DMA1 peripherals according to the specified parameters

/* Configure PA.01, PA.04 (ADC1 fast Channel1, ADC2 fast Channel1) as analog input -----------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // |GPIO_Pin_5 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure);

/* ADC1 Configure Common Init */ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv4; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular; //ADC_DMAMode_Circular; ADC_CommonInitStructure.ADC_TwoSamplingDelay =0; ADC_CommonInit(ADC1, &ADC_CommonInitStructure);

ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable; ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable; ADC_InitStructure.ADC_NbrOfRegChannel = 1; ADC_Init(ADC1, &ADC_InitStructure);

/* Enable DMA1 channel1 */ DMA1_Channel1->CCR |= DMA_CCR_EN; // or by : DMA_Cmd(DMA1_Channel1, ENABLE);

/* ADC1 regular channel1 configuration *************************************/ ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_7Cycles5);

/* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC3 */ ADC_Cmd(ADC1, ENABLE);

}