AnsweredAssumed Answered

ADC for single channel free run

Question asked by hakim.soni on Jan 24, 2014
Latest reply on Jan 24, 2014 by baird.hal.001
hi.. I'm working with STM32F0 and I'm trying to create ADC on STM32 for single channel free run but it doesn't work. Can someone help me to find what is wrong in this code.
thank you for helping me

#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_conf.h"
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
int i,j;
/* Blink a LED, blink speed is set by ADC value */
void ADC_simple(void)
// init for GPIO (LED)
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8 | GPIO_Pin_9 ;       // two LED
        GPIO_Init(GPIOB, &GPIO_InitStructure);
// input of ADC 
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AIN;
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1 ;            // that's ADC1 (PA1 on STM32)
        GPIO_Init(GPIOA, &GPIO_InitStructure);
//clock for ADC (max 14MHz --> 72/6=12MHz)
        RCC_ADCCLKConfig (RCC_PCLK2_Div6);
// enable ADC system clock
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
// define ADC config
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
        ADC_InitStructure.ADC_ScanConvMode = DISABLE;
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;   
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfChannel = 1;
        ADC_RegularChannelConfig(ADC1,ADC_Channel_1, 1,ADC_SampleTime_28Cycles5); // define regular conversion config
        ADC_Init ( ADC1, &ADC_InitStructure);   //set config of ADC1
// enable ADC
        ADC_Cmd (ADC1,ENABLE);  //enable ADC1
//      ADC calibration 
        ADC_ResetCalibration(ADC1);     // Reset previous calibration
        ADC_StartCalibration(ADC1);     // Start new calibration 
// start conversion
        ADC_Cmd (ADC1,ENABLE);  //enable ADC1
        ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// debug information
        RCC_ClocksTypeDef forTestOnly;
        j= 50000;
                for (i=0;i