| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

MFT_Mode_2_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : MFT_Mode_2_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the MFT Mode 2 functionality
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
160 /* Includes ------------------------------------------------------------------*/
161 #include "BlueNRG1.h"
162 #include "BlueNRG1_conf.h"
163 #include "SDK_EVAL_Config.h"
164
165
179 /* Private typedef -----------------------------------------------------------*/
180 /* Private define ------------------------------------------------------------*/
181 #define IO_CAPTURE_PIN_MFT1_TIMERA 2 /* IO2 */
182 #define IO_CAPTURE_PIN_MFT1_TIMERB 3 /* IO3 */
183
184 /* Private macro -------------------------------------------------------------*/
185 /* Private variables ---------------------------------------------------------*/
186 FlagStatus fA_found = RESET;
187 FlagStatus fB_found = RESET;
188
189 /* Private function prototypes -----------------------------------------------*/
190 void MFT_Configuration(void);
191
192 /* Private functions ---------------------------------------------------------*/
193
194
195
201 int main(void)
202 {
203 /* System initialization function */
204 SystemInit();
205
206 /* Identify BlueNRG1 platform */
207 SdkEvalIdentification();
208
209 /* LEDs initialization */
210 SdkEvalLedInit(LED1);
211 SdkEvalLedInit(LED2);
212
213 /* IO2 for TnCRA */
214 MFT_SelectCapturePin(MFT1_TIMERA, IO_CAPTURE_PIN_MFT1_TIMERA);
215
216 /* IO3 for TnCRB */
217 MFT_SelectCapturePin(MFT1_TIMERB, IO_CAPTURE_PIN_MFT1_TIMERB);
218
219 /* MFT configuration */
220 MFT_Configuration();
221
222 /* Configure edge detection on falling edge for TnA and TnB */
223 MFT_TnEDGES(MFT1, MFT_FALLING, MFT_FALLING);
224
225 /* Disable preset for CNT1 on TnA and TnB event */
226 MFT_TnXEN(MFT1, MFT_TnA, DISABLE);
227 MFT_TnXEN(MFT1, MFT_TnB, DISABLE);
228
229 /* Enable all MFT interrupt */
230 MFT_EnableIT(MFT1, MFT_IT_TNA | MFT_IT_TNB | MFT_IT_TNC, ENABLE);
231
232 /* Start MFT1 timer */
233 MFT_Cmd(MFT1, ENABLE);
234
235 /* Infinite loop */
236 while(1) {
237
238 /* If input signal frequency on IN_PIN1 is 1kHz OUT_PIN2 is in LOW state */
239 if (fA_found == SET) {
240 SdkEvalLedOn(LED1);
241 }
242 else {
243 SdkEvalLedOff(LED1);
244 }
245
246 /* If input signal frequency on IN_PIN2 is 10kHz OUT_PIN3 is in LOW state */
247 if (fB_found == SET) {
248 SdkEvalLedOn(LED2);
249 }
250 else {
251 SdkEvalLedOff(LED2);
252 }
253
254 }
255 }
256
257
258
264 void MFT_Configuration()
265 {
266 MFT_InitType timer_init;
267 NVIC_InitType NVIC_InitStructure;
268
269 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_MTFX1, ENABLE);
270
271 /* Init MFT1 in mode 2 */
272 timer_init.MFT_Clock1 = MFT_PRESCALED_CLK;
273 timer_init.MFT_Clock2 = MFT_NO_CLK;
274 timer_init.MFT_Mode = MFT_MODE_2;
275 timer_init.MFT_CRA = 0xFFFF;
276 timer_init.MFT_CRB = 0xFFFF;
277
278 /* If a square waveform is @ input with a frequency of 10kHz => T = 100 us
279 *
280 * with Prescaler = 16 - 1; => 1us sampling period
281 * the counter number within a period is 100.
282 *
283 * with Prescaler = 1 - 1; => 62.5ns sampling period
284 * the counter number within a period is 16000.
285 */
286 timer_init.MFT_Prescaler = 1-1;
287
288 MFT_Init(MFT1, &timer_init);
289
290 MFT_SetCounter(MFT1, 0xFFFF, 0xFFFF);
291
292 /* Enable MFT Interrupts */
293 NVIC_InitStructure.NVIC_IRQChannel = MFT1A_IRQn;
294 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LOW_PRIORITY;
295 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
296 NVIC_Init(&NVIC_InitStructure);
297 }
298
299 #ifdef USE_FULL_ASSERT
300
307 void assert_failed(uint8_t* file, uint32_t line)
308 {
309 /* User can add his own implementation to report the file name and line number,
310 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
311
312 /* Infinite loop */
313 while (1)
314 {
315 }
316 }
317
318 #endif
319
332 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
IO_CAPTURE_PIN_MFT1_TIMERB
#define IO_CAPTURE_PIN_MFT1_TIMERB
Definition: MFT_Mode_2_main.c:182
main
int main(void)
Main program code.
Definition: MFT_Mode_2_main.c:201
fA_found
FlagStatus fA_found
Definition: MFT_Mode_2_main.c:186
MFT_Configuration
void MFT_Configuration(void)
MFT_Configuration.
Definition: MFT_Mode_2_main.c:264
IO_CAPTURE_PIN_MFT1_TIMERA
#define IO_CAPTURE_PIN_MFT1_TIMERA
Definition: MFT_Mode_2_main.c:181
fB_found
FlagStatus fB_found
Definition: MFT_Mode_2_main.c:187