下面是我的程序,请大神们帮忙看看,新手刚刚开始学。。 /**************************************************************/ /** * @brief Configure the TIM3 IRQ Handler. * @param None * @retval None */ static __IO uint16_t PrescalerValue_TIM3=48; void TIM3_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; /* TIM3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* Enable the TIM3 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configuration of TIM3 */ TIM_InternalClockConfig(TIM3); //use internal clock TIM_TimeBaseInit(TIM3,TIM_TimeBaseInitStruct); TIM_PrescalerConfig(TIM3,PrescalerValue_TIM3,0); TIM_CounterModeConfig(TIM3,TIM_CounterMode_Up); TIM_SetCounter(TIM3,0); TIM_SetAutoreload(TIM3,1000); TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); } /**************************************************************/ /** * @brief Configure the ADC. * @param None * @retval None */ void ADC_Config(void) { ADC_InitTypeDef ADC_InitStructure; /* ADC1 Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits*/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; ADC_Init(ADC1, &ADC_InitStructure); /* Convert the ADC1 Channel 11 with 239.5 Cycles as sampling time */ ADC_ChannelConfig(ADC1, ADC_Channel_0 , ADC_SampleTime_239_5Cycles); ADC_ChannelConfig(ADC1, ADC_Channel_1 , ADC_SampleTime_239_5Cycles); /* ADC Calibration */ ADC_GetCalibrationFactor(ADC1); /* Enable the auto delay feature */ ADC_WaitModeCmd(ADC1, ENABLE); /* Enable the Auto power off mode */ ADC_AutoPowerOffCmd(ADC1, ENABLE); /* Enable ADCperipheral[PerIdx] */ ADC_Cmd(ADC1, ENABLE); /* Wait the ADCEN flag */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); /* ADC1 regular Software Start Conversion */ ADC_StartOfConversion(ADC1); } /**************************************************************/ /** * @brief Main program * @param None * @retval None */ static __IO uint16_t ADC1ConvertedValue = 0; static __IO float ADC1ConvertedVoltage = 0.0; int main(void) { /* Initialize Leds mounted on STM32F0-discovery */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PWMInit(PWM1); STM_EVAL_ADInit(AD0); STM_EVAL_ADInit(AD1); /* Initialize User_Button on STM32F0-Discovery */ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); /* TIM Configuration */ TIM2_Config(); TIM3_Config(); /* ADC Configuration */ ADC_Config(); /* Setup SysTick Timer for 1 msec interrupts */ if(SysTick_Config(SystemCoreClock / 1000)) { while (1); } /* Infinite loop */ while(1) { key_LED3(); //if(sign_instant[5]==1) //{ //sign_instant[5]=0; /* Get ADC1 converted data */ //ADC1ConvertedValue = ADC_GetConversionValue(ADC1); /* Compute the voltage */ //ADC1ConvertedVoltage = (ADC1ConvertedValue*3.3)/0xFFF; //} } } /**************************************************************/ 下面是我ADC的GPIO口初始化的程序 #define ADn 2 #define AD0_PIN GPIO_Pin_0 #define AD0_GPIO_PORT GPIOA #define AD0_GPIO_CLK RCC_AHBPeriph_GPIOA #define AD1_PIN GPIO_Pin_1 #define AD1_GPIO_PORT GPIOA #define AD1_GPIO_CLK RCC_AHBPeriph_GPIOA GPIO_TypeDef* AD_PORT[ADn] = {AD0_GPIO_PORT, AD1_GPIO_PORT}; const uint16_t AD_PIN[ADn] = {AD0_PIN, AD1_PIN}; const uint32_t AD_CLK[ADn] = {AD0_GPIO_CLK, AD1_GPIO_CLK}; void STM_EVAL_ADInit(AD_TypeDef ad) { GPIO_InitTypeDef GPIO_InitStructure; /* GPIOA Clocks enable */ RCC_AHBPeriphClockCmd(AD_CLK[ad], ENABLE); /* GPIOA Configuration: Channel 1 as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = AD_PIN[ad]; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(AD_PORT[ad], &GPIO_InitStructure); } |
RE:stm32f0编程,一打开ADC时钟,TIM3的中断就不起作用了
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
这条指令双斜杠了,就TIM3的中断就正常了
RE:stm32f0编程,一打开ADC时钟,TIM3的中断就不起作用了