STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/TIM/TIM_InputCapture/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM/TIM_InputCapture/main.c  
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    24-July-2014
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "main.h"
00030 
00031 /** @addtogroup STM32F0xx_StdPeriph_Examples
00032   * @{
00033   */
00034 
00035 /** @addtogroup TIM_InputCapture
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 
00044 
00045 /* Private function prototypes -----------------------------------------------*/
00046 static void TIM_Config(void);
00047 /* Private functions ---------------------------------------------------------*/
00048 
00049 /**
00050   * @brief  Main program.
00051   * @param  None
00052   * @retval None
00053   */
00054 int main(void)
00055 {
00056   /*!< At this stage the microcontroller clock setting is already configured, 
00057        this is done through SystemInit() function which is called from startup
00058        file (startup_stm32f0xx.s) before to branch to application main.
00059        To reconfigure the default setting of SystemInit() function, refer to
00060        system_stm32f0xx.c file
00061      */ 
00062 
00063   /* TIM Configuration */
00064   TIM_Config();
00065 
00066   /* Infinite loop */
00067   while (1)
00068   {
00069   }
00070 }
00071 
00072 /**
00073   * @brief  Configure the TIM1 Pins.
00074   * @param  None
00075   * @retval None
00076   */
00077 static void TIM_Config(void)
00078 {
00079   TIM_ICInitTypeDef  TIM_ICInitStructure;
00080   GPIO_InitTypeDef GPIO_InitStructure;
00081   NVIC_InitTypeDef NVIC_InitStructure;
00082   
00083   /* TIM1 clock enable */
00084   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
00085 
00086   /* GPIOA clock enable */
00087   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
00088   
00089   /* TIM1 channel 2 pin (PE.11) configuration */
00090   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9;
00091   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
00092   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00093   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
00094   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
00095   GPIO_Init(GPIOA, &GPIO_InitStructure);
00096 
00097   /* Connect TIM pins to AF2 */
00098   GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);
00099   
00100   /* TIM1 configuration: Input Capture mode ---------------------
00101      The external signal is connected to TIM1 CH2 pin (PA.09)  
00102      The Rising edge is used as active edge,
00103      The TIM1 CCR2 is used to compute the frequency value 
00104   ------------------------------------------------------------ */
00105 
00106   TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
00107   TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
00108   TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
00109   TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
00110   TIM_ICInitStructure.TIM_ICFilter = 0x0;
00111 
00112   TIM_ICInit(TIM1, &TIM_ICInitStructure);
00113   
00114   /* TIM enable counter */
00115   TIM_Cmd(TIM1, ENABLE);
00116 
00117   /* Enable the CC2 Interrupt Request */
00118   TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);
00119   
00120   /* Enable the TIM1 global Interrupt */
00121   NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
00122   NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
00123   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00124   NVIC_Init(&NVIC_InitStructure);
00125   
00126 }
00127 
00128 #ifdef  USE_FULL_ASSERT
00129 
00130 /**
00131   * @brief  Reports the name of the source file and the source line number
00132   *         where the assert_param error has occurred.
00133   * @param  file: pointer to the source file name
00134   * @param  line: assert_param error line source number
00135   * @retval None
00136   */
00137 void assert_failed(uint8_t* file, uint32_t line)
00138 { 
00139   /* User can add his own implementation to report the file name and line number,
00140      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00141 
00142   /* Infinite loop */
00143   while (1)
00144   {
00145   }
00146 }
00147 #endif
00148 
00149 /**
00150   * @}
00151   */
00152 
00153 /**
00154   * @}
00155   */
00156 
00157 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32