Skip to content

Commit

Permalink
fix adc
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Jul 17, 2024
1 parent 741f054 commit 6220fcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
26 changes: 12 additions & 14 deletions Core/Src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void MX_ADC1_Init(void)
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 4;
hadc1.Init.NbrOfConversion = 5;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
Expand Down Expand Up @@ -88,7 +88,7 @@ void MX_ADC1_Init(void)

/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = ADC_REGULAR_RANK_3;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Expand All @@ -97,12 +97,21 @@ void MX_ADC1_Init(void)

/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_REGULAR_RANK_4;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}

/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
sConfig.Rank = ADC_REGULAR_RANK_5;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */

/* USER CODE END ADC1_Init 2 */
Expand All @@ -113,22 +122,11 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{

GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */

/* USER CODE END ADC1_MspInit 0 */

/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}

/* ADC1 clock enable */
__HAL_RCC_ADC_CLK_ENABLE();

Expand Down
12 changes: 7 additions & 5 deletions project_v3.ioc
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#MicroXplorer Configuration settings - do not modify
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0
ADC1.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_1
ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_7
ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_TEMPSENSOR
ADC1.ChannelTS=ADC_CHANNEL_TEMPSENSOR
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,SamplingTimeCommon2,SamplingTimeCommon1,Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion,Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,NbrOfConversion,master,SelectedChannel,ChannelTS
ADC1.NbrOfConversion=4
ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_6
ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_7
ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_TEMPSENSOR
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,SamplingTimeCommon2,SamplingTimeCommon1,Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion,Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,NbrOfConversion,master,SelectedChannel,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion
ADC1.NbrOfConversion=5
ADC1.NbrOfConversionFlag=1
ADC1.Rank-0\#ChannelRegularConversion=1
ADC1.Rank-1\#ChannelRegularConversion=2
ADC1.Rank-2\#ChannelRegularConversion=3
ADC1.Rank-3\#ChannelRegularConversion=4
ADC1.Rank-4\#ChannelRegularConversion=5
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTime-1\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTime-3\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC1.SamplingTimeCommon1=ADC_SAMPLETIME_79CYCLES_5
ADC1.SamplingTimeCommon2=ADC_SAMPLETIME_79CYCLES_5
ADC1.SelectedChannel=ADC_CHANNEL_0|ADC_CHANNEL_1|ADC_CHANNEL_6|ADC_CHANNEL_7|ADC_CHANNEL_TEMPSENSOR
Expand Down

0 comments on commit 6220fcc

Please sign in to comment.