From 6220fcc5ae47f6e13a39bfabf927bd94cb9c1fbd Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Wed, 17 Jul 2024 19:25:56 +0300 Subject: [PATCH] fix adc --- Core/Src/adc.c | 26 ++++++++++++-------------- project_v3.ioc | 12 +++++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Core/Src/adc.c b/Core/Src/adc.c index 5c5411b..372492e 100644 --- a/Core/Src/adc.c +++ b/Core/Src/adc.c @@ -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; @@ -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) { @@ -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 */ @@ -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(); diff --git a/project_v3.ioc b/project_v3.ioc index 7a8c3fc..1d2d446 100644 --- a/project_v3.ioc +++ b/project_v3.ioc @@ -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