2019-07-20 22:32发布
Zx1291 发表于 2016-3-4 09:11 用定时器的事件触发,不需要用到中断的,所以也不需要用到中断配置
Zx1291 发表于 2016-3-4 11:35 你用的是f1吗?定时器触发就不需要软件触发啊
最多设置5个标签!
[mw_shl_code=c,true]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_5;//PA5 í¨μà5
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_Disabled; //DMAê§Äü
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 = DISABLE;//·Çé¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//1رÕá¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
//ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//½ûÖ1′¥·¢¼ì2a£¬ê1óÃèí¼t′¥·¢
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//óò¶ÔÆë
ADC_InitStructure.ADC_NbrOfConversion = 1;//1¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD1
ADC_Init(ADC1, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_Cmd(ADC1, ENABLE);//¿aÆôAD×a»»Æ÷
//ADC_ExternalTrigConvCmd(ADC1, ENABLE); //ía2¿′¥·¢ê1Äü
}
//»ñμÃADCÖμ
//ch: @ref ADC_channels
//í¨μàÖμ 0~16è¡Öμ·¶Î§Îa£oADC_Channel_0~ADC_Channel_16
//·μ»ØÖμ:×a»»½á1û
u16 Get_Adc(u8 ch)
{
//éèÖÃÖ¸¶¨ADCμÄ1æÔò×éí¨μ࣬ò»¸öDòáD£¬2éÑùê±¼ä
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_480Cycles ); //ADC1,ADCí¨μà,480¸öÖüÆú,ìá¸ß2éÑùê±¼ä¿éòÔìá¸ß¾«è·¶è
ADC_SoftwareStartConv(ADC1); //ê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»Æô¶ˉ1|Äü
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//μè′y×a»»½áêø
return ADC_GetConversionValue(ADC1); //·μ»Ø×î½üò»′ÎADC11æÔò×éμÄ×a»»½á1û
}[/mw_shl_code]噢,定时器中断里面也没干啥。关键是没有触发到adc采样,显示的数据为0
用的f4
一周热门 更多>