Subversion Repositories testOled

Rev

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

Rev 9 Rev 10
Line 38... Line 38...
38
/* USER CODE BEGIN PM */
38
/* USER CODE BEGIN PM */
39
 
39
 
40
/* USER CODE END PM */
40
/* USER CODE END PM */
41
 
41
 
42
/* Private variables ---------------------------------------------------------*/
42
/* Private variables ---------------------------------------------------------*/
43
 I2C_HandleTypeDef hi2c1;
43
I2C_HandleTypeDef hi2c1;
44
 
44
 
45
SPI_HandleTypeDef hspi1;
45
SPI_HandleTypeDef hspi1;
46
 
46
 
47
/* USER CODE BEGIN PV */
47
/* USER CODE BEGIN PV */
48
 
48
 
Line 58... Line 58...
58
/* USER CODE END PFP */
58
/* USER CODE END PFP */
59
 
59
 
60
/* Private user code ---------------------------------------------------------*/
60
/* Private user code ---------------------------------------------------------*/
61
/* USER CODE BEGIN 0 */
61
/* USER CODE BEGIN 0 */
62
 
62
 
63
void HAL_GPIO_WRITE_ODR(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
63
void HAL_GPIO_WRITE_ODR(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
64
{
64
{
65
  /* Check the parameters */
65
  /* Check the parameters */
66
  assert_param(IS_GPIO_PIN(GPIO_Pin));
66
  assert_param(IS_GPIO_PIN(GPIO_Pin));
67
 
67
 
68
  GPIOx->ODR |= GPIO_Pin;
68
  GPIOx->ODR |= GPIO_Pin;
69
}
69
}
70
 
70
 
71
 
-
 
72
/** Errata code from Stack Overflow
71
/** Errata code from Stack Overflow
73
1. Disable the I2C peripheral by clearing the PE bit in I2Cx_CR1 register.
72
1. Disable the I2C peripheral by clearing the PE bit in I2Cx_CR1 register.
74
2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level
73
2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level
75
(Write 1 to GPIOx_ODR).
74
(Write 1 to GPIOx_ODR).
76
3. Check SCL and SDA High level in GPIOx_IDR.
75
3. Check SCL and SDA High level in GPIOx_IDR.
77
4. Configure the SDA I/O as General Purpose Output Open-Drain, Low level (Write 0 to
76
4. Configure the SDA I/O as General Purpose Output Open-Drain, Low level (Write 0 to
Line 98... Line 97...
98
  static uint8_t resetTried = 0;
97
  static uint8_t resetTried = 0;
99
  if (resetTried == 1)
98
  if (resetTried == 1)
100
  {
99
  {
101
    return;
100
    return;
102
  }
101
  }
103
  uint32_t const SDA_PIN =  GPIO_PIN_7;
102
  uint32_t const SDA_PIN = GPIO_PIN_7;
104
  uint32_t const SCL_PIN = GPIO_PIN_6;
103
  uint32_t const SCL_PIN = GPIO_PIN_6;
105
  GPIO_InitTypeDef GPIO_InitStruct;
104
  GPIO_InitTypeDef GPIO_InitStruct;
106
 
105
 
107
  // 1
106
  // 1
108
  __HAL_I2C_DISABLE(hi2c);
107
  __HAL_I2C_DISABLE(hi2c);
Line 189... Line 188...
189
  }
188
  }
190
 
189
 
191
  // 12
190
  // 12
192
  GPIO_InitStruct.Pin = SDA_PIN | SCL_PIN;
191
  GPIO_InitStruct.Pin = SDA_PIN | SCL_PIN;
193
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
192
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
194
  GPIO_InitStruct.Pull =   GPIO_PULLUP;
193
  GPIO_InitStruct.Pull = GPIO_PULLUP;
195
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
194
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
196
 
195
 
197
  // 13
196
  // 13
198
  hi2c->Instance->CR1 |= I2C_CR1_SWRST;
197
  hi2c->Instance->CR1 |= I2C_CR1_SWRST;
199
 
198
 
Line 207... Line 206...
207
}
206
}
208
 
207
 
209
/* USER CODE END 0 */
208
/* USER CODE END 0 */
210
 
209
 
211
/**
210
/**
212
  * @brief  The application entry point.
211
 * @brief  The application entry point.
213
  * @retval int
212
 * @retval int
214
  */
213
 */
215
int main(void)
214
int main(void)
216
{
215
{
217
  /* USER CODE BEGIN 1 */
216
  /* USER CODE BEGIN 1 */
218
 
217
 
219
  /* USER CODE END 1 */
218
  /* USER CODE END 1 */
Line 266... Line 265...
266
      if (rslt == 0)
265
      if (rslt == 0)
267
      {
266
      {
268
        uint8_t rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
267
        uint8_t rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
269
 
268
 
270
        uint8_t rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
269
        uint8_t rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
-
 
270
 
-
 
271
        cc_feed(comp_pres, comp_temp);
271
      }
272
      }
272
    }
273
    }
273
    /* USER CODE END WHILE */
274
    /* USER CODE END WHILE */
274
 
275
 
275
    /* USER CODE BEGIN 3 */
276
    /* USER CODE BEGIN 3 */
276
  }
277
  }
277
  /* USER CODE END 3 */
278
  /* USER CODE END 3 */
278
}
279
}
279
 
280
 
280
/**
281
/**
281
  * @brief System Clock Configuration
282
 * @brief System Clock Configuration
282
  * @retval None
283
 * @retval None
283
  */
284
 */
284
void SystemClock_Config(void)
285
void SystemClock_Config(void)
285
{
286
{
286
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
287
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
287
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
288
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
288
 
289
 
289
  /** Initializes the RCC Oscillators according to the specified parameters
290
  /** Initializes the RCC Oscillators according to the specified parameters
290
  * in the RCC_OscInitTypeDef structure.
291
   * in the RCC_OscInitTypeDef structure.
291
  */
292
   */
292
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
293
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
293
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
294
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
294
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
295
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
295
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
296
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
296
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
297
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
Line 300... Line 301...
300
  {
301
  {
301
    Error_Handler();
302
    Error_Handler();
302
  }
303
  }
303
 
304
 
304
  /** Initializes the CPU, AHB and APB buses clocks
305
  /** Initializes the CPU, AHB and APB buses clocks
305
  */
306
   */
306
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
307
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
307
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
-
 
308
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
308
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
309
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
309
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
310
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
310
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
311
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
311
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
312
 
312
 
Line 315... Line 315...
315
    Error_Handler();
315
    Error_Handler();
316
  }
316
  }
317
}
317
}
318
 
318
 
319
/**
319
/**
320
  * @brief I2C1 Initialization Function
320
 * @brief I2C1 Initialization Function
321
  * @param None
321
 * @param None
322
  * @retval None
322
 * @retval None
323
  */
323
 */
324
static void MX_I2C1_Init(void)
324
static void MX_I2C1_Init(void)
325
{
325
{
326
 
326
 
327
  /* USER CODE BEGIN I2C1_Init 0 */
327
  /* USER CODE BEGIN I2C1_Init 0 */
328
 
328
 
Line 345... Line 345...
345
    Error_Handler();
345
    Error_Handler();
346
  }
346
  }
347
  /* USER CODE BEGIN I2C1_Init 2 */
347
  /* USER CODE BEGIN I2C1_Init 2 */
348
 
348
 
349
  /* USER CODE END I2C1_Init 2 */
349
  /* USER CODE END I2C1_Init 2 */
350
 
-
 
351
}
350
}
352
 
351
 
353
/**
352
/**
354
  * @brief SPI1 Initialization Function
353
 * @brief SPI1 Initialization Function
355
  * @param None
354
 * @param None
356
  * @retval None
355
 * @retval None
357
  */
356
 */
358
static void MX_SPI1_Init(void)
357
static void MX_SPI1_Init(void)
359
{
358
{
360
 
359
 
361
  /* USER CODE BEGIN SPI1_Init 0 */
360
  /* USER CODE BEGIN SPI1_Init 0 */
362
 
361
 
Line 383... Line 382...
383
    Error_Handler();
382
    Error_Handler();
384
  }
383
  }
385
  /* USER CODE BEGIN SPI1_Init 2 */
384
  /* USER CODE BEGIN SPI1_Init 2 */
386
 
385
 
387
  /* USER CODE END SPI1_Init 2 */
386
  /* USER CODE END SPI1_Init 2 */
388
 
-
 
389
}
387
}
390
 
388
 
391
/**
389
/**
392
  * @brief GPIO Initialization Function
390
 * @brief GPIO Initialization Function
393
  * @param None
391
 * @param None
394
  * @retval None
392
 * @retval None
395
  */
393
 */
396
static void MX_GPIO_Init(void)
394
static void MX_GPIO_Init(void)
397
{
395
{
398
  GPIO_InitTypeDef GPIO_InitStruct = {0};
396
  GPIO_InitTypeDef GPIO_InitStruct = {0};
399
 
397
 
400
  /* GPIO Ports Clock Enable */
398
  /* GPIO Ports Clock Enable */
401
  __HAL_RCC_GPIOD_CLK_ENABLE();
399
  __HAL_RCC_GPIOD_CLK_ENABLE();
402
  __HAL_RCC_GPIOA_CLK_ENABLE();
400
  __HAL_RCC_GPIOA_CLK_ENABLE();
403
  __HAL_RCC_GPIOB_CLK_ENABLE();
401
  __HAL_RCC_GPIOB_CLK_ENABLE();
404
 
402
 
405
  /*Configure GPIO pin Output Level */
403
  /*Configure GPIO pin Output Level */
406
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin|SPI_RESET_Pin, GPIO_PIN_RESET);
404
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | SPI_RESET_Pin, GPIO_PIN_RESET);
407
 
405
 
408
  /*Configure GPIO pin Output Level */
406
  /*Configure GPIO pin Output Level */
409
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
407
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
410
 
408
 
411
  /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */
409
  /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */
412
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_RESET_Pin;
410
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_RESET_Pin;
413
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
411
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
414
  GPIO_InitStruct.Pull = GPIO_NOPULL;
412
  GPIO_InitStruct.Pull = GPIO_NOPULL;
415
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
413
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
416
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
414
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
417
 
415
 
Line 419... Line 417...
419
  GPIO_InitStruct.Pin = SPI_CD_Pin;
417
  GPIO_InitStruct.Pin = SPI_CD_Pin;
420
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
418
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
421
  GPIO_InitStruct.Pull = GPIO_NOPULL;
419
  GPIO_InitStruct.Pull = GPIO_NOPULL;
422
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
420
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
423
  HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct);
421
  HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct);
424
 
-
 
425
}
422
}
426
 
423
 
427
/* USER CODE BEGIN 4 */
424
/* USER CODE BEGIN 4 */
428
 
425
 
429
/* USER CODE END 4 */
426
/* USER CODE END 4 */
430
 
427
 
431
/**
428
/**
432
  * @brief  This function is executed in case of error occurrence.
429
 * @brief  This function is executed in case of error occurrence.
433
  * @retval None
430
 * @retval None
434
  */
431
 */
435
void Error_Handler(void)
432
void Error_Handler(void)
436
{
433
{
437
  /* USER CODE BEGIN Error_Handler_Debug */
434
  /* USER CODE BEGIN Error_Handler_Debug */
438
  /* User can add his own implementation to report the HAL error return state */
435
  /* User can add his own implementation to report the HAL error return state */
439
  __disable_irq();
436
  __disable_irq();
Line 441... Line 438...
441
  {
438
  {
442
  }
439
  }
443
  /* USER CODE END Error_Handler_Debug */
440
  /* USER CODE END Error_Handler_Debug */
444
}
441
}
445
 
442
 
446
#ifdef  USE_FULL_ASSERT
443
#ifdef USE_FULL_ASSERT
447
/**
444
/**
448
  * @brief  Reports the name of the source file and the source line number
445
 * @brief  Reports the name of the source file and the source line number
449
  *         where the assert_param error has occurred.
446
 *         where the assert_param error has occurred.
450
  * @param  file: pointer to the source file name
447
 * @param  file: pointer to the source file name
451
  * @param  line: assert_param error line source number
448
 * @param  line: assert_param error line source number
452
  * @retval None
449
 * @retval None
453
  */
450
 */
454
void assert_failed(uint8_t *file, uint32_t line)
451
void assert_failed(uint8_t *file, uint32_t line)
455
{
452
{
456
  /* USER CODE BEGIN 6 */
453
  /* USER CODE BEGIN 6 */
457
  /* User can add his own implementation to report the file name and line number,
454
  /* User can add his own implementation to report the file name and line number,
458
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
455
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */