Subversion Repositories testOled

Rev

Rev 10 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 11
Line 21... Line 21...
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
#include "bmp280driver.h"
-
 
26
#include "libMisc/fixI2C.h"
26
/* USER CODE END Includes */
27
/* USER CODE END Includes */
27
 
28
 
28
/* Private typedef -----------------------------------------------------------*/
29
/* Private typedef -----------------------------------------------------------*/
29
/* USER CODE BEGIN PTD */
30
/* USER CODE BEGIN PTD */
30
 
31
 
Line 38... Line 39...
38
/* USER CODE BEGIN PM */
39
/* USER CODE BEGIN PM */
39
 
40
 
40
/* USER CODE END PM */
41
/* USER CODE END PM */
41
 
42
 
42
/* Private variables ---------------------------------------------------------*/
43
/* Private variables ---------------------------------------------------------*/
43
I2C_HandleTypeDef hi2c1;
44
 I2C_HandleTypeDef hi2c1;
44
 
45
 
45
SPI_HandleTypeDef hspi1;
46
SPI_HandleTypeDef hspi1;
46
 
47
 
47
/* USER CODE BEGIN PV */
48
/* USER CODE BEGIN PV */
48
 
49
 
Line 58... Line 59...
58
/* USER CODE END PFP */
59
/* USER CODE END PFP */
59
 
60
 
60
/* Private user code ---------------------------------------------------------*/
61
/* Private user code ---------------------------------------------------------*/
61
/* USER CODE BEGIN 0 */
62
/* USER CODE BEGIN 0 */
62
 
63
 
63
void HAL_GPIO_WRITE_ODR(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
-
 
64
{
-
 
65
  /* Check the parameters */
-
 
66
  assert_param(IS_GPIO_PIN(GPIO_Pin));
-
 
67
 
-
 
68
  GPIOx->ODR |= GPIO_Pin;
-
 
69
}
-
 
70
 
-
 
71
/** Errata code from Stack Overflow
-
 
72
1. Disable the I2C peripheral by clearing the PE bit in I2Cx_CR1 register.
-
 
73
2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level
-
 
74
(Write 1 to GPIOx_ODR).
-
 
75
3. Check SCL and SDA High level in GPIOx_IDR.
-
 
76
4. Configure the SDA I/O as General Purpose Output Open-Drain, Low level (Write 0 to
-
 
77
GPIOx_ODR).
-
 
78
5. Check SDA Low level in GPIOx_IDR.
-
 
79
6. Configure the SCL I/O as General Purpose Output Open-Drain, Low level (Write 0 to
-
 
80
GPIOx_ODR).
-
 
81
7. Check SCL Low level in GPIOx_IDR.
-
 
82
8. Configure the SCL I/O as General Purpose Output Open-Drain, High level (Write 1 to
-
 
83
GPIOx_ODR).
-
 
84
9. Check SCL High level in GPIOx_IDR.
-
 
85
10. Configure the SDA I/O as General Purpose Output Open-Drain , High level (Write 1 to
-
 
86
GPIOx_ODR).
-
 
87
11. Check SDA High level in GPIOx_IDR.
-
 
88
12. Configure the SCL and SDA I/Os as Alternate function Open-Drain.
-
 
89
13. Set SWRST bit in I2Cx_CR1 register.
-
 
90
14. Clear SWRST bit in I2Cx_CR1 register.
-
 
91
15. Enable the I2C peripheral by setting the PE bit in I2Cx_CR1 register.
-
 
92
**/
-
 
93
 
-
 
94
void HAL_I2C_ClearBusyFlagErrata_2_14_7(I2C_HandleTypeDef *hi2c)
-
 
95
{
-
 
96
 
-
 
97
  static uint8_t resetTried = 0;
-
 
98
  if (resetTried == 1)
-
 
99
  {
-
 
100
    return;
-
 
101
  }
-
 
102
  uint32_t const SDA_PIN = GPIO_PIN_7;
-
 
103
  uint32_t const SCL_PIN = GPIO_PIN_6;
-
 
104
  GPIO_InitTypeDef GPIO_InitStruct;
-
 
105
 
-
 
106
  // 1
-
 
107
  __HAL_I2C_DISABLE(hi2c);
-
 
108
 
-
 
109
  // 2
-
 
110
  GPIO_InitStruct.Pin = SDA_PIN | SCL_PIN;
-
 
111
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
-
 
112
  GPIO_InitStruct.Pull = GPIO_NOPULL;
-
 
113
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-
 
114
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
115
 
-
 
116
  HAL_GPIO_WRITE_ODR(GPIOB, SDA_PIN);
-
 
117
  HAL_GPIO_WRITE_ODR(GPIOB, SCL_PIN);
-
 
118
 
-
 
119
  // 3
-
 
120
  GPIO_PinState pinState;
-
 
121
  if (HAL_GPIO_ReadPin(GPIOB, SDA_PIN) == GPIO_PIN_RESET)
-
 
122
  {
-
 
123
    for (;;)
-
 
124
    {
-
 
125
    }
-
 
126
  }
-
 
127
  if (HAL_GPIO_ReadPin(GPIOB, SCL_PIN) == GPIO_PIN_RESET)
-
 
128
  {
-
 
129
    for (;;)
-
 
130
    {
-
 
131
    }
-
 
132
  }
-
 
133
 
-
 
134
  // 4
-
 
135
  GPIO_InitStruct.Pin = SDA_PIN;
-
 
136
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
137
 
-
 
138
  HAL_GPIO_TogglePin(GPIOB, SDA_PIN);
-
 
139
 
-
 
140
  // 5
-
 
141
  if (HAL_GPIO_ReadPin(GPIOB, SDA_PIN) == GPIO_PIN_SET)
-
 
142
  {
-
 
143
    for (;;)
-
 
144
    {
-
 
145
    }
-
 
146
  }
-
 
147
 
-
 
148
  // 6
-
 
149
  GPIO_InitStruct.Pin = SCL_PIN;
-
 
150
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
151
 
-
 
152
  HAL_GPIO_TogglePin(GPIOB, SCL_PIN);
-
 
153
 
-
 
154
  // 7
-
 
155
  if (HAL_GPIO_ReadPin(GPIOB, SCL_PIN) == GPIO_PIN_SET)
-
 
156
  {
-
 
157
    for (;;)
-
 
158
    {
-
 
159
    }
-
 
160
  }
-
 
161
 
-
 
162
  // 8
-
 
163
  GPIO_InitStruct.Pin = SDA_PIN;
-
 
164
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
165
 
-
 
166
  HAL_GPIO_WRITE_ODR(GPIOB, SDA_PIN);
-
 
167
 
-
 
168
  // 9
-
 
169
  if (HAL_GPIO_ReadPin(GPIOB, SDA_PIN) == GPIO_PIN_RESET)
-
 
170
  {
-
 
171
    for (;;)
-
 
172
    {
-
 
173
    }
-
 
174
  }
-
 
175
 
-
 
176
  // 10
-
 
177
  GPIO_InitStruct.Pin = SCL_PIN;
-
 
178
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
179
 
-
 
180
  HAL_GPIO_WRITE_ODR(GPIOB, SCL_PIN);
-
 
181
 
-
 
182
  // 11
-
 
183
  if (HAL_GPIO_ReadPin(GPIOB, SCL_PIN) == GPIO_PIN_RESET)
-
 
184
  {
-
 
185
    for (;;)
-
 
186
    {
-
 
187
    }
-
 
188
  }
-
 
189
 
-
 
190
  // 12
-
 
191
  GPIO_InitStruct.Pin = SDA_PIN | SCL_PIN;
-
 
192
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
-
 
193
  GPIO_InitStruct.Pull = GPIO_PULLUP;
-
 
194
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
195
 
-
 
196
  // 13
-
 
197
  hi2c->Instance->CR1 |= I2C_CR1_SWRST;
-
 
198
 
-
 
199
  // 14
-
 
200
  hi2c->Instance->CR1 ^= I2C_CR1_SWRST;
-
 
201
 
-
 
202
  // 15
-
 
203
  __HAL_I2C_ENABLE(hi2c);
-
 
204
 
-
 
205
  resetTried = 1;
-
 
206
}
-
 
207
 
-
 
208
/* USER CODE END 0 */
64
/* USER CODE END 0 */
209
 
65
 
210
/**
66
/**
211
 * @brief  The application entry point.
67
  * @brief  The application entry point.
212
 * @retval int
68
  * @retval int
213
 */
69
  */
214
int main(void)
70
int main(void)
215
{
71
{
216
  /* USER CODE BEGIN 1 */
72
  /* USER CODE BEGIN 1 */
217
 
73
 
218
  /* USER CODE END 1 */
74
  /* USER CODE END 1 */
Line 251... Line 107...
251
  /* USER CODE BEGIN WHILE */
107
  /* USER CODE BEGIN WHILE */
252
  while (1)
108
  while (1)
253
  {
109
  {
254
    cc_display(0);
110
    cc_display(0);
255
 
111
 
-
 
112
    cc_feed_pushbutton(HAL_GPIO_ReadPin(PUSHBUTTON_GPIO_Port, PUSHBUTTON_Pin )==GPIO_PIN_SET);
-
 
113
 
-
 
114
 
256
    if (HAL_GetTick() - lastTick > 200)
115
    if (HAL_GetTick() - lastTick > 200)
257
    {
116
    {
258
      lastTick = HAL_GetTick();
117
      lastTick = HAL_GetTick();
259
      /* Reading the raw data from sensor */
118
      /* Reading the raw data from sensor */
260
      struct bmp280_uncomp_data ucomp_data;
119
      struct bmp280_uncomp_data ucomp_data;
Line 277... Line 136...
277
  }
136
  }
278
  /* USER CODE END 3 */
137
  /* USER CODE END 3 */
279
}
138
}
280
 
139
 
281
/**
140
/**
282
 * @brief System Clock Configuration
141
  * @brief System Clock Configuration
283
 * @retval None
142
  * @retval None
284
 */
143
  */
285
void SystemClock_Config(void)
144
void SystemClock_Config(void)
286
{
145
{
287
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
146
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
288
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
147
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
289
 
148
 
290
  /** Initializes the RCC Oscillators according to the specified parameters
149
  /** Initializes the RCC Oscillators according to the specified parameters
291
   * in the RCC_OscInitTypeDef structure.
150
  * in the RCC_OscInitTypeDef structure.
292
   */
151
  */
293
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
152
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
294
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
153
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
295
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
154
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
296
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
155
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
297
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
156
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
Line 301... Line 160...
301
  {
160
  {
302
    Error_Handler();
161
    Error_Handler();
303
  }
162
  }
304
 
163
 
305
  /** Initializes the CPU, AHB and APB buses clocks
164
  /** Initializes the CPU, AHB and APB buses clocks
306
   */
165
  */
307
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
166
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
-
 
167
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
308
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
168
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
309
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
169
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
310
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
170
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
311
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
171
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
312
 
172
 
Line 315... Line 175...
315
    Error_Handler();
175
    Error_Handler();
316
  }
176
  }
317
}
177
}
318
 
178
 
319
/**
179
/**
320
 * @brief I2C1 Initialization Function
180
  * @brief I2C1 Initialization Function
321
 * @param None
181
  * @param None
322
 * @retval None
182
  * @retval None
323
 */
183
  */
324
static void MX_I2C1_Init(void)
184
static void MX_I2C1_Init(void)
325
{
185
{
326
 
186
 
327
  /* USER CODE BEGIN I2C1_Init 0 */
187
  /* USER CODE BEGIN I2C1_Init 0 */
328
 
188
 
Line 345... Line 205...
345
    Error_Handler();
205
    Error_Handler();
346
  }
206
  }
347
  /* USER CODE BEGIN I2C1_Init 2 */
207
  /* USER CODE BEGIN I2C1_Init 2 */
348
 
208
 
349
  /* USER CODE END I2C1_Init 2 */
209
  /* USER CODE END I2C1_Init 2 */
-
 
210
 
350
}
211
}
351
 
212
 
352
/**
213
/**
353
 * @brief SPI1 Initialization Function
214
  * @brief SPI1 Initialization Function
354
 * @param None
215
  * @param None
355
 * @retval None
216
  * @retval None
356
 */
217
  */
357
static void MX_SPI1_Init(void)
218
static void MX_SPI1_Init(void)
358
{
219
{
359
 
220
 
360
  /* USER CODE BEGIN SPI1_Init 0 */
221
  /* USER CODE BEGIN SPI1_Init 0 */
361
 
222
 
Line 382... Line 243...
382
    Error_Handler();
243
    Error_Handler();
383
  }
244
  }
384
  /* USER CODE BEGIN SPI1_Init 2 */
245
  /* USER CODE BEGIN SPI1_Init 2 */
385
 
246
 
386
  /* USER CODE END SPI1_Init 2 */
247
  /* USER CODE END SPI1_Init 2 */
-
 
248
 
387
}
249
}
388
 
250
 
389
/**
251
/**
390
 * @brief GPIO Initialization Function
252
  * @brief GPIO Initialization Function
391
 * @param None
253
  * @param None
392
 * @retval None
254
  * @retval None
393
 */
255
  */
394
static void MX_GPIO_Init(void)
256
static void MX_GPIO_Init(void)
395
{
257
{
396
  GPIO_InitTypeDef GPIO_InitStruct = {0};
258
  GPIO_InitTypeDef GPIO_InitStruct = {0};
397
 
259
 
398
  /* GPIO Ports Clock Enable */
260
  /* GPIO Ports Clock Enable */
399
  __HAL_RCC_GPIOD_CLK_ENABLE();
261
  __HAL_RCC_GPIOD_CLK_ENABLE();
400
  __HAL_RCC_GPIOA_CLK_ENABLE();
262
  __HAL_RCC_GPIOA_CLK_ENABLE();
401
  __HAL_RCC_GPIOB_CLK_ENABLE();
263
  __HAL_RCC_GPIOB_CLK_ENABLE();
402
 
264
 
403
  /*Configure GPIO pin Output Level */
265
  /*Configure GPIO pin Output Level */
404
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | SPI_RESET_Pin, GPIO_PIN_RESET);
266
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin|SPI_RESET_Pin, GPIO_PIN_RESET);
405
 
267
 
406
  /*Configure GPIO pin Output Level */
268
  /*Configure GPIO pin Output Level */
407
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
269
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
408
 
270
 
409
  /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */
271
  /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */
410
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_RESET_Pin;
272
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_RESET_Pin;
411
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
273
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
412
  GPIO_InitStruct.Pull = GPIO_NOPULL;
274
  GPIO_InitStruct.Pull = GPIO_NOPULL;
413
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
275
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
414
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
276
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
415
 
277
 
Line 417... Line 279...
417
  GPIO_InitStruct.Pin = SPI_CD_Pin;
279
  GPIO_InitStruct.Pin = SPI_CD_Pin;
418
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
280
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
419
  GPIO_InitStruct.Pull = GPIO_NOPULL;
281
  GPIO_InitStruct.Pull = GPIO_NOPULL;
420
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
282
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
421
  HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct);
283
  HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct);
-
 
284
 
-
 
285
  /*Configure GPIO pin : PUSHBUTTON_Pin */
-
 
286
  GPIO_InitStruct.Pin = PUSHBUTTON_Pin;
-
 
287
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
-
 
288
  GPIO_InitStruct.Pull = GPIO_PULLUP;
-
 
289
  HAL_GPIO_Init(PUSHBUTTON_GPIO_Port, &GPIO_InitStruct);
-
 
290
 
422
}
291
}
423
 
292
 
424
/* USER CODE BEGIN 4 */
293
/* USER CODE BEGIN 4 */
425
 
294
 
426
/* USER CODE END 4 */
295
/* USER CODE END 4 */
427
 
296
 
428
/**
297
/**
429
 * @brief  This function is executed in case of error occurrence.
298
  * @brief  This function is executed in case of error occurrence.
430
 * @retval None
299
  * @retval None
431
 */
300
  */
432
void Error_Handler(void)
301
void Error_Handler(void)
433
{
302
{
434
  /* USER CODE BEGIN Error_Handler_Debug */
303
  /* USER CODE BEGIN Error_Handler_Debug */
435
  /* User can add his own implementation to report the HAL error return state */
304
  /* User can add his own implementation to report the HAL error return state */
436
  __disable_irq();
305
  __disable_irq();
Line 438... Line 307...
438
  {
307
  {
439
  }
308
  }
440
  /* USER CODE END Error_Handler_Debug */
309
  /* USER CODE END Error_Handler_Debug */
441
}
310
}
442
 
311
 
443
#ifdef USE_FULL_ASSERT
312
#ifdef  USE_FULL_ASSERT
444
/**
313
/**
445
 * @brief  Reports the name of the source file and the source line number
314
  * @brief  Reports the name of the source file and the source line number
446
 *         where the assert_param error has occurred.
315
  *         where the assert_param error has occurred.
447
 * @param  file: pointer to the source file name
316
  * @param  file: pointer to the source file name
448
 * @param  line: assert_param error line source number
317
  * @param  line: assert_param error line source number
449
 * @retval None
318
  * @retval None
450
 */
319
  */
451
void assert_failed(uint8_t *file, uint32_t line)
320
void assert_failed(uint8_t *file, uint32_t line)
452
{
321
{
453
  /* USER CODE BEGIN 6 */
322
  /* USER CODE BEGIN 6 */
454
  /* User can add his own implementation to report the file name and line number,
323
  /* User can add his own implementation to report the file name and line number,
455
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
324
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */