下面的代碼是EVT中ADC初始化的部分:
void?ADC_Function_Init(void) { ????ADC_InitTypeDef??ADC_InitStructure?=?{0}; ????GPIO_InitTypeDef?GPIO_InitStructure?=?{0}; ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,?ENABLE); ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,?ENABLE); ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2,?ENABLE); ????RCC_ADCCLKConfig(RCC_PCLK2_Div8); ????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_1?|?GPIO_Pin_3; ????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AIN; ????GPIO_Init(GPIOA,?&GPIO_InitStructure); ????ADC_DeInit(ADC1); ????ADC_DeInit(ADC2); ????ADC_InitStructure.ADC_Mode?=?ADC_Mode_RegSimult; ????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_InitStructure.ADC_OutputBuffer?=?ADC_OutputBuffer_Disable; ????ADC_InitStructure.ADC_Pga?=?ADC_Pga_1; ????ADC_Init(ADC1,?&ADC_InitStructure); ????ADC_RegularChannelConfig(ADC1,?ADC_Channel_1,?1,?ADC_SampleTime_239Cycles5); ????ADC_DMACmd(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_Val1?=?Get_CalibrationValue(ADC1); ????ADC_Init(ADC2,?&ADC_InitStructure); ????ADC_RegularChannelConfig(ADC2,?ADC_Channel_3,?1,?ADC_SampleTime_239Cycles5); ????ADC_SoftwareStartConvCmd(ADC2,?ENABLE); ????ADC_Cmd(ADC2,?ENABLE); ????ADC_BufferCmd(ADC2,?DISABLE);?//disable?buffer ????ADC_ResetCalibration(ADC2); ????while(ADC_GetResetCalibrationStatus(ADC2)); ????ADC_StartCalibration(ADC2); ????while(ADC_GetCalibrationStatus(ADC2)); ????Calibrattion_Val2?=?Get_CalibrationValue(ADC2); }
有個(gè)問(wèn)題是,ADC校準(zhǔn)的操作,一般是每次啟動(dòng)時(shí)只用校準(zhǔn)一次就可以了吧,
如果使用ADC_Cmd把ADC模塊關(guān)閉再開(kāi)啟,還需要重新校準(zhǔn)嗎?
ADC_Cmd(ADC1,?DISABLE); ...... ADC_Cmd(ADC1,?ENABLE);
熱門(mén)產(chǎn)品 :
CH32X035: 32位USB+USB PD單片機(jī)