Rev 8 | Rev 10 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
6 | mjames | 2 | ****************************************************************************** |
3 | * File Name : main.c |
||
4 | * Description : Main program body |
||
5 | ****************************************************************************** |
||
6 | * |
||
7 | * COPYRIGHT(c) 2016 STMicroelectronics |
||
8 | * |
||
9 | * Redistribution and use in source and binary forms, with or without modification, |
||
10 | * are permitted provided that the following conditions are met: |
||
11 | * 1. Redistributions of source code must retain the above copyright notice, |
||
12 | * this list of conditions and the following disclaimer. |
||
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
14 | * this list of conditions and the following disclaimer in the documentation |
||
15 | * and/or other materials provided with the distribution. |
||
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
||
17 | * may be used to endorse or promote products derived from this software |
||
18 | * without specific prior written permission. |
||
19 | * |
||
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
30 | * |
||
31 | ****************************************************************************** |
||
32 | */ |
||
2 | mjames | 33 | /* Includes ------------------------------------------------------------------*/ |
34 | #include "stm32f1xx_hal.h" |
||
35 | |||
36 | /* USER CODE BEGIN Includes */ |
||
37 | #include "ap_math.h" |
||
38 | #include "serial.h" |
||
39 | #include "SSD1306.h" |
||
7 | mjames | 40 | #include "Font.h" |
2 | mjames | 41 | #include "dials.h" |
4 | mjames | 42 | #include "switches.h" |
2 | mjames | 43 | #include <math.h> |
4 | mjames | 44 | #include "plx.h" |
2 | mjames | 45 | |
46 | /* USER CODE END Includes */ |
||
47 | |||
48 | /* Private variables ---------------------------------------------------------*/ |
||
49 | SPI_HandleTypeDef hspi1; |
||
50 | |||
3 | mjames | 51 | UART_HandleTypeDef huart1; |
2 | mjames | 52 | UART_HandleTypeDef huart2; |
53 | |||
54 | /* USER CODE BEGIN PV */ |
||
55 | /* Private variables ---------------------------------------------------------*/ |
||
7 | mjames | 56 | #define MAXRDG 10 |
2 | mjames | 57 | |
7 | mjames | 58 | int OldObservation[2] = |
59 | { -1, -1 }; // illegal initial value |
||
60 | int OldObservationIndex[2] = |
||
61 | { -1, -1 }; // if more than one sensor this will be printed |
||
62 | int16_t dial0[2] = |
||
63 | { 0, 0 }; |
||
64 | int16_t dial1[2] = |
||
65 | { -1, -1 }; |
||
66 | union |
||
67 | { |
||
68 | PLX_SensorInfo Sensor[MAXRDG]; |
||
69 | char Bytes[MAXRDG * sizeof(PLX_SensorInfo)]; |
||
70 | } Data; |
||
71 | int Max[MAXRDG]; |
||
72 | int Min[MAXRDG]; |
||
73 | int PLXItems; |
||
2 | mjames | 74 | /* USER CODE END PV */ |
75 | |||
76 | /* Private function prototypes -----------------------------------------------*/ |
||
6 | mjames | 77 | void |
7 | mjames | 78 | SystemClock_Config(void); |
6 | mjames | 79 | void |
7 | mjames | 80 | Error_Handler(void); |
6 | mjames | 81 | static void |
7 | mjames | 82 | MX_GPIO_Init(void); |
6 | mjames | 83 | static void |
7 | mjames | 84 | MX_SPI1_Init(void); |
6 | mjames | 85 | static void |
7 | mjames | 86 | MX_USART2_UART_Init(void); |
6 | mjames | 87 | static void |
7 | mjames | 88 | MX_USART1_UART_Init(void); |
2 | mjames | 89 | |
90 | /* USER CODE BEGIN PFP */ |
||
91 | /* Private function prototypes -----------------------------------------------*/ |
||
92 | |||
93 | /* USER CODE END PFP */ |
||
94 | |||
95 | /* USER CODE BEGIN 0 */ |
||
96 | /* dummy function */ |
||
7 | mjames | 97 | void _init(void) |
6 | mjames | 98 | { |
2 | mjames | 99 | |
100 | } |
||
7 | mjames | 101 | // the dial is the switch number we are using. |
102 | // suppress is the ItemIndex we wish to suppress on this display |
||
103 | int DisplayCurrent(int dial,int suppress) |
||
104 | { |
||
105 | char buff[10]; |
||
106 | int i; |
||
107 | select_display(dial); // pick the display we are using |
||
108 | int ItemIndex = dial_pos[dial]; |
||
109 | // wrap around count if dial too far to the right |
||
110 | if (ItemIndex >= PLXItems) |
||
111 | { |
||
112 | dial_pos[dial] = 0; |
||
113 | ItemIndex = 0; |
||
114 | } |
||
115 | if (ItemIndex < 0) |
||
116 | { |
||
117 | ItemIndex = 0; |
||
118 | dial_pos[dial] = 0; |
||
119 | } |
||
2 | mjames | 120 | |
9 | mjames | 121 | |
122 | |||
7 | mjames | 123 | // check for item suppression |
124 | if(ItemIndex == suppress) |
||
125 | { |
||
126 | dial1[dial] = -1; |
||
127 | OldObservation[dial] = -1; |
||
128 | OldObservationIndex[dial] = -1; |
||
2 | mjames | 129 | |
8 | mjames | 130 | clearDisplay(); |
131 | display(); |
||
7 | mjames | 132 | return -1; // we suppressed this display |
133 | } |
||
134 | // do not try to convert if no items in buffer |
||
135 | if (PLXItems > 0) |
||
136 | { |
||
137 | int DataVal = ConvPLX(Data.Sensor[ItemIndex].ReadingH, |
||
138 | Data.Sensor[ItemIndex].ReadingL); // data reading |
||
139 | int Observation = ConvPLX(Data.Sensor[ItemIndex].AddrH, |
||
140 | Data.Sensor[ItemIndex].AddrL); |
||
141 | int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].Instance); |
||
142 | // now to convert the readings and format strings |
||
143 | // find out limits |
||
144 | char * msg; |
||
145 | int len; |
||
2 | mjames | 146 | |
9 | mjames | 147 | // if the user presses the dial then reset min/max to current value |
148 | if(push_pos[dial] == 1) |
||
149 | { |
||
150 | Max[ItemIndex] = DataVal; |
||
151 | Min[ItemIndex] = DataVal; // 12 bit max value |
||
152 | } |
||
153 | |||
154 | |||
155 | |||
7 | mjames | 156 | if (Observation < PLX_MAX_OBS) |
157 | { |
||
158 | if (Observation != OldObservation[dial] |
||
159 | || ObservationIndex != OldObservationIndex[dial]) |
||
160 | { |
||
161 | dial1[dial] = -1; |
||
162 | clearDisplay(); |
||
163 | dial_draw_scale( |
||
164 | DisplayInfo[Observation].Low |
||
165 | / DisplayInfo[Observation].TickScale, |
||
166 | DisplayInfo[Observation].High |
||
9 | mjames | 167 | / DisplayInfo[Observation].TickScale, 12, 1); |
7 | mjames | 168 | if (ObservationIndex > 0) |
169 | { |
||
170 | len = 5; |
||
171 | buff[6] = ObservationIndex + '1'; |
||
172 | } |
||
173 | else |
||
174 | { |
||
175 | len = 6; |
||
176 | } |
||
177 | { |
||
178 | msg = DisplayInfo[Observation].name; |
||
179 | } |
||
180 | for (i = 0; i < len; i++) |
||
181 | { |
||
182 | buff[i] = msg[i]; |
||
183 | } |
||
184 | print_large_string(buff, 32, 48, 6); // this prints spaces for \0 at end of string |
||
2 | mjames | 185 | |
7 | mjames | 186 | OldObservation[dial] = Observation; |
187 | OldObservationIndex[dial] = ObservationIndex; |
||
188 | // |
||
189 | display(); |
||
2 | mjames | 190 | |
7 | mjames | 191 | } |
2 | mjames | 192 | |
7 | mjames | 193 | double max_rdg; |
194 | double min_rdg; |
||
195 | double cur_rdg; |
||
196 | int int_rdg; |
||
9 | mjames | 197 | int int_max; |
198 | int int_min; |
||
2 | mjames | 199 | |
7 | mjames | 200 | max_rdg = ConveriMFDRaw2Data(Observation, |
201 | DisplayInfo[Observation].Units, Max[ItemIndex]); |
||
202 | min_rdg = ConveriMFDRaw2Data(Observation, |
||
203 | DisplayInfo[Observation].Units, Min[ItemIndex]); |
||
204 | cur_rdg = ConveriMFDRaw2Data(Observation, |
||
205 | DisplayInfo[Observation].Units, DataVal); |
||
2 | mjames | 206 | |
7 | mjames | 207 | cur_rdg /= DisplayInfo[Observation].TickScale; |
208 | int dp_pos; // where to print the decimal place |
||
209 | switch (DisplayInfo[Observation].DP) |
||
210 | { |
||
211 | case 0: |
||
212 | int_rdg = (int) (cur_rdg); |
||
9 | mjames | 213 | int_max = (int) (max_rdg); |
214 | int_min = (int) (min_rdg); |
||
7 | mjames | 215 | dp_pos = 100; |
216 | break; |
||
217 | case 1: |
||
218 | int_rdg = (int) (cur_rdg * 10.0); |
||
9 | mjames | 219 | int_max = (int) (max_rdg * 10.0); |
220 | int_min = (int) (min_rdg * 10.0); |
||
7 | mjames | 221 | dp_pos = 3; |
222 | break; |
||
223 | case 2: |
||
224 | int_rdg = (int) (cur_rdg * 100.0); |
||
9 | mjames | 225 | int_max = (int) (max_rdg * 100.0); |
226 | int_min = (int) (min_rdg * 100.0); |
||
7 | mjames | 227 | dp_pos = 2; |
228 | break; |
||
229 | } |
||
2 | mjames | 230 | |
7 | mjames | 231 | cur_rdg -= DisplayInfo[Observation].Low; |
232 | cur_rdg = 100 * cur_rdg |
||
233 | / (DisplayInfo[Observation].High |
||
234 | - DisplayInfo[Observation].Low); |
||
2 | mjames | 235 | |
7 | mjames | 236 | dial0[dial] = (int) cur_rdg; |
2 | mjames | 237 | |
7 | mjames | 238 | /* old needle un-draw */ |
239 | if (dial1[dial] >= 0) |
||
240 | { |
||
241 | dial_draw_needle(dial1[dial]); |
||
242 | } |
||
243 | dial_draw_needle(dial0[dial]); |
||
244 | // print value overlaid by needle |
||
245 | // this is actual reading |
||
246 | print_digits(64 - 16, 30, 4, dp_pos, int_rdg); |
||
9 | mjames | 247 | font_gotoxy(0,0); |
248 | font_digits(4,dp_pos,int_min); |
||
249 | font_gotoxy(0,1); |
||
250 | font_puts("Min"); |
||
2 | mjames | 251 | |
9 | mjames | 252 | font_gotoxy(17,0); |
253 | font_digits(4,dp_pos,int_max); |
||
254 | font_gotoxy(18,1); |
||
255 | font_puts("Max"); |
||
256 | |||
7 | mjames | 257 | dial1[dial] = dial0[dial]; |
2 | mjames | 258 | |
7 | mjames | 259 | display(); |
2 | mjames | 260 | |
7 | mjames | 261 | } |
262 | } |
||
263 | return ItemIndex; |
||
264 | } |
||
265 | /* USER CODE END 0 */ |
||
2 | mjames | 266 | |
7 | mjames | 267 | int main(void) |
268 | { |
||
2 | mjames | 269 | |
7 | mjames | 270 | /* USER CODE BEGIN 1 */ |
2 | mjames | 271 | |
7 | mjames | 272 | GPIO_InitTypeDef GPIO_InitStruct; |
2 | mjames | 273 | |
7 | mjames | 274 | __HAL_RCC_SPI1_CLK_ENABLE() |
275 | ; |
||
276 | __HAL_RCC_USART1_CLK_ENABLE() |
||
277 | ; // PLX main port |
||
278 | __HAL_RCC_USART2_CLK_ENABLE() |
||
279 | ; // debug port |
||
280 | /* USER CODE END 1 */ |
||
2 | mjames | 281 | |
7 | mjames | 282 | /* MCU Configuration----------------------------------------------------------*/ |
6 | mjames | 283 | |
7 | mjames | 284 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
285 | HAL_Init(); |
||
2 | mjames | 286 | |
7 | mjames | 287 | /* Configure the system clock */ |
288 | SystemClock_Config(); |
||
2 | mjames | 289 | |
7 | mjames | 290 | /* Initialize all configured peripherals */ |
291 | MX_GPIO_Init(); |
||
292 | MX_SPI1_Init(); |
||
293 | MX_USART2_UART_Init(); |
||
294 | MX_USART1_UART_Init(); |
||
2 | mjames | 295 | |
7 | mjames | 296 | /* USER CODE BEGIN 2 */ |
297 | /* Need to set AF mode for output pins DURR. */ |
||
298 | /* SPI bus AF pin selects */ |
||
299 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
||
2 | mjames | 300 | |
8 | mjames | 301 | GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_7; |
7 | mjames | 302 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
303 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
4 | mjames | 304 | |
7 | mjames | 305 | /* USART2 AF pin selects */ |
306 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
||
307 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
308 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 309 | |
7 | mjames | 310 | /* USART1 AF pin selects */ |
311 | GPIO_InitStruct.Pin = GPIO_PIN_9; |
||
312 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 313 | |
7 | mjames | 314 | /* Turn on USART2 IRQ */ |
315 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
||
316 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
||
2 | mjames | 317 | |
7 | mjames | 318 | /* Turn on USART1 IRQ */ |
319 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
||
320 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
||
4 | mjames | 321 | |
7 | mjames | 322 | /* setup the USART control blocks */ |
323 | init_usart_ctl(&uc1, huart1.Instance); |
||
324 | init_usart_ctl(&uc2, huart2.Instance); |
||
2 | mjames | 325 | |
7 | mjames | 326 | EnableSerialRxInterrupt(&uc1); |
327 | EnableSerialRxInterrupt(&uc2); |
||
328 | |||
329 | ap_init(); // set up the approximate math library |
||
330 | |||
331 | int disp; |
||
332 | |||
333 | ssd1306_begin(1, 0); |
||
334 | // static const int xp = 128 - 42; |
||
335 | for (disp = 0; disp < 2; disp++) |
||
6 | mjames | 336 | { |
7 | mjames | 337 | select_display(disp); |
338 | clearDisplay(); |
||
339 | dim(0); |
||
340 | //font_puts( |
||
341 | // "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font"); |
||
4 | mjames | 342 | |
7 | mjames | 343 | dial_origin(64, 60); |
344 | dial_size(60); |
||
9 | mjames | 345 | dial_draw_scale(0, 10, 12, 5); |
4 | mjames | 346 | |
7 | mjames | 347 | display(); |
4 | mjames | 348 | |
7 | mjames | 349 | } |
350 | InitSwitches(); |
||
4 | mjames | 351 | |
7 | mjames | 352 | /* USER CODE END 2 */ |
353 | |||
354 | /* Infinite loop */ |
||
355 | /* USER CODE BEGIN WHILE */ |
||
356 | uint32_t Ticks = HAL_GetTick() + 100; |
||
357 | |||
358 | int i; |
||
359 | |||
360 | // PLX decoder protocol |
||
361 | char PLXPacket = 0; |
||
362 | for (i = 0; i < MAXRDG; i++) |
||
363 | { |
||
364 | Max[i] = 0; |
||
365 | Min[i] = 0xFFF; // 12 bit max value |
||
366 | } |
||
367 | |||
368 | int PLXPtr = 0; |
||
369 | |||
370 | while (1) |
||
371 | { |
||
372 | // poll switches |
||
373 | HandleSwitches(); |
||
374 | |||
9 | mjames | 375 | |
376 | |||
377 | |||
7 | mjames | 378 | uint16_t cc = SerialCharsReceived(&uc1); |
379 | int chr; |
||
380 | for (chr = 0; chr < cc; chr++) |
||
6 | mjames | 381 | { |
7 | mjames | 382 | char c = GetCharSerial(&uc1); |
383 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
||
6 | mjames | 384 | { |
7 | mjames | 385 | PLXPtr = 0; // reset the pointer |
386 | PLXPacket = 1; |
||
4 | mjames | 387 | } |
7 | mjames | 388 | else if (c == PLX_Stop) |
6 | mjames | 389 | { |
7 | mjames | 390 | if (PLXPacket) |
391 | { |
||
392 | // we can now decode the selected parameter |
||
393 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
||
394 | // saturate the rotary switch position |
||
395 | |||
396 | int DataVal; |
||
397 | // process min/max |
||
398 | for (i = 0; i < PLXItems; i++) |
||
399 | { |
||
400 | DataVal = ConvPLX(Data.Sensor[i].ReadingH, |
||
401 | Data.Sensor[i].ReadingL); |
||
402 | if (DataVal > Max[i]) |
||
403 | { |
||
404 | Max[i] = DataVal; |
||
405 | } |
||
406 | if (DataVal < Min[i]) |
||
407 | { |
||
408 | Min[i] = DataVal; |
||
409 | } |
||
410 | } |
||
411 | |||
412 | // now to display the information |
||
413 | int suppress = DisplayCurrent(0,-1); |
||
414 | DisplayCurrent(1,suppress); |
||
415 | } |
||
416 | PLXPtr = 0; |
||
417 | PLXPacket = 0; |
||
4 | mjames | 418 | } |
7 | mjames | 419 | else if (c > PLX_Stop) // illegal char, restart reading |
6 | mjames | 420 | { |
7 | mjames | 421 | PLXPacket = 0; |
422 | PLXPtr = 0; |
||
4 | mjames | 423 | } |
7 | mjames | 424 | else if (PLXPtr < sizeof(Data.Bytes)) |
6 | mjames | 425 | { |
7 | mjames | 426 | Data.Bytes[PLXPtr++] = c; |
6 | mjames | 427 | } |
428 | } |
||
4 | mjames | 429 | |
7 | mjames | 430 | HAL_Delay(1); |
6 | mjames | 431 | } |
7 | mjames | 432 | /* USER CODE END WHILE */ |
2 | mjames | 433 | |
7 | mjames | 434 | /* USER CODE BEGIN 3 */ |
6 | mjames | 435 | |
2 | mjames | 436 | } |
7 | mjames | 437 | /* USER CODE END 3 */ |
2 | mjames | 438 | |
439 | /** System Clock Configuration |
||
6 | mjames | 440 | */ |
7 | mjames | 441 | void SystemClock_Config(void) |
5 | mjames | 442 | { |
2 | mjames | 443 | |
7 | mjames | 444 | RCC_OscInitTypeDef RCC_OscInitStruct; |
445 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
||
2 | mjames | 446 | |
7 | mjames | 447 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
448 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
||
449 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
||
450 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||
451 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
||
452 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
||
453 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
||
454 | { |
||
455 | Error_Handler(); |
||
2 | mjames | 456 | } |
457 | |||
7 | mjames | 458 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
459 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
||
460 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
||
461 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
462 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
||
463 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||
464 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
||
5 | mjames | 465 | { |
7 | mjames | 466 | Error_Handler(); |
467 | } |
||
2 | mjames | 468 | |
7 | mjames | 469 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
2 | mjames | 470 | |
7 | mjames | 471 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
2 | mjames | 472 | |
7 | mjames | 473 | /* SysTick_IRQn interrupt configuration */ |
474 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
||
2 | mjames | 475 | } |
476 | |||
477 | /* SPI1 init function */ |
||
7 | mjames | 478 | static void MX_SPI1_Init(void) |
5 | mjames | 479 | { |
2 | mjames | 480 | |
7 | mjames | 481 | hspi1.Instance = SPI1; |
482 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
483 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
||
484 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
485 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
||
486 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
487 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
488 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
||
489 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||
490 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
491 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
492 | hspi1.Init.CRCPolynomial = 10; |
||
493 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
||
494 | { |
||
495 | Error_Handler(); |
||
496 | } |
||
2 | mjames | 497 | |
498 | } |
||
499 | |||
3 | mjames | 500 | /* USART1 init function */ |
7 | mjames | 501 | static void MX_USART1_UART_Init(void) |
5 | mjames | 502 | { |
3 | mjames | 503 | |
7 | mjames | 504 | huart1.Instance = USART1; |
505 | huart1.Init.BaudRate = 19200; |
||
506 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
507 | huart1.Init.StopBits = UART_STOPBITS_1; |
||
508 | huart1.Init.Parity = UART_PARITY_NONE; |
||
509 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
510 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
511 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
512 | if (HAL_UART_Init(&huart1) != HAL_OK) |
||
513 | { |
||
514 | Error_Handler(); |
||
515 | } |
||
3 | mjames | 516 | |
517 | } |
||
518 | |||
2 | mjames | 519 | /* USART2 init function */ |
7 | mjames | 520 | static void MX_USART2_UART_Init(void) |
5 | mjames | 521 | { |
2 | mjames | 522 | |
7 | mjames | 523 | huart2.Instance = USART2; |
524 | huart2.Init.BaudRate = 115200; |
||
525 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
||
526 | huart2.Init.StopBits = UART_STOPBITS_1; |
||
527 | huart2.Init.Parity = UART_PARITY_NONE; |
||
528 | huart2.Init.Mode = UART_MODE_TX_RX; |
||
529 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
530 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
||
531 | if (HAL_UART_Init(&huart2) != HAL_OK) |
||
532 | { |
||
533 | Error_Handler(); |
||
534 | } |
||
2 | mjames | 535 | |
536 | } |
||
537 | |||
7 | mjames | 538 | /** Configure pins as |
6 | mjames | 539 | * Analog |
540 | * Input |
||
541 | * Output |
||
542 | * EVENT_OUT |
||
543 | * EXTI |
||
544 | */ |
||
7 | mjames | 545 | static void MX_GPIO_Init(void) |
5 | mjames | 546 | { |
2 | mjames | 547 | |
7 | mjames | 548 | GPIO_InitTypeDef GPIO_InitStruct; |
2 | mjames | 549 | |
7 | mjames | 550 | /* GPIO Ports Clock Enable */ |
551 | __HAL_RCC_GPIOD_CLK_ENABLE() |
||
552 | ; |
||
553 | __HAL_RCC_GPIOA_CLK_ENABLE() |
||
554 | ; |
||
555 | __HAL_RCC_GPIOC_CLK_ENABLE() |
||
556 | ; |
||
557 | __HAL_RCC_GPIOB_CLK_ENABLE() |
||
558 | ; |
||
2 | mjames | 559 | |
7 | mjames | 560 | /*Configure GPIO pin Output Level */ |
561 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
||
2 | mjames | 562 | |
7 | mjames | 563 | /*Configure GPIO pin Output Level */ |
564 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
||
2 | mjames | 565 | |
7 | mjames | 566 | /*Configure GPIO pin Output Level */ |
567 | HAL_GPIO_WritePin(GPIOC, |
||
568 | SPI_RESET_Pin | USART3_INVERT_Pin | USB_PWR_Pin, GPIO_PIN_RESET); |
||
2 | mjames | 569 | |
7 | mjames | 570 | /*Configure GPIO pin Output Level */ |
571 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
||
2 | mjames | 572 | |
7 | mjames | 573 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
574 | GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin; |
||
575 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
576 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
577 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 578 | |
7 | mjames | 579 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
580 | GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin |
||
581 | | USB_PWR_Pin; |
||
582 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
583 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
584 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||
2 | mjames | 585 | |
7 | mjames | 586 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
587 | GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin; |
||
588 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
589 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
590 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||
5 | mjames | 591 | |
7 | mjames | 592 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
593 | GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin; |
||
594 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
595 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
596 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||
5 | mjames | 597 | |
2 | mjames | 598 | } |
599 | |||
600 | /* USER CODE BEGIN 4 */ |
||
601 | |||
602 | /* USER CODE END 4 */ |
||
603 | |||
5 | mjames | 604 | /** |
6 | mjames | 605 | * @brief This function is executed in case of error occurrence. |
606 | * @param None |
||
607 | * @retval None |
||
608 | */ |
||
7 | mjames | 609 | void Error_Handler(void) |
5 | mjames | 610 | { |
7 | mjames | 611 | /* USER CODE BEGIN Error_Handler */ |
612 | /* User can add his own implementation to report the HAL error return state */ |
||
613 | while (1) |
||
614 | { |
||
5 | mjames | 615 | } |
7 | mjames | 616 | /* USER CODE END Error_Handler */ |
617 | } |
||
5 | mjames | 618 | |
2 | mjames | 619 | #ifdef USE_FULL_ASSERT |
620 | |||
621 | /** |
||
6 | mjames | 622 | * @brief Reports the name of the source file and the source line number |
623 | * where the assert_param error has occurred. |
||
624 | * @param file: pointer to the source file name |
||
625 | * @param line: assert_param error line source number |
||
626 | * @retval None |
||
627 | */ |
||
2 | mjames | 628 | void assert_failed(uint8_t* file, uint32_t line) |
7 | mjames | 629 | { |
630 | /* USER CODE BEGIN 6 */ |
||
631 | /* User can add his own implementation to report the file name and line number, |
||
632 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
633 | /* USER CODE END 6 */ |
||
2 | mjames | 634 | |
7 | mjames | 635 | } |
2 | mjames | 636 | |
637 | #endif |
||
638 | |||
639 | /** |
||
6 | mjames | 640 | * @} |
641 | */ |
||
2 | mjames | 642 | |
643 | /** |
||
6 | mjames | 644 | * @} |
645 | */ |
||
2 | mjames | 646 | |
647 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |