Rev 16 | Rev 18 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
16 | 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" |
16 | mjames | 45 | #include "eeprom.h" |
2 | mjames | 46 | |
47 | /* USER CODE END Includes */ |
||
48 | |||
49 | /* Private variables ---------------------------------------------------------*/ |
||
50 | SPI_HandleTypeDef hspi1; |
||
51 | |||
3 | mjames | 52 | UART_HandleTypeDef huart1; |
2 | mjames | 53 | UART_HandleTypeDef huart2; |
54 | |||
55 | /* USER CODE BEGIN PV */ |
||
56 | /* Private variables ---------------------------------------------------------*/ |
||
7 | mjames | 57 | #define MAXRDG 10 |
2 | mjames | 58 | |
7 | mjames | 59 | int OldObservation[2] = |
60 | { -1, -1 }; // illegal initial value |
||
61 | int OldObservationIndex[2] = |
||
62 | { -1, -1 }; // if more than one sensor this will be printed |
||
63 | int16_t dial0[2] = |
||
64 | { 0, 0 }; |
||
65 | int16_t dial1[2] = |
||
66 | { -1, -1 }; |
||
14 | mjames | 67 | |
16 | mjames | 68 | /* Virtual address defined by the user: 0xFFFF value is prohibited */ |
17 | mjames | 69 | uint16_t VirtAddVarTab[NumbOfVar] = {0x1111,0x2222 } ; |
14 | mjames | 70 | |
7 | mjames | 71 | union |
72 | { |
||
73 | PLX_SensorInfo Sensor[MAXRDG]; |
||
74 | char Bytes[MAXRDG * sizeof(PLX_SensorInfo)]; |
||
75 | } Data; |
||
76 | int Max[MAXRDG]; |
||
77 | int Min[MAXRDG]; |
||
78 | int PLXItems; |
||
2 | mjames | 79 | /* USER CODE END PV */ |
80 | |||
81 | /* Private function prototypes -----------------------------------------------*/ |
||
16 | mjames | 82 | void SystemClock_Config(void); |
83 | void Error_Handler(void); |
||
84 | static void MX_GPIO_Init(void); |
||
85 | static void MX_SPI1_Init(void); |
||
86 | static void MX_USART2_UART_Init(void); |
||
87 | static void MX_USART1_UART_Init(void); |
||
2 | mjames | 88 | |
89 | /* USER CODE BEGIN PFP */ |
||
90 | /* Private function prototypes -----------------------------------------------*/ |
||
91 | |||
92 | /* USER CODE END PFP */ |
||
93 | |||
94 | /* USER CODE BEGIN 0 */ |
||
95 | /* dummy function */ |
||
7 | mjames | 96 | void _init(void) |
6 | mjames | 97 | { |
2 | mjames | 98 | |
99 | } |
||
7 | mjames | 100 | // the dial is the switch number we are using. |
101 | // suppress is the ItemIndex we wish to suppress on this display |
||
102 | int DisplayCurrent(int dial,int suppress) |
||
103 | { |
||
104 | char buff[10]; |
||
105 | int i; |
||
106 | select_display(dial); // pick the display we are using |
||
13 | mjames | 107 | int ItemIndex = dial_pos[dial]/4; |
14 | mjames | 108 | |
7 | mjames | 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 | { |
||
14 | mjames | 117 | ItemIndex = PLXItems-1; |
118 | dial_pos[dial] = (PLXItems-1)*4; |
||
7 | mjames | 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 | { |
||
14 | mjames | 161 | |
162 | |||
7 | mjames | 163 | dial1[dial] = -1; |
164 | clearDisplay(); |
||
165 | dial_draw_scale( |
||
13 | mjames | 166 | DisplayInfo[Observation].Low, |
167 | DisplayInfo[Observation].High, |
||
168 | 12, 1,DisplayInfo[Observation].TickScale); |
||
14 | mjames | 169 | |
170 | msg = DisplayInfo[Observation].name; |
||
171 | len = 7; |
||
172 | int len1 = ObservationIndex > 0 ? len-1: len; |
||
173 | for (i = 0; i < len1 && msg[i]; i++) |
||
7 | mjames | 174 | { |
14 | mjames | 175 | buff[i] = msg[i]; |
7 | mjames | 176 | } |
14 | mjames | 177 | if (ObservationIndex > 0 && i<len) |
7 | mjames | 178 | { |
14 | mjames | 179 | buff[i++] = ObservationIndex + '1'; |
7 | mjames | 180 | } |
2 | mjames | 181 | |
15 | mjames | 182 | print_large_string(buff, 64-i*4, 48, i); // this prints spaces for \0 at end of string |
14 | mjames | 183 | |
7 | mjames | 184 | OldObservation[dial] = Observation; |
185 | OldObservationIndex[dial] = ObservationIndex; |
||
186 | // |
||
187 | display(); |
||
2 | mjames | 188 | |
7 | mjames | 189 | } |
2 | mjames | 190 | |
7 | mjames | 191 | double max_rdg; |
192 | double min_rdg; |
||
193 | double cur_rdg; |
||
194 | int int_rdg; |
||
9 | mjames | 195 | int int_max; |
196 | int int_min; |
||
2 | mjames | 197 | |
7 | mjames | 198 | max_rdg = ConveriMFDRaw2Data(Observation, |
199 | DisplayInfo[Observation].Units, Max[ItemIndex]); |
||
200 | min_rdg = ConveriMFDRaw2Data(Observation, |
||
201 | DisplayInfo[Observation].Units, Min[ItemIndex]); |
||
202 | cur_rdg = ConveriMFDRaw2Data(Observation, |
||
203 | DisplayInfo[Observation].Units, DataVal); |
||
2 | mjames | 204 | |
7 | mjames | 205 | int dp_pos; // where to print the decimal place |
206 | switch (DisplayInfo[Observation].DP) |
||
207 | { |
||
208 | case 0: |
||
209 | int_rdg = (int) (cur_rdg); |
||
9 | mjames | 210 | int_max = (int) (max_rdg); |
211 | int_min = (int) (min_rdg); |
||
7 | mjames | 212 | dp_pos = 100; |
213 | break; |
||
214 | case 1: |
||
215 | int_rdg = (int) (cur_rdg * 10.0); |
||
9 | mjames | 216 | int_max = (int) (max_rdg * 10.0); |
217 | int_min = (int) (min_rdg * 10.0); |
||
7 | mjames | 218 | dp_pos = 3; |
219 | break; |
||
220 | case 2: |
||
221 | int_rdg = (int) (cur_rdg * 100.0); |
||
9 | mjames | 222 | int_max = (int) (max_rdg * 100.0); |
223 | int_min = (int) (min_rdg * 100.0); |
||
7 | mjames | 224 | dp_pos = 2; |
225 | break; |
||
226 | } |
||
2 | mjames | 227 | |
7 | mjames | 228 | cur_rdg -= DisplayInfo[Observation].Low; |
229 | cur_rdg = 100 * cur_rdg |
||
230 | / (DisplayInfo[Observation].High |
||
231 | - DisplayInfo[Observation].Low); |
||
2 | mjames | 232 | |
13 | mjames | 233 | dial0[dial] = (int) cur_rdg ; |
2 | mjames | 234 | |
7 | mjames | 235 | /* old needle un-draw */ |
236 | if (dial1[dial] >= 0) |
||
237 | { |
||
238 | dial_draw_needle(dial1[dial]); |
||
239 | } |
||
240 | dial_draw_needle(dial0[dial]); |
||
241 | // print value overlaid by needle |
||
242 | // this is actual reading |
||
15 | mjames | 243 | print_digits(20, 30, 5, dp_pos, int_rdg); |
9 | mjames | 244 | font_gotoxy(0,0); |
15 | mjames | 245 | font_digits(5,dp_pos,int_min); |
246 | |||
9 | mjames | 247 | font_gotoxy(0,1); |
248 | font_puts("Min"); |
||
2 | mjames | 249 | |
15 | mjames | 250 | font_gotoxy(15,0); |
251 | font_digits(5,dp_pos,int_max); |
||
9 | mjames | 252 | font_gotoxy(18,1); |
253 | font_puts("Max"); |
||
254 | |||
7 | mjames | 255 | dial1[dial] = dial0[dial]; |
2 | mjames | 256 | |
7 | mjames | 257 | display(); |
2 | mjames | 258 | |
7 | mjames | 259 | } |
260 | } |
||
261 | return ItemIndex; |
||
262 | } |
||
263 | /* USER CODE END 0 */ |
||
2 | mjames | 264 | |
7 | mjames | 265 | int main(void) |
266 | { |
||
2 | mjames | 267 | |
16 | mjames | 268 | /* USER CODE BEGIN 1 */ |
2 | mjames | 269 | |
7 | mjames | 270 | GPIO_InitTypeDef GPIO_InitStruct; |
2 | mjames | 271 | |
7 | mjames | 272 | __HAL_RCC_SPI1_CLK_ENABLE() |
273 | ; |
||
274 | __HAL_RCC_USART1_CLK_ENABLE() |
||
275 | ; // PLX main port |
||
276 | __HAL_RCC_USART2_CLK_ENABLE() |
||
277 | ; // debug port |
||
16 | mjames | 278 | /* USER CODE END 1 */ |
2 | mjames | 279 | |
16 | mjames | 280 | /* MCU Configuration----------------------------------------------------------*/ |
6 | mjames | 281 | |
16 | mjames | 282 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
283 | HAL_Init(); |
||
2 | mjames | 284 | |
16 | mjames | 285 | /* Configure the system clock */ |
286 | SystemClock_Config(); |
||
2 | mjames | 287 | |
16 | mjames | 288 | /* Initialize all configured peripherals */ |
289 | MX_GPIO_Init(); |
||
290 | MX_SPI1_Init(); |
||
291 | MX_USART2_UART_Init(); |
||
292 | MX_USART1_UART_Init(); |
||
2 | mjames | 293 | |
16 | mjames | 294 | /* USER CODE BEGIN 2 */ |
7 | mjames | 295 | /* SPI bus AF pin selects */ |
2 | mjames | 296 | |
4 | mjames | 297 | |
16 | mjames | 298 | /* Turn on USART2 IRQ */ |
7 | mjames | 299 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
300 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
||
2 | mjames | 301 | |
7 | mjames | 302 | /* Turn on USART1 IRQ */ |
303 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
||
304 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
||
4 | mjames | 305 | |
7 | mjames | 306 | /* setup the USART control blocks */ |
307 | init_usart_ctl(&uc1, huart1.Instance); |
||
308 | init_usart_ctl(&uc2, huart2.Instance); |
||
2 | mjames | 309 | |
7 | mjames | 310 | EnableSerialRxInterrupt(&uc1); |
311 | EnableSerialRxInterrupt(&uc2); |
||
312 | |||
16 | mjames | 313 | EE_Init(); |
314 | |||
17 | mjames | 315 | int i; |
316 | for(i=0;i<2;i++) |
||
317 | { |
||
318 | uint16_t val; |
||
319 | |||
320 | uint16_t rc = EE_ReadVariable(i, &val); |
||
321 | |||
322 | if (rc == 0) |
||
323 | { |
||
324 | dial_pos[i] = val; |
||
325 | } |
||
326 | } |
||
327 | |||
7 | mjames | 328 | ap_init(); // set up the approximate math library |
329 | |||
330 | int disp; |
||
331 | |||
332 | ssd1306_begin(1, 0); |
||
10 | mjames | 333 | dial_origin(64, 60); |
334 | dial_size(60); |
||
335 | |||
336 | |||
17 | mjames | 337 | // sort out the switch positions |
14 | mjames | 338 | |
17 | mjames | 339 | |
340 | |||
341 | |||
7 | mjames | 342 | for (disp = 0; disp < 2; disp++) |
6 | mjames | 343 | { |
7 | mjames | 344 | select_display(disp); |
345 | clearDisplay(); |
||
346 | dim(0); |
||
347 | //font_puts( |
||
348 | // "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font"); |
||
4 | mjames | 349 | |
13 | mjames | 350 | dial_draw_scale(0, 10, 12, 5,1); |
10 | mjames | 351 | char buffer[] = "Display "; |
352 | buffer[8] = disp+'1'; |
||
353 | print_large_string(buffer, 20,30, 9); |
||
4 | mjames | 354 | |
7 | mjames | 355 | display(); |
4 | mjames | 356 | |
7 | mjames | 357 | } |
10 | mjames | 358 | |
359 | |||
7 | mjames | 360 | InitSwitches(); |
4 | mjames | 361 | |
16 | mjames | 362 | /* USER CODE END 2 */ |
7 | mjames | 363 | |
16 | mjames | 364 | /* Infinite loop */ |
365 | /* USER CODE BEGIN WHILE */ |
||
7 | mjames | 366 | uint32_t Ticks = HAL_GetTick() + 100; |
367 | |||
368 | |||
369 | // PLX decoder protocol |
||
370 | char PLXPacket = 0; |
||
371 | for (i = 0; i < MAXRDG; i++) |
||
372 | { |
||
373 | Max[i] = 0; |
||
374 | Min[i] = 0xFFF; // 12 bit max value |
||
375 | } |
||
376 | |||
377 | int PLXPtr = 0; |
||
378 | |||
379 | while (1) |
||
380 | { |
||
381 | // poll switches |
||
382 | HandleSwitches(); |
||
383 | |||
9 | mjames | 384 | |
385 | |||
386 | |||
7 | mjames | 387 | uint16_t cc = SerialCharsReceived(&uc1); |
388 | int chr; |
||
389 | for (chr = 0; chr < cc; chr++) |
||
6 | mjames | 390 | { |
7 | mjames | 391 | char c = GetCharSerial(&uc1); |
392 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
||
6 | mjames | 393 | { |
7 | mjames | 394 | PLXPtr = 0; // reset the pointer |
395 | PLXPacket = 1; |
||
4 | mjames | 396 | } |
7 | mjames | 397 | else if (c == PLX_Stop) |
6 | mjames | 398 | { |
7 | mjames | 399 | if (PLXPacket) |
400 | { |
||
401 | // we can now decode the selected parameter |
||
402 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
||
403 | // saturate the rotary switch position |
||
404 | |||
405 | int DataVal; |
||
406 | // process min/max |
||
407 | for (i = 0; i < PLXItems; i++) |
||
408 | { |
||
409 | DataVal = ConvPLX(Data.Sensor[i].ReadingH, |
||
410 | Data.Sensor[i].ReadingL); |
||
411 | if (DataVal > Max[i]) |
||
412 | { |
||
413 | Max[i] = DataVal; |
||
414 | } |
||
415 | if (DataVal < Min[i]) |
||
416 | { |
||
417 | Min[i] = DataVal; |
||
418 | } |
||
419 | } |
||
420 | |||
421 | // now to display the information |
||
14 | mjames | 422 | int suppress = DisplayCurrent(0,-1); |
423 | DisplayCurrent(1, suppress); |
||
7 | mjames | 424 | } |
425 | PLXPtr = 0; |
||
426 | PLXPacket = 0; |
||
4 | mjames | 427 | } |
7 | mjames | 428 | else if (c > PLX_Stop) // illegal char, restart reading |
6 | mjames | 429 | { |
7 | mjames | 430 | PLXPacket = 0; |
431 | PLXPtr = 0; |
||
4 | mjames | 432 | } |
7 | mjames | 433 | else if (PLXPtr < sizeof(Data.Bytes)) |
6 | mjames | 434 | { |
7 | mjames | 435 | Data.Bytes[PLXPtr++] = c; |
6 | mjames | 436 | } |
437 | } |
||
4 | mjames | 438 | |
7 | mjames | 439 | HAL_Delay(1); |
6 | mjames | 440 | } |
16 | mjames | 441 | /* USER CODE END WHILE */ |
2 | mjames | 442 | |
16 | mjames | 443 | /* USER CODE BEGIN 3 */ |
6 | mjames | 444 | |
16 | mjames | 445 | |
446 | /* USER CODE END 3 */ |
||
447 | |||
2 | mjames | 448 | } |
449 | |||
450 | /** System Clock Configuration |
||
16 | mjames | 451 | */ |
7 | mjames | 452 | void SystemClock_Config(void) |
5 | mjames | 453 | { |
2 | mjames | 454 | |
16 | mjames | 455 | RCC_OscInitTypeDef RCC_OscInitStruct; |
456 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
||
2 | mjames | 457 | |
16 | mjames | 458 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
459 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
||
460 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
||
461 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||
462 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
||
463 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
||
464 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
||
465 | { |
||
466 | Error_Handler(); |
||
467 | } |
||
2 | mjames | 468 | |
16 | mjames | 469 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
470 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
||
471 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
||
472 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
473 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
||
474 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||
475 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
||
476 | { |
||
477 | Error_Handler(); |
||
478 | } |
||
2 | mjames | 479 | |
16 | mjames | 480 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
2 | mjames | 481 | |
16 | mjames | 482 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
2 | mjames | 483 | |
16 | mjames | 484 | /* SysTick_IRQn interrupt configuration */ |
485 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
||
2 | mjames | 486 | } |
487 | |||
488 | /* SPI1 init function */ |
||
7 | mjames | 489 | static void MX_SPI1_Init(void) |
5 | mjames | 490 | { |
2 | mjames | 491 | |
16 | mjames | 492 | hspi1.Instance = SPI1; |
493 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
494 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
||
495 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
496 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
||
497 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
498 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
499 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
||
500 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||
501 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
502 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
503 | hspi1.Init.CRCPolynomial = 10; |
||
504 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
||
505 | { |
||
506 | Error_Handler(); |
||
507 | } |
||
2 | mjames | 508 | |
509 | } |
||
510 | |||
3 | mjames | 511 | /* USART1 init function */ |
7 | mjames | 512 | static void MX_USART1_UART_Init(void) |
5 | mjames | 513 | { |
3 | mjames | 514 | |
16 | mjames | 515 | huart1.Instance = USART1; |
516 | huart1.Init.BaudRate = 19200; |
||
517 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
518 | huart1.Init.StopBits = UART_STOPBITS_1; |
||
519 | huart1.Init.Parity = UART_PARITY_NONE; |
||
520 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
521 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
522 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
523 | if (HAL_UART_Init(&huart1) != HAL_OK) |
||
524 | { |
||
525 | Error_Handler(); |
||
526 | } |
||
3 | mjames | 527 | |
528 | } |
||
529 | |||
2 | mjames | 530 | /* USART2 init function */ |
7 | mjames | 531 | static void MX_USART2_UART_Init(void) |
5 | mjames | 532 | { |
2 | mjames | 533 | |
16 | mjames | 534 | huart2.Instance = USART2; |
535 | huart2.Init.BaudRate = 115200; |
||
536 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
||
537 | huart2.Init.StopBits = UART_STOPBITS_1; |
||
538 | huart2.Init.Parity = UART_PARITY_NONE; |
||
539 | huart2.Init.Mode = UART_MODE_TX_RX; |
||
540 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
541 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
||
542 | if (HAL_UART_Init(&huart2) != HAL_OK) |
||
543 | { |
||
544 | Error_Handler(); |
||
545 | } |
||
2 | mjames | 546 | |
547 | } |
||
548 | |||
7 | mjames | 549 | /** Configure pins as |
16 | mjames | 550 | * Analog |
551 | * Input |
||
552 | * Output |
||
553 | * EVENT_OUT |
||
554 | * EXTI |
||
555 | */ |
||
7 | mjames | 556 | static void MX_GPIO_Init(void) |
5 | mjames | 557 | { |
2 | mjames | 558 | |
16 | mjames | 559 | GPIO_InitTypeDef GPIO_InitStruct; |
2 | mjames | 560 | |
16 | mjames | 561 | /* GPIO Ports Clock Enable */ |
562 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
||
563 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
564 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
||
565 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
2 | mjames | 566 | |
16 | mjames | 567 | /*Configure GPIO pin Output Level */ |
568 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
||
2 | mjames | 569 | |
16 | mjames | 570 | /*Configure GPIO pin Output Level */ |
571 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
||
2 | mjames | 572 | |
16 | mjames | 573 | /*Configure GPIO pin Output Level */ |
574 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET); |
||
2 | mjames | 575 | |
16 | mjames | 576 | /*Configure GPIO pin Output Level */ |
577 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
||
2 | mjames | 578 | |
16 | mjames | 579 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
580 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin; |
||
581 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
582 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
583 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
2 | mjames | 584 | |
16 | mjames | 585 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
586 | GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|USART3_INVERT_Pin|USB_PWR_Pin; |
||
587 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
588 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
589 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||
2 | mjames | 590 | |
16 | mjames | 591 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
592 | GPIO_InitStruct.Pin = SW1_PUSH_Pin|SW1_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin; |
||
593 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
594 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
595 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||
5 | mjames | 596 | |
16 | mjames | 597 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
598 | GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin; |
||
599 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
600 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
||
601 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||
5 | mjames | 602 | |
2 | mjames | 603 | } |
604 | |||
605 | /* USER CODE BEGIN 4 */ |
||
606 | |||
607 | /* USER CODE END 4 */ |
||
608 | |||
5 | mjames | 609 | /** |
16 | mjames | 610 | * @brief This function is executed in case of error occurrence. |
611 | * @param None |
||
612 | * @retval None |
||
613 | */ |
||
7 | mjames | 614 | void Error_Handler(void) |
5 | mjames | 615 | { |
16 | mjames | 616 | /* USER CODE BEGIN Error_Handler */ |
7 | mjames | 617 | /* User can add his own implementation to report the HAL error return state */ |
618 | while (1) |
||
619 | { |
||
5 | mjames | 620 | } |
16 | mjames | 621 | /* USER CODE END Error_Handler */ |
7 | mjames | 622 | } |
5 | mjames | 623 | |
2 | mjames | 624 | #ifdef USE_FULL_ASSERT |
625 | |||
626 | /** |
||
16 | mjames | 627 | * @brief Reports the name of the source file and the source line number |
628 | * where the assert_param error has occurred. |
||
629 | * @param file: pointer to the source file name |
||
630 | * @param line: assert_param error line source number |
||
631 | * @retval None |
||
632 | */ |
||
2 | mjames | 633 | void assert_failed(uint8_t* file, uint32_t line) |
7 | mjames | 634 | { |
16 | mjames | 635 | /* USER CODE BEGIN 6 */ |
7 | mjames | 636 | /* User can add his own implementation to report the file name and line number, |
637 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
16 | mjames | 638 | /* USER CODE END 6 */ |
2 | mjames | 639 | |
7 | mjames | 640 | } |
2 | mjames | 641 | |
642 | #endif |
||
643 | |||
644 | /** |
||
16 | mjames | 645 | * @} |
646 | */ |
||
2 | mjames | 647 | |
648 | /** |
||
16 | mjames | 649 | * @} |
650 | */ |
||
2 | mjames | 651 | |
652 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |