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()
GYRO_MEMS_Test()
GYRO_ReadAng()
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @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 */ int16_t ThresholdHigh = 1000; int16_t ThresholdLow = -1000; Private variables /* Private function prototypes -----------------------------------------------*/ static void ACCELERO_ReadAcc(void); static void GYRO_ReadAng(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) { 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); }{ ... } /** * @brief Test Gyroscope MEMS Hardware. * The main objectif of this test is to check the hardware connection of the * MEMS peripheral. * @param None * @retval None *//* ... */ void GYRO_MEMS_Test(void) { /* Init Gyroscope MEMS */ if(BSP_ACCELERO_Init() != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (BSP_ACCELERO_Init() != HAL_OK) { ... } UserPressButton = 0; while(!UserPressButton) { GYRO_ReadAng(); }while (!UserPressButton) { ... } }{ ... } /** * @brief Read Gyroscope Angular data. * @param None * @retval None *//* ... */ static void GYRO_ReadAng(void) { /* Gyroscope variables */ float Buffer[3]; float Xval, Yval = 0x00; /* Init Gyroscope Mems */ if(BSP_GYRO_Init() != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (BSP_GYRO_Init() != HAL_OK) { ... } /* Read Gyroscope Angular data */ BSP_GYRO_GetXYZ(Buffer); Xval = ABS((Buffer[0])); Yval = ABS((Buffer[1])); if(Xval>Yval) { if(Buffer[0] > 5000.0f) { /* LED5 On */ BSP_LED_On(LED5); HAL_Delay(10); }if (Buffer[0] > 5000.0f) { ... } else if(Buffer[0] < -5000.0f) { /* LED4 On */ BSP_LED_On(LED4); HAL_Delay(10); }else if (Buffer[0] < -5000.0f) { ... } else { HAL_Delay(10); }else { ... } }if (Xval>Yval) { ... } else { if(Buffer[1] < -5000.0f) { /* LED6 On */ BSP_LED_On(LED6); HAL_Delay(10); }if (Buffer[1] < -5000.0f) { ... } else if(Buffer[1] > 5000.0f) { /* LED3 On */ BSP_LED_On(LED3); HAL_Delay(10); }else if (Buffer[1] > 5000.0f) { ... } else { HAL_Delay(10); }else { ... } }else { ... } BSP_LED_Off(LED3); BSP_LED_Off(LED4); BSP_LED_Off(LED5); BSP_LED_Off(LED6); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */
Details