L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
adc.c
Go to the documentation of this file.
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) 2026 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
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27ADC_HandleTypeDef hadc;
28
29/* ADC init function */
30void MX_ADC_Init(void)
31{
32
33 /* USER CODE BEGIN ADC_Init 0 */
34
35 /* USER CODE END ADC_Init 0 */
36
37 ADC_ChannelConfTypeDef sConfig = {0};
38
39 /* USER CODE BEGIN ADC_Init 1 */
40
41 /* USER CODE END ADC_Init 1 */
42
43 /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
44 */
45 hadc.Instance = ADC;
46 hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
47 hadc.Init.Resolution = ADC_RESOLUTION_12B;
48 hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
49 hadc.Init.ScanConvMode = ADC_SCAN_DISABLE;
50 hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
51 hadc.Init.LowPowerAutoWait = ENABLE;
52 hadc.Init.LowPowerAutoPowerOff = ENABLE;
53 hadc.Init.ContinuousConvMode = DISABLE;
54 hadc.Init.NbrOfConversion = 1;
55 hadc.Init.DiscontinuousConvMode = DISABLE;
56 hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
57 hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
58 hadc.Init.DMAContinuousRequests = DISABLE;
59 hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
60 hadc.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_160CYCLES_5;
61 hadc.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_160CYCLES_5;
62 hadc.Init.OversamplingMode = DISABLE;
63 hadc.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
64 if (HAL_ADC_Init(&hadc) != HAL_OK)
65 {
67 }
68
69 /** Configure Regular Channel
70 */
71 sConfig.Channel = ADC_CHANNEL_VREFINT;
72 sConfig.Rank = ADC_REGULAR_RANK_1;
73 sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
74 if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
75 {
77 }
78 /* USER CODE BEGIN ADC_Init 2 */
79
80 /* USER CODE END ADC_Init 2 */
81
82}
83
84void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
85{
86
87 GPIO_InitTypeDef GPIO_InitStruct = {0};
88 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
89 if(adcHandle->Instance==ADC)
90 {
91 /* USER CODE BEGIN ADC_MspInit 0 */
92
93 /* USER CODE END ADC_MspInit 0 */
94
95 /** Initializes the peripherals clocks
96 */
97 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
98 PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
99 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
100 {
102 }
103
104 /* ADC clock enable */
105 __HAL_RCC_ADC_CLK_ENABLE();
106
107 __HAL_RCC_GPIOA_CLK_ENABLE();
108 /**ADC GPIO Configuration
109 PA15 ------> ADC_IN11
110 */
111 GPIO_InitStruct.Pin = GPIO_PIN_15;
112 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
113 GPIO_InitStruct.Pull = GPIO_NOPULL;
114 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
115
116 /* ADC interrupt Init */
117 HAL_NVIC_SetPriority(ADC_IRQn, 3, 0);
118 HAL_NVIC_EnableIRQ(ADC_IRQn);
119 /* USER CODE BEGIN ADC_MspInit 1 */
120
121 /* USER CODE END ADC_MspInit 1 */
122 }
123}
124
125void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
126{
127
128 if(adcHandle->Instance==ADC)
129 {
130 /* USER CODE BEGIN ADC_MspDeInit 0 */
131
132 /* USER CODE END ADC_MspDeInit 0 */
133 /* Peripheral clock disable */
134 __HAL_RCC_ADC_CLK_DISABLE();
135
136 /**ADC GPIO Configuration
137 PA15 ------> ADC_IN11
138 */
139 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_15);
140
141 /* ADC interrupt Deinit */
142 HAL_NVIC_DisableIRQ(ADC_IRQn);
143 /* USER CODE BEGIN ADC_MspDeInit 1 */
144
145 /* USER CODE END ADC_MspDeInit 1 */
146 }
147}
148
149/* USER CODE BEGIN 1 */
150
151/* USER CODE END 1 */
void HAL_ADC_MspDeInit(ADC_HandleTypeDef *adcHandle)
Definition adc.c:125
void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle)
Definition adc.c:84
void MX_ADC_Init(void)
Initialise the ADC peripheral (hadc) with settings generated by STM32CubeMX. Configures the ADC clock...
Definition adc.c:30
This file contains all the function prototypes for the adc.c file.
ADC_HandleTypeDef hadc
Definition adc.c:27
void Error_Handler(void)
Default error handler called by HAL on unrecoverable errors. Disables interrupts and enters an infini...
Definition main.c:505