/\*\* \* @brief ADC MSP Initialization \* This function configures the hardware resources used in this example \* @param hadc: ADC handle pointer \* @retval None \*/ void HAL\_ADC\_MspInit(ADC_HandleTypeDef\* hadc) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(hadc->Instance==ADC1) { /\* USER CODE BEGIN ADC1\_MspInit 0 \*/
/\* USER CODE END ADC1\_MspInit 0 \*/ /\* Peripheral clock enable \*/ \_\_HAL\_RCC\_ADC1\_CLK\_ENABLE();
/\*\* \* @brief The application entry point. \* @retval int \*/ int main(void) { /\* USER CODE BEGIN 1 \*/ uint16_t AD_RES = 0; /\* USER CODE END 1 \*/
/\* Reset of all peripherals, Initializes the Flash interface and the Systick. \*/ HAL\_Init();
/\* USER CODE BEGIN Init \*/
/\* USER CODE END Init \*/
/\* Configure the system clock \*/ SystemClock\_Config();
/\* USER CODE BEGIN SysInit \*/
/\* USER CODE END SysInit \*/
/\* Initialize all configured peripherals \*/ MX\_GPIO\_Init(); MX\_ADC1\_Init(); MX\_TIM2\_Init(); /\* USER CODE BEGIN 2 \*/ HAL\_TIM\_PWM\_Start(&htim2, TIM_CHANNEL_1); // Calibrate The ADC On Power-Up For Better Accuracy HAL\_ADCEx\_Calibration\_Start(&hadc1); /\* USER CODE END 2 \*/
/\* Infinite loop \*/ /\* USER CODE BEGIN WHILE \*/ while (1) { /\* USER CODE END WHILE \*/
/\* USER CODE BEGIN 3 \*/ // Start ADC Conversion HAL\_ADC\_Start(&hadc1); // Poll ADC1 Perihperal & TimeOut = 1mSec HAL\_ADC\_PollForConversion(&hadc1, 1); // Read The ADC Conversion Result & Map It To PWM DutyCycle AD_RES = HAL\_ADC\_GetValue(&hadc1); TIM2->CCR1 = (AD_RES << 4); HAL\_Delay(1); } /\* USER CODE END 3 \*/ }