STM32F10x_StdPeriph_Examples/ADC/AnalogWatchdog/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    ADC/AnalogWatchdog/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 #include "stm32_eval.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup ADC_AnalogWatchdog
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 ADC_InitTypeDef  ADC_InitStructure;
00038     
00039 /* Private function prototypes -----------------------------------------------*/
00040 void RCC_Configuration(void);
00041 void GPIO_Configuration(void);
00042 void NVIC_Configuration(void);
00043 
00044 /* Private functions ---------------------------------------------------------*/
00045 
00046 /**
00047   * @brief   Main program
00048   * @param  None
00049   * @retval None
00050   */
00051 int main(void)
00052 {
00053   /*!< At this stage the microcontroller clock setting is already configured, 
00054        this is done through SystemInit() function which is called from startup
00055        file (startup_stm32f10x_xx.s) before to branch to application main.
00056        To reconfigure the default setting of SystemInit() function, refer to
00057        system_stm32f10x.c file
00058      */     
00059        
00060   /* System clocks configuration ---------------------------------------------*/
00061   RCC_Configuration();
00062 
00063   /* NVIC configuration ------------------------------------------------------*/
00064   NVIC_Configuration();
00065 
00066   /* GPIO configuration ------------------------------------------------------*/
00067   GPIO_Configuration();
00068 
00069   /* Configure LED GPIO Pin ------------------------------------------------- */
00070   STM_EVAL_LEDInit(LED1);
00071 
00072   /* ADC1 Configuration ------------------------------------------------------*/
00073   ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
00074   ADC_InitStructure.ADC_ScanConvMode = DISABLE;
00075   ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
00076   ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
00077   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
00078   ADC_InitStructure.ADC_NbrOfChannel = 1;
00079   ADC_Init(ADC1, &ADC_InitStructure);
00080 
00081   /* ADC1 regular channel14 configuration */ 
00082   ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);
00083 
00084   /* Configure high and low analog watchdog thresholds */
00085   ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0B00, 0x0300);
00086   /* Configure channel14 as the single analog watchdog guarded channel */
00087   ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_14);
00088   /* Enable analog watchdog on one regular channel */
00089   ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
00090 
00091   /* Enable AWD interupt */
00092   ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
00093 
00094   /* Enable ADC1 */
00095   ADC_Cmd(ADC1, ENABLE);
00096 
00097   /* Enable ADC1 reset calibaration register */   
00098   ADC_ResetCalibration(ADC1);
00099   /* Check the end of ADC1 reset calibration register */
00100   while(ADC_GetResetCalibrationStatus(ADC1));
00101 
00102   /* Start ADC1 calibaration */
00103   ADC_StartCalibration(ADC1);
00104   /* Check the end of ADC1 calibration */
00105   while(ADC_GetCalibrationStatus(ADC1));
00106 
00107   /* Start ADC1 Software Conversion */ 
00108   ADC_SoftwareStartConvCmd(ADC1, ENABLE);
00109 
00110   while (1)
00111   {
00112   }
00113 }
00114 
00115 /**
00116   * @brief  Configures the different system clocks.
00117   * @param  None
00118   * @retval None
00119   */
00120 void RCC_Configuration(void)
00121 {
00122 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
00123   /* ADCCLK = PCLK2/2 */
00124   RCC_ADCCLKConfig(RCC_PCLK2_Div2);
00125 #else
00126   /* ADCCLK = PCLK2/4 */
00127   RCC_ADCCLKConfig(RCC_PCLK2_Div4); 
00128 #endif
00129 /* Enable peripheral clocks --------------------------------------------------*/
00130   /* Enable ADC1 and GPIO_LED clock */
00131   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
00132 }
00133 
00134 /**
00135   * @brief  Configures the different GPIO ports.
00136   * @param  None
00137   * @retval None
00138   */
00139 void GPIO_Configuration(void)
00140 {
00141   GPIO_InitTypeDef GPIO_InitStructure;
00142 
00143   /* Configure PC.04 (ADC Channel14) as analog input -------------------------*/
00144   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
00145   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
00146   GPIO_Init(GPIOC, &GPIO_InitStructure);
00147 }
00148 
00149 /**
00150   * @brief  Configures NVIC and Vector Table base location.
00151   * @param  None
00152   * @retval None
00153   */
00154 void NVIC_Configuration(void)
00155 {
00156   NVIC_InitTypeDef NVIC_InitStructure;
00157 
00158   /* Configure and enable ADC interrupt */
00159 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
00160   NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;
00161 #else
00162   NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
00163 #endif
00164   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00165   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00166   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00167   NVIC_Init(&NVIC_InitStructure);
00168 }
00169 
00170 #ifdef  USE_FULL_ASSERT
00171 
00172 /**
00173   * @brief  Reports the name of the source file and the source line number
00174   *         where the assert_param error has occurred.
00175   * @param  file: pointer to the source file name
00176   * @param  line: assert_param error line source number
00177   * @retval None
00178   */
00179 void assert_failed(uint8_t* file, uint32_t line)
00180 { 
00181   /* User can add his own implementation to report the file name and line number,
00182      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00183 
00184   /* Infinite loop */
00185   while (1)
00186   {
00187   }
00188 }
00189 #endif
00190 
00191 /**
00192   * @}
00193   */ 
00194 
00195 /**
00196   * @}
00197   */ 
00198 
00199 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32