2015-04-09 09:49 PM
Hi all,
When I using ADC it work correctly, but when I want MCU enter STOP(or standby) mode and wakup by external interrupt, ADC is hang, can not convert ADC./** ****************************************************************************** * @file PWR_STOP/main.c * @author MCD Application Team * @version V1.1.0 * @date 20-September-2012 * @brief Main program body ****************************************************************************** * @attention * * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> * * Licensed under MCD-ST Liberty SW License Agreement V2, (the ''License''); * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.st.com/software_license_agreement_liberty_v2 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an ''AS IS'' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/#include ''main.h''/** @addtogroup STM32F3_Discovery_Peripheral_Examples * @{ *//** @addtogroup PWR_STOP * @{ */ #if 1/* Private typedef -----------------------------------------------------------*//* Private define ------------------------------------------------------------*//* Private macro -------------------------------------------------------------*//* Private variables ---------------------------------------------------------*/RTC_TimeTypeDef RTC_TimeStructure;RTC_InitTypeDef RTC_InitStructure;RTC_AlarmTypeDef RTC_AlarmStructure;EXTI_InitTypeDef EXTI_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;__IO uint32_t TimingDelay;/* Private function prototypes -----------------------------------------------*/void Delay(__IO uint32_t nTime);__IO uint16_t ADC1ConvertedValue = 0, ADC1ConvertedVoltage = 0, calibration_value = 0;__IO uint32_t TimingDelay = 0;ADC_InitTypeDef ADC_InitStructure;ADC_CommonInitTypeDef ADC_CommonInitStructure;GPIO_InitTypeDef GPIO_InitStructure;/* Private functions ---------------------------------------------------------*/int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ /* Configure the ADC clock */ RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2); /* Enable ADC1 clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE); /* Setup SysTick Timer for 1 µsec interrupts */ if (SysTick_Config(SystemCoreClock / 1000000)) { /* Capture error */ while (1) {} } RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Configures the USER button */ STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_EXTI); /* ADC Channel configuration */ /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure ADC Channel7 as analog input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure); ADC_StructInit(&ADC_InitStructure); /* Calibration procedure */ ADC_VoltageRegulatorCmd(ADC1, ENABLE); /* Insert delay equal to 10 µs */ Delay(10); ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1) != RESET ); calibration_value = ADC_GetCalibrationValue(ADC1); ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; 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(ADC1, &ADC_CommonInitStructure); ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0; ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; 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(ADC1, &ADC_InitStructure); /* ADC1 regular channel7 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_7Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* wait for ADRDY */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY)); /* Start ADC1 Software Conversion */ ADC_StartConversion(ADC1); /* Request to enter STOP mode with regulator in low power mode */ // PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Infinite loop */ while (1) { /* Test EOC flag */ while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); /* Get ADC1 converted data */ ADC1ConvertedValue =ADC_GetConversionValue(ADC1); /* Compute the voltage */ ADC1ConvertedVoltage = (ADC1ConvertedValue *3300)/0xFFF; }}Please give me a help.Thanks2015-04-09 09:50 PM