| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

MFT_Mode_3_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : MFT_Mode_3_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the MFT Mode 3 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
157 /* Includes ------------------------------------------------------------------*/
158 #include "BlueNRG1.h"
159 #include "BlueNRG1_conf.h"
160 #include "SDK_EVAL_Config.h"
161
175 /* Private typedef -----------------------------------------------------------*/
176 /* Private define ------------------------------------------------------------*/
177
178 #define IO_CAPTURE_PIN_MFT1_TIMERB 3 /* IO3 */
179
180 /* Private macro -------------------------------------------------------------*/
181 /* Private variables ---------------------------------------------------------*/
182 extern FlagStatus output_status;
183
184 /* Private function prototypes -----------------------------------------------*/
185 /* Private functions ---------------------------------------------------------*/
186 void GPIO_Configuration(void);
187 void MFT_Configuration(void);
188
194 int main(void)
195 {
196 /* System initialization function */
197 SystemInit();
198
199 /* Identify BlueNRG1 platform */
200 SdkEvalIdentification();
201
202 /* LED initialization */
203 SdkEvalLedInit(LED1);
204
205 /* GPIO configuration */
206 GPIO_Configuration();
207
208 /* MFT configuration */
209 MFT_Configuration();
210
211 /* IO3 for TnCRB */
212 MFT_SelectCapturePin(MFT1_TIMERB, IO_CAPTURE_PIN_MFT1_TIMERB);
213
214 /* Timer input sensitive to the rising edge */
215 MFT_TnEDGES(MFT1, MFT_RISING, MFT_RISING);
216
217 /* Connect PWM output from timer to TnA pin */
218 MFT_TnXEN(MFT1, MFT_TnA, ENABLE);
219
220 /* Enable MFT interrupts */
221 MFT_EnableIT(MFT1, MFT_IT_TNA | MFT_IT_TND, ENABLE);
222
223 /* Start MFT timer */
224 MFT_Cmd(MFT1, ENABLE);
225
226 /* Infinite loop */
227 while (1)
228 {
229 /* Update status of OUT_PIN2 */
230 if (output_status == SET)
231 SdkEvalLedOn(LED1);
232 else
233 SdkEvalLedOff(LED1);
234 }
235 }
236
237
243 void GPIO_Configuration(void)
244 {
245 GPIO_InitType GPIO_InitStructure;
246
247 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE);
248
249 /* Configure PWM pin */
250 GPIO_InitStructure.GPIO_Pin = MFT_PWM0_PIN;
251 GPIO_InitStructure.GPIO_Mode = Serial1_Mode;
252 GPIO_InitStructure.GPIO_Pull = DISABLE;
253 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
254 GPIO_Init(&GPIO_InitStructure);
255 }
256
262 void MFT_Configuration()
263 {
264 MFT_InitType timer_init;
265 NVIC_InitType NVIC_InitStructure;
266
267 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_MTFX1, ENABLE);
268
269 /* Init MFT3 in mode 3 */
270 /* Clock 1 is from prescaled clock */
271 /* Clock 2 is external clock */
272 /* Counter 1 is preset and reloaded to 5000 (timer period = TnCRA * 2 = 10 ms) */
273 /* Counter 2 is preset and reloaded to 5 (timer period = TnCRA * 2 * (5 * 2) = 100 ms */
274 timer_init.MFT_Mode = MFT_MODE_3;
275 timer_init.MFT_Clock1 = MFT_PRESCALED_CLK;
276 timer_init.MFT_Prescaler = 16 - 1;
277 timer_init.MFT_Clock2 = MFT_EXTERNAL_EVENT;
278 timer_init.MFT_CRA = 5000 - 1;
279 timer_init.MFT_CRB = 5 - 1;
280 MFT_Init(MFT1, &timer_init);
281
282 /* Set counter for timer1 and timer2 */
283 MFT_SetCounter(MFT1, 5000 - 1, 5 - 1);
284
285 /* Enable MFT Interrupts */
286 NVIC_InitStructure.NVIC_IRQChannel = MFT1A_IRQn;
287 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LOW_PRIORITY;
288 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
289 NVIC_Init(&NVIC_InitStructure);
290
291 NVIC_InitStructure.NVIC_IRQChannel = MFT1B_IRQn;
292 NVIC_Init(&NVIC_InitStructure);
293 }
294
295
296 #ifdef USE_FULL_ASSERT
297
304 void assert_failed(uint8_t* file, uint32_t line)
305 {
306 /* User can add his own implementation to report the file name and line number,
307 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
308
309 /* Infinite loop */
310 while (1)
311 {
312 }
313 }
314
315 #endif
316
329 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
IO_CAPTURE_PIN_MFT1_TIMERB
#define IO_CAPTURE_PIN_MFT1_TIMERB
Definition: MFT_Mode_3_main.c:178
main
int main(void)
Main program code.
Definition: MFT_Mode_3_main.c:194
MFT_Configuration
void MFT_Configuration(void)
MFT_Configuration.
Definition: MFT_Mode_3_main.c:262
output_status
FlagStatus output_status
GPIO_Configuration
void GPIO_Configuration(void)
GPIO Configuration.
Definition: MFT_Mode_3_main.c:243