AnsweredAssumed Answered

Problem with ADC DMA in STM32F0

Question asked by pemo nowak on Nov 13, 2017

Hi.

I configured adc with dma and it doesnt work. I use stm32f030r8t6. When I use only adc and command ADC_GetConversionValue it's all ok.

Here is my code:

/**
  ******************************************************************************
  * @file    main.c
  * @author  Ac6
  * @version V1.0
  * @date    01-December-2013
  * @brief   Default main function.
  ******************************************************************************
*/

 


#include "stm32f0xx.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_adc.h"
#include "stm32f0xx_dma.h"

 

#define ADC_DR_ADD 0x40;
uint32_t ADC_value;

 

 

 

void ADC_init(void)
{
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

 

    GPIO_InitTypeDef GPIO_InitStructure;

 


        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);

 


        DMA_InitTypeDef DMA_INIT;

 

             DMA_INIT.DMA_PeripheralBaseAddr = (uint32_t*) ADC_DR_ADD;
             DMA_INIT.DMA_MemoryBaseAddr = (uint32_t)&ADC_value;
             DMA_INIT.DMA_DIR = DMA_DIR_PeripheralSRC;
             DMA_INIT.DMA_BufferSize = 1;
             DMA_INIT.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
             DMA_INIT.DMA_MemoryInc = DMA_MemoryInc_Enable;
             DMA_INIT.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
             DMA_INIT.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
             DMA_INIT.DMA_Mode =DMA_Mode_Circular;
             DMA_INIT.DMA_Priority = DMA_Priority_High;
             DMA_INIT.DMA_M2M = DMA_M2M_Disable;
             DMA_Init(DMA1_Channel1, &DMA_INIT);
             DMA_Cmd(DMA1_Channel1, ENABLE);

 


    ADC_InitTypeDef ADC_INIT;

 

        ADC_INIT.ADC_Resolution = ADC_Resolution_10b;
        ADC_INIT.ADC_ContinuousConvMode = ENABLE;
        ADC_INIT.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
        ADC_INIT.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_INIT.ADC_ScanDirection = ADC_ScanDirection_Upward;
        ADC_Init(ADC1, &ADC_INIT);

 

        ADC_ChannelConfig(ADC1, ADC_Channel_1 , ADC_SampleTime_55_5Cycles);
        ADC_DMACmd(ADC1,ENABLE);
        ADC_Cmd(ADC1, ENABLE);
        ADC_GetCalibrationFactor(ADC1);
        ADC_StartOfConversion(ADC1);
}

 

 

 

 

 

int main(void)
{

 

ADC_init();
    while (1)
    {
    }
}

Outcomes