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

stm32 f446re ADC problem - fluctuations or something

Hi i dont know how use ADC.
I have very strange readings:
On Vref: http://i.imgur.com/6eHe2k5.png (chanel17)
On PA1: http://i.imgur.com/ZtxtBVF.png (chanel1)
My code:

int main(void) {
        SysTick_Config(SystemCoreClock/1000);



        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1ENR_GPIOAEN ,ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);


        GPIO_InitTypeDef gpio;
        gpio.GPIO_Pin = GPIO_Pin_1;
        gpio.GPIO_Mode=GPIO_Mode_AN;
        gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOA,&gpio);

        RCC_PCLK1Config(RCC_HCLK_Div8);

        ADC_InitTypeDef ADC_InitStructure;
        ADC_StructInit(&ADC_InitStructure);
        ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
        ADC_InitStructure.ADC_ScanConvMode = DISABLE;
        ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
        ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfConversion = 1;
        ADC_Init(ADC1,&ADC_InitStructure);

        ADC_RegularChannelConfig(ADC1,ADC_Channel_17,1,ADC_SampleTime_15Cycles);

        ADC_TempSensorVrefintCmd(ENABLE);

        ADC_Cmd(ADC1,ENABLE);

        setup_USART2();

        USART_puts(USART2,"Pomiar napiecia\r\n");
        uint16_t adc;
        while (1) {
                ADC_RegularChannelConfig(ADC1,ADC_Channel_17,1,ADC_SampleTime_15Cycles);
                ADC_SoftwareStartConv(ADC1);
                while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!= SET );
                adc = ADC_GetConversionValue(ADC1);
                printf("%.6fV\r\n",adc*3.3f/4096.0f);
                Delay(50);
        }
        return 0;
}

I know that the code is not the best. But I wanted something that works, and no matter what I do the results are not accurate.

I try find on google but nothing.