Subversion Repositories EngineBay2

Rev

Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 7
Line 32... Line 32...
32
  */
32
  */
33
/* Includes ------------------------------------------------------------------*/
33
/* Includes ------------------------------------------------------------------*/
34
#include "stm32l1xx_hal.h"
34
#include "stm32l1xx_hal.h"
35
 
35
 
36
/* USER CODE BEGIN Includes */
36
/* USER CODE BEGIN Includes */
37
 
-
 
-
 
37
#include "serial.h"
38
/* USER CODE END Includes */
38
/* USER CODE END Includes */
39
 
39
 
40
/* Private variables ---------------------------------------------------------*/
40
/* Private variables ---------------------------------------------------------*/
41
ADC_HandleTypeDef hadc;
41
ADC_HandleTypeDef hadc;
42
DMA_HandleTypeDef hdma_adc;
42
DMA_HandleTypeDef hdma_adc;
Line 70... Line 70...
70
               
70
               
71
 
71
 
72
/* USER CODE BEGIN PFP */
72
/* USER CODE BEGIN PFP */
73
/* Private function prototypes -----------------------------------------------*/
73
/* Private function prototypes -----------------------------------------------*/
74
 
74
 
-
 
75
long ADC_samples[6];
-
 
76
 
-
 
77
 
-
 
78
void ConfigureDMA(void)
-
 
79
{
-
 
80
 hdma_adc.Instance                 = DMA1_Channel1;
-
 
81
 hdma_adc.Init.Direction           = DMA_PERIPH_TO_MEMORY;
-
 
82
 hdma_adc.Init.PeriphInc           = DMA_PINC_DISABLE;
-
 
83
 hdma_adc.Init.MemInc              = DMA_MINC_ENABLE;
-
 
84
 hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
-
 
85
 hdma_adc.Init.MemDataAlignment    = DMA_MDATAALIGN_WORD;
-
 
86
 hdma_adc.Init.Mode                = DMA_CIRCULAR; // make the DMA loop automatically
-
 
87
 hdma_adc.Init.Priority            = DMA_PRIORITY_LOW;
-
 
88
 HAL_DMA_Init(&hdma_adc);
-
 
89
 __HAL_LINKDMA(&hadc, DMA_Handle, hdma_adc);
-
 
90
 
-
 
91
}
-
 
92
 
75
/* USER CODE END PFP */
93
/* USER CODE END PFP */
76
 
94
 
77
/* USER CODE BEGIN 0 */
95
/* USER CODE BEGIN 0 */
78
 
96
 
79
/* USER CODE END 0 */
97
/* USER CODE END 0 */
Line 103... Line 121...
103
  MX_USART1_UART_Init();
121
  MX_USART1_UART_Init();
104
  MX_USART2_UART_Init();
122
  MX_USART2_UART_Init();
105
 
123
 
106
  /* USER CODE BEGIN 2 */
124
  /* USER CODE BEGIN 2 */
107
 
125
 
-
 
126
        __HAL_RCC_SPI1_CLK_ENABLE() ;   // Temp sensor port
-
 
127
        __HAL_RCC_USART1_CLK_ENABLE() ; // PLX comms port
-
 
128
        __HAL_RCC_USART2_CLK_ENABLE() ;  // Debug comms port
-
 
129
 
-
 
130
    __HAL_RCC_ADC1_CLK_ENABLE(); // enable the ADC
-
 
131
 
-
 
132
 
-
 
133
    ConfigureDMA();
-
 
134
  //   HAL_ADC_Start_DMA(&g_AdcHandle, g_ADCBuffer, ADC_BUFFER_LENGTH);
-
 
135
 
-
 
136
        /* setup the USART control blocks */
-
 
137
        init_usart_ctl(&uc1, huart1.Instance);
-
 
138
        init_usart_ctl(&uc2, huart2.Instance);
-
 
139
 
-
 
140
        EnableSerialRxInterrupt(&uc1);
-
 
141
        EnableSerialRxInterrupt(&uc2);
-
 
142
 
-
 
143
  PutCharSerial(&uc2,'A');
-
 
144
 
108
  /* USER CODE END 2 */
145
  /* USER CODE END 2 */
109
 
146
 
110
  /* Infinite loop */
147
  /* Infinite loop */
111
  /* USER CODE BEGIN WHILE */
148
  /* USER CODE BEGIN WHILE */
112
  while (1)
149
  while (1)
113
  {
150
  {
114
  /* USER CODE END WHILE */
151
  /* USER CODE END WHILE */
-
 
152
      char c =  GetCharSerial(&uc2);
-
 
153
      PutCharSerial(&uc2,c);
-
 
154
 
-
 
155
 
115
 
156
 
116
  /* USER CODE BEGIN 3 */
157
  /* USER CODE BEGIN 3 */
117
 
158
 
118
  }
159
  }
119
  /* USER CODE END 3 */
160
  /* USER CODE END 3 */
Line 452... Line 493...
452
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
493
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
453
  GPIO_InitStruct.Pull = GPIO_NOPULL;
494
  GPIO_InitStruct.Pull = GPIO_NOPULL;
454
  HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
495
  HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
455
 
496
 
456
  /*Configure GPIO pins : PA0 PA1 PA8 PA11
497
  /*Configure GPIO pins : PA0 PA1 PA8 PA11
457
                           PA12 PA13 PA14 */
498
                           PA12 */
458
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11
499
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11
459
                          |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14;
500
                          |GPIO_PIN_12;
460
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
501
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
461
  GPIO_InitStruct.Pull = GPIO_NOPULL;
502
  GPIO_InitStruct.Pull = GPIO_NOPULL;
462
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
503
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
463
 
504
 
464
  /*Configure GPIO pin : NSS_CHT_Pin */
505
  /*Configure GPIO pin : LED_Blink_Pin */
465
  GPIO_InitStruct.Pin = NSS_CHT_Pin;
506
  GPIO_InitStruct.Pin = LED_Blink_Pin;
466
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
507
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
467
  GPIO_InitStruct.Pull = GPIO_NOPULL;
508
  GPIO_InitStruct.Pull = GPIO_NOPULL;
468
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
509
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
469
  HAL_GPIO_Init(NSS_CHT_GPIO_Port, &GPIO_InitStruct);
510
  HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct);
470
 
511
 
471
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */
512
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */
472
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin;
513
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin;
473
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
514
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
474
  GPIO_InitStruct.Pull = GPIO_NOPULL;
515
  GPIO_InitStruct.Pull = GPIO_NOPULL;
475
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
516
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
476
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
517
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
477
 
518
 
478
  /*Configure GPIO pin : SPI_RESET_Pin */
519
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NS_Temp_Pin */
479
  GPIO_InitStruct.Pin = SPI_RESET_Pin;
520
  GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NS_Temp_Pin;
480
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
521
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
481
  GPIO_InitStruct.Pull = GPIO_NOPULL;
522
  GPIO_InitStruct.Pull = GPIO_NOPULL;
482
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
523
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
483
  HAL_GPIO_Init(SPI_RESET_GPIO_Port, &GPIO_InitStruct);
524
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
484
 
525
 
485
  /*Configure GPIO pins : PB1 PB2 PB12 PB13
526
  /*Configure GPIO pins : PB2 PB12 PB13 PB14
486
                           PB14 PB15 PB4 PB5
527
                           PB15 PB4 PB5 PB6
487
                           PB6 PB7 PB8 PB9 */
528
                           PB7 PB8 PB9 */
488
  GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_12|GPIO_PIN_13
529
  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
489
                          |GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5
530
                          |GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
490
                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
531
                          |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
491
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
532
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
492
  GPIO_InitStruct.Pull = GPIO_NOPULL;
533
  GPIO_InitStruct.Pull = GPIO_NOPULL;
493
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
534
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
494
 
535
 
495
  /*Configure GPIO pin : PD2 */
536
  /*Configure GPIO pin : PD2 */
Line 497... Line 538...
497
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
538
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
498
  GPIO_InitStruct.Pull = GPIO_NOPULL;
539
  GPIO_InitStruct.Pull = GPIO_NOPULL;
499
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
540
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
500
 
541
 
501
  /*Configure GPIO pin Output Level */
542
  /*Configure GPIO pin Output Level */
502
  HAL_GPIO_WritePin(NSS_CHT_GPIO_Port, NSS_CHT_Pin, GPIO_PIN_RESET);
543
  HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET);
-
 
544
 
-
 
545
  /*Configure GPIO pin Output Level */
-
 
546
  HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
503
 
547
 
504
  /*Configure GPIO pin Output Level */
548
  /*Configure GPIO pin Output Level */
505
  HAL_GPIO_WritePin(GPIOC, SPI_NSS1_Pin|SPI1CD_Pin, GPIO_PIN_RESET);
549
  HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET);
506
 
550
 
507
  /*Configure GPIO pin Output Level */
551
  /*Configure GPIO pin Output Level */
508
  HAL_GPIO_WritePin(SPI_RESET_GPIO_Port, SPI_RESET_Pin, GPIO_PIN_RESET);
552
  HAL_GPIO_WritePin(SPI_RESET_GPIO_Port, SPI_RESET_Pin, GPIO_PIN_RESET);
509
 
553
 
-
 
554
  /*Configure GPIO pin Output Level */
-
 
555
  HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET);
-
 
556
 
510
}
557
}
511
 
558
 
512
/* USER CODE BEGIN 4 */
559
/* USER CODE BEGIN 4 */
513
 
560
 
514
/* USER CODE END 4 */
561
/* USER CODE END 4 */