目的是为了实现外部给一个信号就转换一组规则组,用的是EXIT_11选做PF11口,接了按键0所在的PE2,希望通过按键来实现外部触发来AD转换,但是无论我的按键却没有反应,始终运行之后都会转换一组(无论我按不按键,有时候还会转换两组)然后就没反应了,是我没启动中断触发AD吗?可是该配置的函数我都配置了才对?
void Adc_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó
//Ïè3õê¼»ˉADC1í¨μà5 IO¿ú
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4;//ê1ÄüáËADC1μÄ0£¬1£¬2í¨μà
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); //ADC1¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //¸′λ½áêø
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//¶àá¢Ä£ê½
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//ὸö2éÑù½×¶ÎÖ®¼äμÄÑó3ù5¸öê±Öó
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; //DMAÄ£꽶t
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//Ô¤·ÖÆμ4·ÖÆμ¡£ADCCLK=PCLK2/4=84/4=21Mhz,ADCê±Öó×îoÃ2»òa3¬1y36Mhz
ADC_CommonInit(&ADC_CommonInitStructure);//3õê¼»ˉ
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12λÄ£ê½
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//é¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//¿aÆôá¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConvEdge =ADC_ExternalTrigConvEdge_Rising; //?????
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_Ext_IT11; //??exti_11??
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//óò¶ÔÆë
ADC_InitStructure.ADC_NbrOfConversion = 2;//3¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD3
ADC_Init(ADC1, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_3Cycles);
ADC_DMACmd(ADC1, ENABLE);
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
ADC_Cmd(ADC1, ENABLE);//¿aÆôAD×a»»Æ÷
//ADC_DMACmd(ADC2, ENABLE);
// ADC_Cmd(ADC2, ENABLE);//¿aÆôAD×a»»Æ÷
//ADC_DMACmd(ADC3, ENABLE);
//ADC_Cmd(ADC3, ENABLE);//¿aÆôAD×a»»Æ÷
EXTIX_Init();
ADC_SoftwareStartConv(ADC1);
//ADC_SoftwareStartConv(ADC2);
// ADC_SoftwareStartConv(ADC3);
}
void EXTIX_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
KEY_Init();
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_11;//ê1ÄüáËADC10£11£¬¬12í¨μà
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOF, &GPIO_InitStructure);//3õê¼»ˉ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//ê1ÄüSYSCFGê±Öó
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF, EXTI_PinSource11);//PF11 ᬽóμ½ÖD¶ÏÏß11
/* ÅäÖÃEXTI_Line0 */
EXTI_InitStructure.EXTI_Line = EXTI_Line11;//LINE0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;//ÖD¶Ïê¼t
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //éÏéyÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//ê1ÄüLINE0
EXTI_Init(&EXTI_InitStructure);//ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;//ía2¿ÖD¶Ï0 ????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;//ÇàÕ¼óÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
}
因为为事件触发,所以不用写中断处理函数。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
已解决,是触发管脚的模式设置错了,应该是IO模式我设置成模拟模式了
一周热门 更多>