AnsweredAssumed Answered

Adc value

Question asked by deroux.gregory on Feb 23, 2013
Latest reply on Feb 23, 2013 by Clive One
Hello,

I'm trying to get back the value of the conversion from adc1. But, nothing happend.
Could you help me ?

Thank you,

/* Includes */
#include <stddef.h>
#include "stm32f10x.h"
 
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
int main(void)
{
float a;
        GPIO_StructInit (& GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init(GPIOC , &GPIO_InitStructure);
 
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
        //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init(GPIOA , &GPIO_InitStructure);
 
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
 
 
        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_Init(ADC1 , &ADC_InitStructure);
        // Configure ADC_IN6
        ADC_RegularChannelConfig(ADC1 , ADC_Channel_6 , 1,ADC_SampleTime_55Cycles5);
        // Enable ADC
        ADC_Cmd(ADC1 , ENABLE);
 
        // Check the end of ADC1 reset calibration register
        while(ADC_GetResetCalibrationStatus(ADC1));
        // Start ADC1 calibration
        ADC_StartCalibration(ADC1);
        // Check the end of ADC1 calibration
        while(ADC_GetCalibrationStatus(ADC1));
        a = ADC_GetConversionValue(ADC1);
 
}

Outcomes