请问如何方便可靠的暂停ADC+DMA 的连续扫描模式?

2019-12-10 18:08发布

    扫描CH0 CH1 CH2 CH3  4个通道,用ADC+DMA   连续扫描循环。 设置总的搬运buf大小为4*128  ,即每个通道都采集到了128个值。  也开启了DMA传送完成中断,想在中断中暂停传送等数据处理完毕后再次传送。
有没有什么好的方法当传输完进入中断后可以暂停传输?想到的笨办法是关闭ADC,关闭DMA,处理完后再次初始化打开。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
9条回答
icoyool
2019-12-11 09:16

#define ADC1_BUFF_SIZE (USER_ADC_ADC1_CH_NUM*AI_MAX_COLLECT)
#define ADC2_BUFF_SIZE (USER_ADC_ADC2_CH_NUM*AI_MAX_COLLECT)
uint16 ADC1_DATA_BUFF[AI_MAX_COLLECT][USER_ADC_ADC1_CH_NUM];
uint16 ADC2_DATA_BUFF[USER_ADC_ADC2_CH_NUM][AI_MAX_COLLECT];
void ADC_Initial(void) {

    ADC_InitTypeDef ADC_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);

    ADC_DeInit(ADC1);
    ADC_DeInit(ADC2);
    ADC_StructInit(&ADC_InitStructure);
    ADC_InitStructure.ADC_PRESCARE = ADC_PCLK2_PRESCARE_8; //96M/8=12M

    //ADC_InitStructure.ADC_Mode = ADC_Mode_Single_Period;
    //ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_Mode = ADC_Mode_Continuous_Scan;
    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; //ADC1
    ADC_Init(ADC1, &ADC_InitStructure);


    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_EXTI_15; //ADC1
    ADC_Init(ADC2, &ADC_InitStructure);

    /*屏蔽所有通道*/
    /*使能选中通道,后面参数保留*/
    ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 0, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 2, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 3, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 4, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 5, ADC_SampleTime_239_5Cycles);

    ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 6, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC2, ADC_Channel_3, 6, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC2, ADC_Channel_4, 6, ADC_SampleTime_239_5Cycles);
    ADC_RegularChannelConfig(ADC2, ADC_Channel_5, 6, ADC_SampleTime_239_5Cycles);


//    ADC_ExternalTrigConvCmd(ADC1, ENABLE);
    ADC_ExternalTrigConvCmd(ADC1, DISABLE);
    ADC_ExternalTrigConvCmd(ADC2, DISABLE);

    ADC_DMACmd(ADC1, ENABLE); //开DMA
    ADC_DMACmd(ADC2, ENABLE); //开DMA

    ADC_Cmd(ADC1, ENABLE);
    ADC_Cmd(ADC2, ENABLE);
}

一周热门 更多>