初始化代码见后面。目的是利用PB2的Exti来触发ADC4的3通道(PB12)
如果在main函数里,用ADC_StartConversion(ADC4)来打开转换,是可以得到正确值的。说明,adc的配置大部分应该正确的。
或者开pb2的exti中断,在中断里用ADC_StartConversion(ADC4)也可以正常打开adc转换。说明pb2的配置应该基本正确。
但是,就是无法实现pb2的脉冲上升沿自动触发一次adc转换。
请帮忙指点一下,问题在哪里
下面是用pb2的脉冲上升沿自动触发adc转换的初始化代码,求指点。
ADC_InitTypeDef ADC_InitStructure;//定义ADC初始化结构体变量
ADC_CommonInitTypeDef ADC_CommonInitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
//ADC Pin
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Trig Pin
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource2);
EXTI_ClearITPendingBit(EXTI_Line2);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;//EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
// NVIC_InitStructure.NVIC_IRQChannel = EXTI2_TS_IRQn; /**< 注意 10~15 中断源合在了一起 */
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
//设置ADC时钟为72M/6=12MHz
RCC_ADCCLKConfig(RCC_ADC34PLLCLK_Div4);
//启动ADC1时钟
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC34, ENABLE);
ADC_StructInit(&ADC_InitStructure);
/* Calibration procedure */
ADC_VoltageRegulatorCmd(ADC4, ENABLE);
/* Insert delay equal to 10 祍 */
Delay(0xFFFF);
ADC_SelectCalibrationMode(ADC4, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC4);
while(ADC_GetCalibrationStatus(ADC4) != RESET );
ADC_GetCalibrationValue(ADC4);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //主要是这一句,用来关掉双ADC模式
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
ADC_CommonInit(ADC4, &ADC_CommonInitStructure);
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_5;//ADC_ExternalTrigConvEvent_5;
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_RisingEdge;//ADC_ExternalTrigEventEdge_RisingEdge;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel = 1;
ADC_Init(ADC4, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC4, ADC_Channel_3, 1, ADC_SampleTime_19Cycles5);
/* Regular discontinuous mode channel number configuration */
ADC_DiscModeChannelCountConfig(ADC4, 1);
/* Enable regular discontinuous mode */
ADC_DiscModeCmd(ADC4, ENABLE);
ADC_DMACmd(ADC4, DISABLE);//使能ADC1模块DMA
ADC_Cmd(ADC4, ENABLE);//使能ADC1
while(!ADC_GetFlagStatus(ADC4, ADC_FLAG_RDY)); |