直接上程序 时钟已经是56M
void ADC_Configuration(void)
{
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADCConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel1, ENABLE);
/* 定义 ADC 初始化结构体 ADC_InitStructure */
ADC_InitTypeDef ADC_InitStructure;
/*
* 独立工作模式;
* 多通道扫描模式;
* 连续模数转换模式;
* 转换触发方式:转换由软件触发启动;
* ADC 数据右对齐 ;
* 进行规则转换的 ADC 通道的数目为1;
*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/*配置ADC时钟,为PCLK2的8分频,即8MHz*/
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
/* 设置 ADC1 使用8转换通道,采样时间为 55.5 周期 */
//ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_55Cycles5);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_55Cycles5);
ADC_DMACmd(ADC1, ENABLE);
ADC_InjectedSequencerLengthConfig(ADC1, 1);
ADC_InjectedChannelConfig(ADC1,ADC_Channel_8,1,ADC_SampleTime_1Cycles5);
ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE);
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4);//设置注入通道T1比较4中断触发
/* Enable JEOC interupt */
ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
/* 使能 ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* 复位 ADC1 的校准寄存器 */
ADC_ResetCalibration(ADC1);
/* 等待 ADC1 校准寄存器复位完成 */
while(ADC_GetResetCalibrationStatus(ADC1));
/* 开始 ADC1 校准 */
ADC_StartCalibration(ADC1);
/* 等待 ADC1 校准完成 */
while(ADC_GetCalibrationStatus(ADC1));
/* 启动 ADC1 转换 */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
} |