你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32L152 AD采集问题

[复制链接]
jikejie135 提问时间:2013-7-30 10:12 /
[url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__ADC1__AnalogWatchdog.html#ga840291bc02cba5474a4cb46a9b9566fe]00061[/url] int [url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__ADC1__AnalogWatchdog.html#ga840291bc02cba5474a4cb46a9b9566fe]main[/url](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   [url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__STM32L152__EVAL__LOW__LEVEL__Private__Functions.html#ga01e1a245e786705357f741c8d42cbd3a]STM_EVAL_LEDInit[/url]([url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__STM32L152D__EVAL__LOW__LEVEL__Exported__Types.html#ggaa059704b7ca945eb9c1e7f2c3d03fecdadac6477842247cab1a8c02c65f431b44]LED1[/url]);
00072
00073 /* Configure PB.12 (ADC1 Channel18) or PF.10 (ADC1 Channel31) in analog mode -*/
00074   GPIO_InitStructure.[url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/structGPIO__InitTypeDef.html#a55bd77e335c2bfeec9caa5dc922b791b]GPIO_Mode[/url]  = [url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__Configuration__Mode__enumeration.html#gga1347339e1c84a196fabbb31205eec5d4a6e5c0d7e6d2e22b834b24e1ca1d6d0db]GPIO_Mode_AN[/url];
00075   GPIO_InitStructure.[url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/structGPIO__InitTypeDef.html#aad62942c003bc2083d37f10f6f39bd5f]GPIO_PuPd[/url]  = [url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__Configuration__Pull-Up__Pull-Down__enumeration.html#ggafb7ecd99c44b4fd702d669304a36c2c8a013a40bdeb6b3f43e02f8e4da896ba51]GPIO_PuPd_NOPULL[/url];
00076  
00077 #if defined USE_STM32L152D_EVAL
00078   /* Enable the GPIOF Clock */
00079   [url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__RCC.html#gae0b30d8598b8393bdba9c3fefba3a968]RCC_AHBPeriphClockCmd[/url]([url=mkMSITStore:E:\盖特信息\煤矿\水文分站\软件\stsw-stm32077\STM32L1xx_StdPeriph_Lib_V1.2.0\stm32l1xx_stdperiph_lib_um.chm::/group__RCC__AHB__Peripherals.html#ga16d4ffadf5b50e96653c8b426d20cc27]RCC_AHBPeriph_GPIOF[/url], 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 发布时间:2013-7-30 10:12

举报

1个回答
lpfzhx 回答时间:2014-12-29 07:34:06
看图,我是这么理解的,不妥之处可以讨论

时钟

时钟

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版