环境 : stm32f103cbt6 使用的正点原子的库函数的ADC例程 中断处理函数名字是ADC1_2_IRQHandler,是启动文件中定义的。 单通道 单次 软件触发,adc转换能正确执行
仿真的时候EOCIE置位,EOC标志位转换完成后也置位了,但是没有跳转到中断处理函数。
下边是程序求技术大牛帮助
1主函数
int main(void)
{
u16 adcx;
float temp;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//éèÖÃÖD¶ÏóÅÏ輶·Ö×éÎa×é2£o2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
Adc_Init(); //ADC3õê¼»ˉ
GPIO_SetBits(GPIOA,GPIO_Pin_4);
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_2,10);
temp=(float)adcx*(3.3/4096);
adcx=temp;
delay_ms_repeat(250);
}
}
void Adc_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_ADC1 , ENABLE ); //ê1ÄüADC1í¨μàê±Öó
RCC_ADCCLKConfig(RCC_PCLK2_Div6); //éèÖÃADC·ÖÆμòò×ó6 72M/6=12,ADC×î′óê±¼ä2»Äü3¬1y14M
//PA1 ×÷ÎaÄ£Äaí¨μàêäèëòy½Å
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //Ä£Äaêäèëòy½Å
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //êä3öòy½Å
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_DeInit(ADC1); //¸′λADC1
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1¤×÷Ä£ê½:ADC1oíADC21¤×÷Ôú¶àá¢Ä£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //Ä£êy×a»»1¤×÷Ôúμ¥í¨μàÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //Ä£êy×a»»1¤×÷Ôúμ¥′Î×a»»Ä£ê½
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //×a»»óéèí¼t¶ø2»êÇía2¿′¥·¢Æô¶ˉ
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADCêy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = 1; //Ë3Dò½øDD1æÔò×a»»μÄADCí¨μàμÄêyÄ¿
ADC_Init(ADC1, &ADC_InitStructure); //¸ù¾YADC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèADCxμļÄ′æÆ÷
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);
//éèÖÃÖD¶Ï
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
ADC_Cmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1
ADC_ResetCalibration(ADC1); //ê1Äü¸′λD£×¼
while(ADC_GetResetCalibrationStatus(ADC1)); //μè′y¸′λD£×¼½áêø
ADC_StartCalibration(ADC1); //¿aÆôADD£×¼
while(ADC_GetCalibrationStatus(ADC1)); //μè′yD£×¼½áêø
}
u16 Get_Adc(u8 ch)
{
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 ); //ADC1,ADCí¨μà,2éÑùê±¼äÎa239.5ÖüÆú
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»Æô¶ˉ1|Äü
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//μè′y×a»»½áêø
return ADC_GetConversionValue(ADC1); //·μ»Ø×î½üò»′ÎADC11æÔò×éμÄ×a»»½á1û
}
u16 Get_Adc_Average(u8 ch,u8 times)
{
u32 temp_val=0;
u8 t;
for(t=0;t<times;t++)
{
temp_val+=Get_Adc(ch);
delay_ms_repeat(5);
}
return temp_val/times;
}
3中断处理函数
void ADC1_2_IRQHandler(void)
{
if(ADC_GetITStatus(ADC1,ADC_IT_EOC) == SET)
{
ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>