// ADC2 configuration
void ADC2_Init(void)
{
// RCC->CFGR |= RCC_CFGR_ADC1PRE; //Set ADC2 clock frequency PCLK2/6 12MHZ
RCC->APB2ENR|= RCC_APB2Periph_ADC2; // enable periperal clock for ADC2
ADC2->CR1 |= ADC_Mode_Independent; // use independant mode
ADC2->SMPR2 |= (ADC_SampleTime_239Cycles5<<3); //Set ADC2 Channel 1 sample time 239.5
ADC2->SQR3 |= ADC_Channel_1; //select ADC channal
ADC2->CR2 |= ADC_CR2_CAL; //selfcalibration ADC
ADC2->CR2 |= ADC_CR2_Exttrig; //External Trigger Conversion
ADC2->CR2 |= ADC_ExternalTrigConv_None; // External event
ADC2->CR2 |= ADC_CR2_ADON; //A/D converter ON and start
DelayuS(10); //Wait power stable
}
以上程序是ADC2的初始化设置。在主函数中读取的函数如下:
Send_Int_Four(ADC2->DR);
USART1_CRLF();
DelayuS(100);
ADC2->CR2 |= ADC_CR2_Swstart;
DelayuS(1000000);
|