comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/TIM/InputCapture/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file TIM/InputCapture/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-2011
7 * @brief Main program body
8 ******************************************************************************
9 * @attention
10 *
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
20 */
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x.h"
24
25 /** @addtogroup STM32F10x_StdPeriph_Examples
26 * @{
27 */
28
29 /** @addtogroup TIM_Input_Capture
30 * @{
31 */
32
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 /* Private macro -------------------------------------------------------------*/
36 /* Private variables ---------------------------------------------------------*/
37 TIM_ICInitTypeDef TIM_ICInitStructure;
38
39 /* Private function prototypes -----------------------------------------------*/
40 void RCC_Configuration(void);
41 void GPIO_Configuration(void);
42 void NVIC_Configuration(void);
43
44 /* Private functions ---------------------------------------------------------*/
45
46 /**
47 * @brief Main program
48 * @param None
49 * @retval None
50 */
51 int main(void)
52 {
53 /*!< At this stage the microcontroller clock setting is already configured,
54 this is done through SystemInit() function which is called from startup
55 file (startup_stm32f10x_xx.s) before to branch to application main.
56 To reconfigure the default setting of SystemInit() function, refer to
57 system_stm32f10x.c file
58 */
59
60 /* System Clocks Configuration */
61 RCC_Configuration();
62
63 /* NVIC configuration */
64 NVIC_Configuration();
65
66 /* Configure the GPIO ports */
67 GPIO_Configuration();
68
69 /* TIM3 configuration: Input Capture mode ---------------------
70 The external signal is connected to TIM3 CH2 pin (PA.07)
71 The Rising edge is used as active edge,
72 The TIM3 CCR2 is used to compute the frequency value
73 ------------------------------------------------------------ */
74
75 TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
76 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
77 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
78 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
79 TIM_ICInitStructure.TIM_ICFilter = 0x0;
80
81 TIM_ICInit(TIM3, &TIM_ICInitStructure);
82
83 /* TIM enable counter */
84 TIM_Cmd(TIM3, ENABLE);
85
86 /* Enable the CC2 Interrupt Request */
87 TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
88
89 while (1);
90 }
91
92 /**
93 * @brief Configures the different system clocks.
94 * @param None
95 * @retval None
96 */
97 void RCC_Configuration(void)
98 {
99 /* TIM3 clock enable */
100 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
101
102 /* GPIOA and GPIOB clock enable */
103 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
104 }
105
106 /**
107 * @brief Configure the GPIOD Pins.
108 * @param None
109 * @retval None
110 */
111 void GPIO_Configuration(void)
112 {
113 GPIO_InitTypeDef GPIO_InitStructure;
114
115 /* TIM3 channel 2 pin (PA.07) configuration */
116 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
117 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
118 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
119
120 GPIO_Init(GPIOA, &GPIO_InitStructure);
121 }
122
123 /**
124 * @brief Configure the nested vectored interrupt controller.
125 * @param None
126 * @retval None
127 */
128 void NVIC_Configuration(void)
129 {
130 NVIC_InitTypeDef NVIC_InitStructure;
131
132 /* Enable the TIM3 global Interrupt */
133 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
134 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
135 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
136 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
137 NVIC_Init(&NVIC_InitStructure);
138 }
139
140 #ifdef USE_FULL_ASSERT
141
142 /**
143 * @brief Reports the name of the source file and the source line number
144 * where the assert_param error has occurred.
145 * @param file: pointer to the source file name
146 * @param line: assert_param error line source number
147 * @retval None
148 */
149 void assert_failed(uint8_t* file, uint32_t line)
150 {
151 /* User can add his own implementation to report the file name and line number,
152 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
153
154 while (1)
155 {}
156 }
157
158 #endif
159
160 /**
161 * @}
162 */
163
164 /**
165 * @}
166 */
167
168 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/