adc.c.bak 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file adc.c
  5. * @brief This file provides code for the configuration
  6. * of the ADC instances.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2025 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "adc.h"
  22. /* USER CODE BEGIN 0 */
  23. /* USER CODE END 0 */
  24. ADC_HandleTypeDef hadc1;
  25. /* ADC1 init function */
  26. void MX_ADC1_Init(void)
  27. {
  28. /* USER CODE BEGIN ADC1_Init 0 */
  29. /* USER CODE END ADC1_Init 0 */
  30. ADC_ChannelConfTypeDef sConfig = {0};
  31. /* USER CODE BEGIN ADC1_Init 1 */
  32. /* USER CODE END ADC1_Init 1 */
  33. /** Common config
  34. */
  35. hadc1.Instance = ADC1;
  36. hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  37. hadc1.Init.ContinuousConvMode = DISABLE;
  38. hadc1.Init.DiscontinuousConvMode = DISABLE;
  39. hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  40. hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  41. hadc1.Init.NbrOfConversion = 1;
  42. if (HAL_ADC_Init(&hadc1) != HAL_OK)
  43. {
  44. Error_Handler();
  45. }
  46. /** Configure Regular Channel
  47. */
  48. sConfig.Channel = ADC_CHANNEL_9;
  49. sConfig.Rank = ADC_REGULAR_RANK_1;
  50. sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  51. if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  52. {
  53. Error_Handler();
  54. }
  55. /* USER CODE BEGIN ADC1_Init 2 */
  56. /* USER CODE END ADC1_Init 2 */
  57. }
  58. void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
  59. {
  60. GPIO_InitTypeDef GPIO_InitStruct = {0};
  61. if(adcHandle->Instance==ADC1)
  62. {
  63. /* USER CODE BEGIN ADC1_MspInit 0 */
  64. /* USER CODE END ADC1_MspInit 0 */
  65. /* ADC1 clock enable */
  66. __HAL_RCC_ADC1_CLK_ENABLE();
  67. __HAL_RCC_GPIOB_CLK_ENABLE();
  68. /**ADC1 GPIO Configuration
  69. PB1 ------> ADC1_IN9
  70. */
  71. GPIO_InitStruct.Pin = NTC_Pin;
  72. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  73. HAL_GPIO_Init(NTC_GPIO_Port, &GPIO_InitStruct);
  74. /* USER CODE BEGIN ADC1_MspInit 1 */
  75. /* USER CODE END ADC1_MspInit 1 */
  76. }
  77. }
  78. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
  79. {
  80. if(adcHandle->Instance==ADC1)
  81. {
  82. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  83. /* USER CODE END ADC1_MspDeInit 0 */
  84. /* Peripheral clock disable */
  85. __HAL_RCC_ADC1_CLK_DISABLE();
  86. /**ADC1 GPIO Configuration
  87. PB1 ------> ADC1_IN9
  88. */
  89. HAL_GPIO_DeInit(NTC_GPIO_Port, NTC_Pin);
  90. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  91. /* USER CODE END ADC1_MspDeInit 1 */
  92. }
  93. }
  94. /* USER CODE BEGIN 1 */
  95. /* USER CODE END 1 */