152 lines
4.3 KiB
C
152 lines
4.3 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file adc.c
|
|
* @brief This file provides code for the configuration
|
|
* of the ADC instances.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2025 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "adc.h"
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
ADC_HandleTypeDef hadc3;
|
|
|
|
/* ADC3 init function */
|
|
void MX_ADC3_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN ADC3_Init 0 */
|
|
|
|
/* USER CODE END ADC3_Init 0 */
|
|
|
|
ADC_ChannelConfTypeDef sConfig = {0};
|
|
ADC_InjectionConfTypeDef sConfigInjected = {0};
|
|
|
|
/* USER CODE BEGIN ADC3_Init 1 */
|
|
|
|
/* USER CODE END ADC3_Init 1 */
|
|
|
|
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
|
|
*/
|
|
hadc3.Instance = ADC3;
|
|
hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
|
|
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
|
|
hadc3.Init.ScanConvMode = DISABLE;
|
|
hadc3.Init.ContinuousConvMode = DISABLE;
|
|
hadc3.Init.DiscontinuousConvMode = DISABLE;
|
|
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
|
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
|
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
|
hadc3.Init.NbrOfConversion = 1;
|
|
hadc3.Init.DMAContinuousRequests = DISABLE;
|
|
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
|
if (HAL_ADC_Init(&hadc3) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
|
|
*/
|
|
sConfig.Channel = ADC_CHANNEL_4;
|
|
sConfig.Rank = 1;
|
|
sConfig.SamplingTime = ADC_SAMPLETIME_144CYCLES;
|
|
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time
|
|
*/
|
|
sConfigInjected.InjectedChannel = ADC_CHANNEL_4;
|
|
sConfigInjected.InjectedRank = 1;
|
|
sConfigInjected.InjectedNbrOfConversion = 1;
|
|
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_3CYCLES;
|
|
sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONVEDGE_NONE;
|
|
sConfigInjected.ExternalTrigInjecConv = ADC_INJECTED_SOFTWARE_START;
|
|
sConfigInjected.AutoInjectedConv = DISABLE;
|
|
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
|
sConfigInjected.InjectedOffset = 0;
|
|
if (HAL_ADCEx_InjectedConfigChannel(&hadc3, &sConfigInjected) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN ADC3_Init 2 */
|
|
|
|
/* USER CODE END ADC3_Init 2 */
|
|
|
|
}
|
|
|
|
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
if(adcHandle->Instance==ADC3)
|
|
{
|
|
/* USER CODE BEGIN ADC3_MspInit 0 */
|
|
|
|
/* USER CODE END ADC3_MspInit 0 */
|
|
/* ADC3 clock enable */
|
|
__HAL_RCC_ADC3_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
/**ADC3 GPIO Configuration
|
|
PF3 ------> ADC3_IN9
|
|
PF4 ------> ADC3_IN14
|
|
PF6 ------> ADC3_IN4
|
|
PF8 ------> ADC3_IN6
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_8;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN ADC3_MspInit 1 */
|
|
|
|
/* USER CODE END ADC3_MspInit 1 */
|
|
}
|
|
}
|
|
|
|
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
|
{
|
|
|
|
if(adcHandle->Instance==ADC3)
|
|
{
|
|
/* USER CODE BEGIN ADC3_MspDeInit 0 */
|
|
|
|
/* USER CODE END ADC3_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_ADC3_CLK_DISABLE();
|
|
|
|
/**ADC3 GPIO Configuration
|
|
PF3 ------> ADC3_IN9
|
|
PF4 ------> ADC3_IN14
|
|
PF6 ------> ADC3_IN4
|
|
PF8 ------> ADC3_IN6
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_8);
|
|
|
|
/* USER CODE BEGIN ADC3_MspDeInit 1 */
|
|
|
|
/* USER CODE END ADC3_MspDeInit 1 */
|
|
}
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|