STM32F10x_StdPeriph_Examples/TIM/InputCapture/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM/InputCapture/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 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup TIM_Input_Capture
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 /* Private macro -------------------------------------------------------------*/
00035 /* Private variables ---------------------------------------------------------*/
00036 TIM_ICInitTypeDef  TIM_ICInitStructure;
00037 
00038 /* Private function prototypes -----------------------------------------------*/
00039 void RCC_Configuration(void);
00040 void GPIO_Configuration(void);
00041 void NVIC_Configuration(void);
00042 
00043 /* Private functions ---------------------------------------------------------*/
00044 
00045 /**
00046   * @brief   Main program
00047   * @param  None
00048   * @retval None
00049   */
00050 int main(void)
00051 {
00052   /*!< At this stage the microcontroller clock setting is already configured, 
00053        this is done through SystemInit() function which is called from startup
00054        file (startup_stm32f10x_xx.s) before to branch to application main.
00055        To reconfigure the default setting of SystemInit() function, refer to
00056        system_stm32f10x.c file
00057      */     
00058        
00059   /* System Clocks Configuration */
00060   RCC_Configuration();
00061 
00062   /* NVIC configuration */
00063   NVIC_Configuration();
00064 
00065   /* Configure the GPIO ports */
00066   GPIO_Configuration();
00067 
00068   /* TIM3 configuration: Input Capture mode ---------------------
00069      The external signal is connected to TIM3 CH2 pin (PA.07)  
00070      The Rising edge is used as active edge,
00071      The TIM3 CCR2 is used to compute the frequency value 
00072   ------------------------------------------------------------ */
00073 
00074   TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
00075   TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
00076   TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
00077   TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
00078   TIM_ICInitStructure.TIM_ICFilter = 0x0;
00079 
00080   TIM_ICInit(TIM3, &TIM_ICInitStructure);
00081   
00082   /* TIM enable counter */
00083   TIM_Cmd(TIM3, ENABLE);
00084 
00085   /* Enable the CC2 Interrupt Request */
00086   TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
00087 
00088   while (1);
00089 }
00090 
00091 /**
00092   * @brief  Configures the different system clocks.
00093   * @param  None
00094   * @retval None
00095   */
00096 void RCC_Configuration(void)
00097 {
00098   /* TIM3 clock enable */
00099   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
00100 
00101   /* GPIOA and GPIOB clock enable */
00102   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
00103 }
00104 
00105 /**
00106   * @brief  Configure the GPIOD Pins.
00107   * @param  None
00108   * @retval None
00109   */
00110 void GPIO_Configuration(void)
00111 {
00112   GPIO_InitTypeDef GPIO_InitStructure;
00113 
00114   /* TIM3 channel 2 pin (PA.07) configuration */
00115   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_7;
00116   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00117   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00118 
00119   GPIO_Init(GPIOA, &GPIO_InitStructure);
00120 }
00121 
00122 /**
00123   * @brief  Configure the nested vectored interrupt controller.
00124   * @param  None
00125   * @retval None
00126   */
00127 void NVIC_Configuration(void)
00128 {
00129   NVIC_InitTypeDef NVIC_InitStructure;
00130 
00131   /* Enable the TIM3 global Interrupt */
00132   NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
00133   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00134   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
00135   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00136   NVIC_Init(&NVIC_InitStructure);
00137 }
00138 
00139 #ifdef  USE_FULL_ASSERT
00140 
00141 /**
00142   * @brief  Reports the name of the source file and the source line number
00143   *         where the assert_param error has occurred.
00144   * @param  file: pointer to the source file name
00145   * @param  line: assert_param error line source number
00146   * @retval None
00147   */
00148 void assert_failed(uint8_t* file, uint32_t line)
00149 {
00150   /* User can add his own implementation to report the file name and line number,
00151      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00152 
00153   while (1)
00154   {}
00155 }
00156 #endif
00157 
00158 /**
00159   * @}
00160   */ 
00161 
00162 /**
00163   * @}
00164   */ 
00165 
00166 /******************* (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