BSP
Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "mems.h"
Private variables
ThresholdHigh
ThresholdLow
Private function prototypes
ACCELERO_MEMS_Test()
ACCELERO_ReadAcc()
Files
loading...
SourceVuSTM32 Libraries and SamplesBSPSrc/mems.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file BSP/Src/mems.c * @author MCD Application Team * @brief This example code shows how to use MEMS features. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "mems.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup BSP * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ extern __IO uint8_t UserPressButton; /* Init af threshold to detect acceleration on MEMS */ /* Typical value: - No acceleration: X, Y inferior to 100 (positive or negative) - Max acceleration: X, Y around 2000 (positive or negative) *//* ... */ int16_t ThresholdHigh = 200; int16_t ThresholdLow = -200; Private variables /* Private function prototypes -----------------------------------------------*/ static void ACCELERO_ReadAcc(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Test ACCELERATOR MEMS Hardware. * The main objective of this test is to check acceleration on 2 axes X and Y * @param None * @retval None *//* ... */ void ACCELERO_MEMS_Test(void) { /* Init Accelerometer MEMS */ if(BSP_ACCELERO_Init() != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (BSP_ACCELERO_Init() != HAL_OK) { ... } UserPressButton = 0; while(!UserPressButton) { ACCELERO_ReadAcc(); }while (!UserPressButton) { ... } }{ ... } /** * @brief Read Acceleration data. * @param None * @retval None *//* ... */ static void ACCELERO_ReadAcc(void) { /* Accelerometer variables */ int16_t buffer[3] = {0}; int16_t xval, yval = 0x00; /* Read Acceleration */ BSP_ACCELERO_GetXYZ(buffer); xval = buffer[0]; yval = buffer[1]; if((ABS(xval))>(ABS(yval))) { if(xval > ThresholdHigh) { /* LED5 On */ BSP_LED_On(LED5); HAL_Delay(10); }if (xval > ThresholdHigh) { ... } else if(xval < ThresholdLow) { /* LED4 On */ BSP_LED_On(LED4); HAL_Delay(10); }else if (xval < ThresholdLow) { ... } else { HAL_Delay(10); }else { ... } }if ((ABS(xval))>(ABS(yval))) { ... } else { if(yval < ThresholdLow) { /* LED6 On */ BSP_LED_On(LED6); HAL_Delay(10); }if (yval < ThresholdLow) { ... } else if(yval > ThresholdHigh) { /* LED3 On */ BSP_LED_On(LED3); HAL_Delay(10); }else if (yval > ThresholdHigh) { ... } else { HAL_Delay(10); }else { ... } }else { ... } BSP_LED_Off(LED3); BSP_LED_Off(LED4); BSP_LED_Off(LED5); BSP_LED_Off(LED6); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */
Details