请问如何软件触发读取PB0,PB1 的ADC,有没有例程

    自己改的单路改为两路读不对。

    ADC_Function_Init();

    while(1)

    {

        ADC_SoftwareStartConvCmd(ADC1, ENABLE);

        while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));

        while( !ADC_GetFlagStatus( ADC1, ADC_FLAG_JEOC ) );

        adc_jval = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);

        printf("PB0:%04d   ", Get_ConversionVal(adc_jval));

        adc_jval = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_2);

        printf("PB1:%04d   \r\n", Get_ConversionVal(adc_jval));

         Delay_Ms(500);

    }




void ADC_Function_Init(void)

{

    ADC_InitTypeDef  ADC_InitStructure = {0};

    GPIO_InitTypeDef GPIO_InitStructure = {0};


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

    RCC_ADCCLKConfig(RCC_PCLK2_Div8);


//    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

//    GPIO_Init(GPIOA, &GPIO_InitStructure);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

    GPIO_Init(GPIOB, &GPIO_InitStructure);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

    GPIO_Init(GPIOB, &GPIO_InitStructure);



    ADC_DeInit(ADC1);

    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

    ADC_InitStructure.ADC_ScanConvMode = DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfChannel = 1;

    ADC_Init(ADC1, &ADC_InitStructure);


    ADC_InjectedSequencerLengthConfig(ADC1, 2);

//    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5);


    ADC_InjectedChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_71Cycles5);

    ADC_InjectedChannelConfig(ADC1, ADC_Channel_9, 2, ADC_SampleTime_239Cycles5);


    ADC_AutoInjectedConvCmd(ADC1, ENABLE);

    ADC_Cmd(ADC1, ENABLE);


    ADC_BufferCmd(ADC1, DISABLE); //disable buffer

    ADC_ResetCalibration(ADC1);

    while(ADC_GetResetCalibrationStatus(ADC1));

    ADC_StartCalibration(ADC1);

    while(ADC_GetCalibrationStatus(ADC1));

    Calibrattion_Val = Get_CalibrationValue(ADC1);


}



您好,附件例程可以参考一下

icon_rar.gifCH32V208 ADC_PB0_1.zip



如果要休眠,让ADC不耗电,需要执行这些指令对吗?

ADC_DeInit(ADC1);

ADC_Cmd(ADC1, DISABLE);

DMA_Cmd(DMA1_Channel1, DISABLE);

ADC_DMACmd(ADC1, DISABLE);

ADC_SoftwareStartConvCmd(ADC1, DISABLE);



您好,一般进低功耗模式(如停止、待机)的时候时钟都被关闭了,不需要再配置关闭这些外设



只有登录才能回复,可以选择微信账号登录