配置的源文件 ,有没有谁遇到过了
/*******************************************************************************
* Function Name :
* Description :
* Input : None
* Output : None
* Return : None
*******************************************************************************/
extern void ADC_KEY_2AIN_Configuration(uint32 DMA_Priority ,uint32 IRQ_Priority)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* ADCCLK = PCLK2/6 = 12mhz MAX 14MHZ*/
//RCC_HSI14Cmd(ENABLE);
//RCC_ADCCLKConfig(RCC_ADCCLK_HSI14);
//CLK = 8M = 1 CLK = 0.1US
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
//RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
RCC->APB2ENR |= RCC_APB2Periph_ADC1 ;
RCC->APB2RSTR |= RCC_APB2Periph_ADC1 ;
RCC->APB2RSTR &= ~RCC_APB2Periph_ADC1;
/* Configure PB.00 (ADC Channel8) as analog input ADC_KEY ---------------------------------------------*/
GPIO_InitStructure.GPIO_Pin = KEY_AIN_1_PIN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN ;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz ;
GPIO_Init(KEY_AIN_1_PORT, &GPIO_InitStructure) ;
/* Configure as analog input AN_AIN_1_PIN ---------------------------------------------*/
GPIO_InitStructure.GPIO_Pin = AN_AIN_1_PIN ;
GPIO_Init(AN_AIN_1_PORT, &GPIO_InitStructure) ;
/* Configure as analog input AN_AIN_2_PIN ---------------------------------------------*/
GPIO_InitStructure.GPIO_Pin = AN_AIN_2_PIN ;
GPIO_Init(AN_AIN_2_PORT, &GPIO_InitStructure) ;
/* ADC1 configuration -----------------------------------------------------------------------*/
//温度检测开启, 参考电压开启;
ADC1->CR2 = ADC1->CR2 | ADC_CR2_TSVREFE ;
//VBAT 开关到ADCIN18 开启;
SYSCFG->CFGR1 |= SYSCFG_CFGR1_VBAT ;
/* 规则设置采样时间SampleTime 71.5 个周期 = 7.15 μs ,ADC 转换时间12.5 个周期--------------------------------------------------*/
// 通道0 - 9
ADC1_SMPR2 = (ADC_SampleTime_239Cycles5<<(3*9))|(ADC_SampleTime_239Cycles5<<(3*8))|(ADC_SampleTime_239Cycles5<<(3*7))|(ADC_SampleTime_239Cycles5<<(3*6))|(ADC_SampleTime_239Cycles5<<(3*5))|(ADC_SampleTime_239Cycles5<<(3*4))|(ADC_SampleTime_239Cycles5<<(3*3))|(ADC_SampleTime_239Cycles5<<(3*2))|(ADC_SampleTime_239Cycles5<<(3*1))|(ADC_SampleTime_239Cycles5<<(3*0)) ;
// 通道10 - 18
ADC1_SMPR1 = (ADC_SampleTime_239Cycles5<<(3*8))|(ADC_SampleTime_239Cycles5<<(3*7))|(ADC_SampleTime_239Cycles5<<(3*6))|(ADC_SampleTime_239Cycles5<<(3*5))|(ADC_SampleTime_239Cycles5<<(3*4))|(ADC_SampleTime_239Cycles5<<(3*3))|(ADC_SampleTime_239Cycles5<<(3*2))|(ADC_SampleTime_239Cycles5<<(3*1))|(ADC_SampleTime_239Cycles5<<(3*0)) ;
/* 规则通道设置最多16 个通道,设置 联系 转换的 次序---------------------------------------------------------------------*/
// 规则序列1 - 6
ADC1_SQR3 = ((uint32)ADC_Channel_0<<(5*5))|((uint32)ADC_Channel_0<<(5*4))|((uint32)ADC_Channel_0<<(5*3))|((uint32)ADC_Channel_0<<(5*2))|((uint32)AN_AIN_2_CH<<(5*1))|((uint32)AN_AIN_1_CH<<(5*0)) ;
// 规则序列7 - 12
ADC1_SQR2 = ((uint32)ADC_Channel_0<<(5*5))|((uint32)ADC_Channel_0<<(5*4))|((uint32)ADC_Channel_0<<(5*3))|((uint32)ADC_Channel_0<<(5*2))|((uint32)ADC_Channel_0<<(5*1))|((uint32)ADC_Channel_0<<(5*0)) ;
// 规则序列13 - 16 和总数设置
ADC1_SQR1 = ((uint32)3<20) |((uint32)ADC_Channel_0<<(5*3))|((uint32)ADC_Channel_0<<(5*2))|((uint32)ADC_Channel_0<<(5*1))|((uint32)ADC_Channel_0<<(5*0)) ;
/* 注入通道设置最多4 个通道---------------------------------------------------------------------*/
/* Set injected sequencer length */
//ADC1_JSQR = ((uint32)3<<20)|((uint32)ADC_Channel_3<<(5*3))|((uint32)ADC_Channel_2<<(5*2))|((uint32)ADC_Channel_Vbat<<(5*1))|((uint32)ADC_Channel_TempSensor<<(5*0)) ;
ADC1_JSQR = ((uint32)3<<20)|((uint32)KEY_AIN_1_CH<<(5*3))|((uint32)ADC_Channel_Vbat<<(5*2))|((uint32)ADC_Channel_Vrefint<<(5*1))|((uint32)ADC_Channel_TempSensor<<(5*0)) ;
//设置规则通道的外部触发源
//自动转换连续模式
ADC1->CR2 = ADC1->CR2 | (ADC_CR2_CONT | ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL ) ;
//ADC1_CR2_CONT = 1 ;
//ADC1_CR2_EXTSEL0 = 1 ;
//ADC1_CR2_EXTSEL1 = 1 ;
//ADC1_CR2_EXTSEL2 = 1 ;
//设置自动注入扫描模式
ADC1->CR1 = ADC1->CR1 | (ADC_CR1_SCAN | ADC_CR1_JAUTO ) ;
//ADC1_CR1_SAN = 1 ;
//ADC1_CR1_JAUTO = 1 ;
/* Enable ADC1 */
ADC1->CR2 |= ADC_CR2_ADON ;
/*******************************************ADC 校准*********************************************/
/* Enable ADC1 reset calibaration register */
ADC1->CR2 |= ADC_CR2_RSTCAL ;
/* Check the end of ADC1 reset calibration register */
while(ADC1->CR2 & ADC_CR2_RSTCAL);
/* Start ADC1 calibaration */
ADC1->CR2 |= ADC_CR2_CAL ;
/* Check the end of ADC1 calibration */
while(ADC1->CR2 & ADC_CR2_CAL);
/****************************************************************************************************/
//DMA 通道设置
#if 1
RCC->AHBENR |= RCC_AHBPeriph_DMA1 ;
DMA1_Channel1->CCR = 0 ;
DMA1_Channel1->CNDTR = ADC_Regular_DMA_BufferSize ;
DMA1_Channel1->CPAR = (uint32 )&ADC1_DR ;
DMA1_Channel1->CMAR = (uint32_t)&ADC_RegularConvertedValueTab[0];
DMA1_Channel1->CCR = DMA_M2M_Disable |DMA_Priority|DMA_MemoryDataSize_HalfWord|
DMA_PeripheralDataSize_HalfWord|DMA_MemoryInc_Enable|DMA_PeripheralInc_Disable|
DMA_Mode_Circular|DMA_DIR_PeripheralSRC ;
DMA1_IFCR = 0x0000000F ;
//DMA1_Channel1_CCR_TEIE = 1 ;
//DMA1_Channel1_CCR_HTIE = 1 ;
//DMA1_Channel1_CCR_TCIE = 1 ;
DMA1_Channel1->CCR |= DMA_CCR_EN ;
/* Enable ADC1 DMA */
ADC1->CR2 |= ADC_CR2_DMA ;
#endif
/****************************************************************************************************/
/* Start ADC1 Software Conversion */
/* Enable ADC1 */
ADC1->CR2 |= ADC_CR2_ADON ;
//ADC1_CR2_SWSTART = 1 ;
ADC1->CR2 |= ADC_CR2_JSWSTART| ADC_CR2_SWSTART ;
}
|