Rev 2 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 4 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | #include "main.h" |
20 | #include "main.h" |
21 | 21 | ||
22 | /* Private includes ----------------------------------------------------------*/ |
22 | /* Private includes ----------------------------------------------------------*/ |
23 | /* USER CODE BEGIN Includes */ |
23 | /* USER CODE BEGIN Includes */ |
24 | #include "display.h" |
24 | #include "display.h" |
- | 25 | #include "bmp280driver.h" |
|
25 | /* USER CODE END Includes */ |
26 | /* USER CODE END Includes */ |
26 | 27 | ||
27 | /* Private typedef -----------------------------------------------------------*/ |
28 | /* Private typedef -----------------------------------------------------------*/ |
28 | /* USER CODE BEGIN PTD */ |
29 | /* USER CODE BEGIN PTD */ |
29 | 30 | ||
Line 37... | Line 38... | ||
37 | /* USER CODE BEGIN PM */ |
38 | /* USER CODE BEGIN PM */ |
38 | 39 | ||
39 | /* USER CODE END PM */ |
40 | /* USER CODE END PM */ |
40 | 41 | ||
41 | /* Private variables ---------------------------------------------------------*/ |
42 | /* Private variables ---------------------------------------------------------*/ |
- | 43 | I2C_HandleTypeDef hi2c1; |
|
- | 44 | ||
42 | SPI_HandleTypeDef hspi1; |
45 | SPI_HandleTypeDef hspi1; |
43 | 46 | ||
44 | /* USER CODE BEGIN PV */ |
47 | /* USER CODE BEGIN PV */ |
45 | 48 | ||
46 | /* USER CODE END PV */ |
49 | /* USER CODE END PV */ |
47 | 50 | ||
48 | /* Private function prototypes -----------------------------------------------*/ |
51 | /* Private function prototypes -----------------------------------------------*/ |
49 | void SystemClock_Config(void); |
52 | void SystemClock_Config(void); |
50 | static void MX_GPIO_Init(void); |
53 | static void MX_GPIO_Init(void); |
51 | static void MX_SPI1_Init(void); |
54 | static void MX_SPI1_Init(void); |
- | 55 | static void MX_I2C1_Init(void); |
|
52 | /* USER CODE BEGIN PFP */ |
56 | /* USER CODE BEGIN PFP */ |
53 | 57 | ||
54 | /* USER CODE END PFP */ |
58 | /* USER CODE END PFP */ |
55 | 59 | ||
56 | /* Private user code ---------------------------------------------------------*/ |
60 | /* Private user code ---------------------------------------------------------*/ |
57 | /* USER CODE BEGIN 0 */ |
61 | /* USER CODE BEGIN 0 */ |
58 | 62 | ||
59 | /* USER CODE END 0 */ |
63 | /* USER CODE END 0 */ |
60 | 64 | ||
61 | /** |
65 | /** |
62 | * @brief The application entry point. |
66 | * @brief The application entry point. |
63 | * @retval int |
67 | * @retval int |
64 | */ |
68 | */ |
65 | int main(void) |
69 | int main(void) |
66 | { |
70 | { |
67 | /* USER CODE BEGIN 1 */ |
71 | /* USER CODE BEGIN 1 */ |
68 | 72 | ||
69 | /* USER CODE END 1 */ |
73 | /* USER CODE END 1 */ |
70 | 74 | ||
71 | /* MCU Configuration--------------------------------------------------------*/ |
75 | /* MCU Configuration--------------------------------------------------------*/ |
Line 85... | Line 89... | ||
85 | /* USER CODE END SysInit */ |
89 | /* USER CODE END SysInit */ |
86 | 90 | ||
87 | /* Initialize all configured peripherals */ |
91 | /* Initialize all configured peripherals */ |
88 | MX_GPIO_Init(); |
92 | MX_GPIO_Init(); |
89 | MX_SPI1_Init(); |
93 | MX_SPI1_Init(); |
- | 94 | MX_I2C1_Init(); |
|
90 | /* USER CODE BEGIN 2 */ |
95 | /* USER CODE BEGIN 2 */ |
91 | cc_init(); |
96 | cc_init(); |
- | 97 | ||
- | 98 | init_bmp(&hi2c1); |
|
- | 99 | uint32_t lastTick = HAL_GetTick(); |
|
92 | /* USER CODE END 2 */ |
100 | /* USER CODE END 2 */ |
93 | 101 | ||
94 | /* Infinite loop */ |
102 | /* Infinite loop */ |
95 | /* USER CODE BEGIN WHILE */ |
103 | /* USER CODE BEGIN WHILE */ |
96 | while (1) |
104 | while (1) |
97 | { |
105 | { |
98 | cc_display(0); |
106 | cc_display(0); |
- | 107 | ||
- | 108 | if (HAL_GetTick() - lastTick > 200) |
|
- | 109 | { |
|
- | 110 | lastTick = HAL_GetTick(); |
|
- | 111 | /* Reading the raw data from sensor */ |
|
- | 112 | struct bmp280_uncomp_data ucomp_data; |
|
- | 113 | uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp); |
|
- | 114 | ||
- | 115 | uint32_t comp_pres = 0; |
|
- | 116 | int32_t comp_temp = -10000; |
|
- | 117 | if (rslt == 0) |
|
- | 118 | { |
|
- | 119 | uint8_t rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp); |
|
- | 120 | ||
- | 121 | uint8_t rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp); |
|
- | 122 | } |
|
- | 123 | } |
|
99 | /* USER CODE END WHILE */ |
124 | /* USER CODE END WHILE */ |
100 | 125 | ||
101 | /* USER CODE BEGIN 3 */ |
126 | /* USER CODE BEGIN 3 */ |
102 | - | ||
103 | } |
127 | } |
104 | /* USER CODE END 3 */ |
128 | /* USER CODE END 3 */ |
105 | } |
129 | } |
106 | 130 | ||
107 | /** |
131 | /** |
108 | * @brief System Clock Configuration |
132 | * @brief System Clock Configuration |
109 | * @retval None |
133 | * @retval None |
110 | */ |
134 | */ |
111 | void SystemClock_Config(void) |
135 | void SystemClock_Config(void) |
112 | { |
136 | { |
113 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
137 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
114 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
138 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
115 | 139 | ||
116 | /** Initializes the RCC Oscillators according to the specified parameters |
140 | /** Initializes the RCC Oscillators according to the specified parameters |
117 | * in the RCC_OscInitTypeDef structure. |
141 | * in the RCC_OscInitTypeDef structure. |
118 | */ |
142 | */ |
119 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
143 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
120 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
144 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
121 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
145 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
122 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
146 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
123 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
147 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
Line 127... | Line 151... | ||
127 | { |
151 | { |
128 | Error_Handler(); |
152 | Error_Handler(); |
129 | } |
153 | } |
130 | 154 | ||
131 | /** Initializes the CPU, AHB and APB buses clocks |
155 | /** Initializes the CPU, AHB and APB buses clocks |
132 | */ |
156 | */ |
133 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
157 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
134 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
- | |
135 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
158 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
136 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
159 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
137 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
160 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
138 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
161 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
139 | 162 | ||
Line 142... | Line 165... | ||
142 | Error_Handler(); |
165 | Error_Handler(); |
143 | } |
166 | } |
144 | } |
167 | } |
145 | 168 | ||
146 | /** |
169 | /** |
- | 170 | * @brief I2C1 Initialization Function |
|
- | 171 | * @param None |
|
- | 172 | * @retval None |
|
- | 173 | */ |
|
- | 174 | static void MX_I2C1_Init(void) |
|
- | 175 | { |
|
- | 176 | ||
- | 177 | /* USER CODE BEGIN I2C1_Init 0 */ |
|
- | 178 | ||
- | 179 | /* USER CODE END I2C1_Init 0 */ |
|
- | 180 | ||
- | 181 | /* USER CODE BEGIN I2C1_Init 1 */ |
|
- | 182 | ||
- | 183 | /* USER CODE END I2C1_Init 1 */ |
|
- | 184 | hi2c1.Instance = I2C1; |
|
- | 185 | hi2c1.Init.ClockSpeed = 100000; |
|
- | 186 | hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; |
|
- | 187 | hi2c1.Init.OwnAddress1 = 0; |
|
- | 188 | hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
|
- | 189 | hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
|
- | 190 | hi2c1.Init.OwnAddress2 = 0; |
|
- | 191 | hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
|
- | 192 | hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
|
- | 193 | if (HAL_I2C_Init(&hi2c1) != HAL_OK) |
|
- | 194 | { |
|
- | 195 | Error_Handler(); |
|
- | 196 | } |
|
- | 197 | /* USER CODE BEGIN I2C1_Init 2 */ |
|
- | 198 | ||
- | 199 | /* USER CODE END I2C1_Init 2 */ |
|
- | 200 | } |
|
- | 201 | ||
- | 202 | /** |
|
147 | * @brief SPI1 Initialization Function |
203 | * @brief SPI1 Initialization Function |
148 | * @param None |
204 | * @param None |
149 | * @retval None |
205 | * @retval None |
150 | */ |
206 | */ |
151 | static void MX_SPI1_Init(void) |
207 | static void MX_SPI1_Init(void) |
152 | { |
208 | { |
153 | 209 | ||
154 | /* USER CODE BEGIN SPI1_Init 0 */ |
210 | /* USER CODE BEGIN SPI1_Init 0 */ |
155 | 211 | ||
Line 176... | Line 232... | ||
176 | Error_Handler(); |
232 | Error_Handler(); |
177 | } |
233 | } |
178 | /* USER CODE BEGIN SPI1_Init 2 */ |
234 | /* USER CODE BEGIN SPI1_Init 2 */ |
179 | 235 | ||
180 | /* USER CODE END SPI1_Init 2 */ |
236 | /* USER CODE END SPI1_Init 2 */ |
181 | - | ||
182 | } |
237 | } |
183 | 238 | ||
184 | /** |
239 | /** |
185 | * @brief GPIO Initialization Function |
240 | * @brief GPIO Initialization Function |
186 | * @param None |
241 | * @param None |
187 | * @retval None |
242 | * @retval None |
188 | */ |
243 | */ |
189 | static void MX_GPIO_Init(void) |
244 | static void MX_GPIO_Init(void) |
190 | { |
245 | { |
191 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
246 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
192 | 247 | ||
193 | /* GPIO Ports Clock Enable */ |
248 | /* GPIO Ports Clock Enable */ |
194 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
249 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
195 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
250 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
196 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
251 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
197 | 252 | ||
198 | /*Configure GPIO pin Output Level */ |
253 | /*Configure GPIO pin Output Level */ |
199 | HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin|SPI_RESET_Pin, GPIO_PIN_RESET); |
254 | HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | SPI_RESET_Pin, GPIO_PIN_RESET); |
200 | 255 | ||
201 | /*Configure GPIO pin Output Level */ |
256 | /*Configure GPIO pin Output Level */ |
202 | HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET); |
257 | HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET); |
203 | 258 | ||
204 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */ |
259 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */ |
205 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_RESET_Pin; |
260 | GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_RESET_Pin; |
206 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
261 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
207 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
262 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
208 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
263 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
209 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
264 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
210 | 265 | ||
Line 212... | Line 267... | ||
212 | GPIO_InitStruct.Pin = SPI_CD_Pin; |
267 | GPIO_InitStruct.Pin = SPI_CD_Pin; |
213 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
268 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
214 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
269 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
215 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
270 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
216 | HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct); |
271 | HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct); |
217 | - | ||
218 | } |
272 | } |
219 | 273 | ||
220 | /* USER CODE BEGIN 4 */ |
274 | /* USER CODE BEGIN 4 */ |
221 | 275 | ||
222 | /* USER CODE END 4 */ |
276 | /* USER CODE END 4 */ |
223 | 277 | ||
224 | /** |
278 | /** |
225 | * @brief This function is executed in case of error occurrence. |
279 | * @brief This function is executed in case of error occurrence. |
226 | * @retval None |
280 | * @retval None |
227 | */ |
281 | */ |
228 | void Error_Handler(void) |
282 | void Error_Handler(void) |
229 | { |
283 | { |
230 | /* USER CODE BEGIN Error_Handler_Debug */ |
284 | /* USER CODE BEGIN Error_Handler_Debug */ |
231 | /* User can add his own implementation to report the HAL error return state */ |
285 | /* User can add his own implementation to report the HAL error return state */ |
232 | __disable_irq(); |
286 | __disable_irq(); |
Line 234... | Line 288... | ||
234 | { |
288 | { |
235 | } |
289 | } |
236 | /* USER CODE END Error_Handler_Debug */ |
290 | /* USER CODE END Error_Handler_Debug */ |
237 | } |
291 | } |
238 | 292 | ||
239 | #ifdef USE_FULL_ASSERT |
293 | #ifdef USE_FULL_ASSERT |
240 | /** |
294 | /** |
241 | * @brief Reports the name of the source file and the source line number |
295 | * @brief Reports the name of the source file and the source line number |
242 | * where the assert_param error has occurred. |
296 | * where the assert_param error has occurred. |
243 | * @param file: pointer to the source file name |
297 | * @param file: pointer to the source file name |
244 | * @param line: assert_param error line source number |
298 | * @param line: assert_param error line source number |
245 | * @retval None |
299 | * @retval None |
246 | */ |
300 | */ |
247 | void assert_failed(uint8_t *file, uint32_t line) |
301 | void assert_failed(uint8_t *file, uint32_t line) |
248 | { |
302 | { |
249 | /* USER CODE BEGIN 6 */ |
303 | /* USER CODE BEGIN 6 */ |
250 | /* User can add his own implementation to report the file name and line number, |
304 | /* User can add his own implementation to report the file name and line number, |
251 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
305 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |