時鐘96MHZ, 通道3進行AD轉換,做測試.最簡單處理方法,全部在一個函數(shù)中了
VOID??ADC_Function_test(void) { ????ADC_InitTypeDef?ADC_InitStructure; ????GPIO_InitTypeDef?GPIO_InitStructure; ???? ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,?ENABLE?); ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,?ENABLE?); ????RCC_ADCCLKConfig(RCC_PCLK2_Div8);??//ADC分頻?最大14M???96/8=12M ???? ????GPIO_InitStructure.GPIO_Pin?=GPIO_Pin_3;//通道3; ????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AIN; ????GPIO_Init(GPIOA,?&GPIO_InitStructure); ???? ???//?ADC_StructInit(&ADC_InitStructure); ????ADC_InitStructure.ADC_Mode?=?ADC_Mode_Independent;????//ADC1工作在獨立模式 ????ADC_InitStructure.ADC_ScanConvMode?=?DISABLE;?????????//單通道模式 ????ADC_InitStructure.ADC_ContinuousConvMode?=?DISABLE;???//單次轉換模式 ????ADC_InitStructure.ADC_ExternalTrigConv?=?ADC_ExternalTrigInjecConv_None;??//轉換啟動由軟件而不是外部啟動 ????ADC_InitStructure.ADC_DataAlign?=?ADC_DataAlign_Right;??//ADC?數(shù)據(jù)右對齊 ????ADC_InitStructure.ADC_NbrOfChannel?=?1;??????????????//順序進行規(guī)則的通道數(shù) ????ADC_Init(ADC1,?&ADC_InitStructure); ???? ?????ADC_Cmd(ADC1,?ENABLE);?//使能ADC1 ????? ????//?ADC_BufferCmd(ADC1,?DISABLE);???//disable?buffer ?????ADC_ResetCalibration(ADC1); ?????while(ADC_GetResetCalibrationStatus(ADC1)); ?????ADC_StartCalibration(ADC1); ?????while(ADC_GetCalibrationStatus(ADC1)); ???//??ADC_BufferCmd(ADC1,?ENABLE);???//enable?buffer ??? ?????ADC_RegularChannelConfig(ADC1,?ADC_Channel_3,?1,ADC_SampleTime_239Cycles5);?//采樣時間為239.5個周期 ?????ADC_SoftwareStartConvCmd(ADC1,?ENABLE);?//啟動轉換 ?????while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));?//等待轉換結束??????????死等待了 ?????ADC_GetConversionValue(ADC1);//讀取數(shù)據(jù) ????return?; }
在while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)); //死等