STM32L152 AD采集问题
00061 int main(void)00062 {
00063 /*!< At this stage the microcontroller clock setting is already configured,
00064 this is done through SystemInit() function which is called from startup
00065 file (startup_stm32l1xx_xx.s) before to branch to application main.
00066 To reconfigure the default setting of SystemInit() function, refer to
00067 system_stm32l1xx.c file
00068 */
00069
00070 /* Configure LED1 available on STM32L152X-EVAL board ---------------------- */
00071 STM_EVAL_LEDInit(LED1);
00072
00073 /* Configure PB.12 (ADC1 Channel18) or PF.10 (ADC1 Channel31) in analog mode -*/
00074 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
00075 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
00076
00077 #if defined USE_STM32L152D_EVAL
00078 /* Enable the GPIOF Clock */
00079 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
00080 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
00081 GPIO_Init(GPIOF, &GPIO_InitStructure);
00082 #elif defined USE_STM32L152_EVAL
00083 /* Enable the GPIOB Clock */
00084 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
00085 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
00086 GPIO_Init(GPIOB, &GPIO_InitStructure);
00087 #endif
00088
00089 /* Enable the HSI */
00090 RCC_HSICmd(ENABLE);
00091 /* Wait until HSI oscillator is ready */
00092 while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
00093
00094 /* Enable ADC1 clock */
00095 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
00096 /* ADC1 Configuration -----------------------------------------------------*/
00097 ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
00098 ADC_InitStructure.ADC_ScanConvMode = ENABLE;
00099 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
00100 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
00101 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
00102 ADC_InitStructure.ADC_NbrOfConversion = 1;
00103 ADC_Init(ADC1, &ADC_InitStructure);
00104
00105 #if defined USE_STM32L152D_EVAL
00106 /* ADC1 regular channel31 configuration */
00107 ADC_RegularChannelConfig(ADC1, ADC_Channel_31, 1, ADC_SampleTime_16Cycles);
00108 #elif defined USE_STM32L152_EVAL
00109 /* ADC1 regular channel18 configuration */
00110 ADC_RegularChannelConfig(ADC1, ADC_Channel_18, 1, ADC_SampleTime_16Cycles);
00111 #endif
00112
00113
00114 /* Configure high and low analog watchdog thresholds */
00115 ADC_AnalogWatchdogThresholdsConfig(ADC1, 0xE8B, 0x26D);
00116
00117 #if defined USE_STM32L152D_EVAL
00118 /* Configure channel31 as the single analog watchdog guarded channel */
00119 ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_31);
00120 /* Enable analog watchdog on one regular channel: channel31 */
00121 ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
00122 #elif defined USE_STM32L152_EVAL
00123 /* Configure channel18 as the single analog watchdog guarded channel */
00124 ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_18);
00125 /* Enable analog watchdog on one regular channel: channel18 */
00126 ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
00127 #endif
00128
00129 /* Configure and enable ADC1 interrupt */
00130 NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;
00131 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00132 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00133 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00134 NVIC_Init(&NVIC_InitStructure);
00135
00136 /* Enable AWD interrupt */
00137 ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
00138
00139 /* Enable ADC1 */
00140 ADC_Cmd(ADC1, ENABLE);
00141
00142 /* Wait until the ADC1 is ready */
00143 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
00144 {
00145 }
00146
00147 /* Start ADC1 Software Conversion */
00148 ADC_SoftwareStartConv(ADC1);
00149
00150 while (1)
00151 {
00152 }
00153 }
在这个文档中,为何必须使用内部时钟,AD才能运行,如果我使用外部时钟,程序一直运行在while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)处,
请指教 看图,我是这么理解的,不妥之处可以讨论
页:
[1]