cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-H743ZI2 ADC Polling gives wrong result.

ABane.1
Associate II

Hello,

I am trying to read single ADC channel using NUCLEO-H743ZI2 board but the result is wrong. I have created a very simple project using CubeMX. Kept the default Clock setting. Enabled ADC3 CH0 (PC3_C Pint) in single ended mode polling. Enabled UART3 to print the message using on board VCP. But the adc return value is not correct. When i connect PC3 Pin to GND, value is around 4650-4750. I have tried many other combinations, but could not figure out what wrong i did. Can someone help me to solve ADC reading error. Initialization code is as bellow.

ADC Value Read :

uint16_t ADC_Raw;

 while (1)

 {

  //HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

HAL_ADC_Start (&hadc3);

HAL_ADC_PollForConversion (&hadc3, 100);

ADC_Raw = HAL_ADC_GetValue (&hadc3);

My_Printf("\r\n CH%d[%d] ",0,ADC_Raw);

HAL_ADC_Stop(&hadc3);

HAL_Delay(1000);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

System Clock Configuration :

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};

 /** Supply configuration update enable

 */

 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);

 /** Configure the main internal regulator output voltage

 */

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}

 /** Macro to configure the PLL clock source

 */

 __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSI);

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB buses clocks

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2

               |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;

 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

 {

  Error_Handler();

 }

 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_ADC;

 PeriphClkInitStruct.PLL2.PLL2M = 32;

 PeriphClkInitStruct.PLL2.PLL2N = 129;

 PeriphClkInitStruct.PLL2.PLL2P = 2;

 PeriphClkInitStruct.PLL2.PLL2Q = 2;

 PeriphClkInitStruct.PLL2.PLL2R = 2;

 PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_1;

 PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;

 PeriphClkInitStruct.PLL2.PLL2FRACN = 0;

 PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;

 PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

}

ADC Configuration :

static void MX_ADC3_Init(void)

{

 /* USER CODE BEGIN ADC3_Init 0 */

 /* USER CODE END ADC3_Init 0 */

 ADC_ChannelConfTypeDef sConfig = {0};

 /* USER CODE BEGIN ADC3_Init 1 */

 /* USER CODE END ADC3_Init 1 */

 /** Common config

 */

 hadc3.Instance = ADC3;

 hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV256;

 hadc3.Init.Resolution = ADC_RESOLUTION_16B;

 hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;

 hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc3.Init.LowPowerAutoWait = DISABLE;

 hadc3.Init.ContinuousConvMode = DISABLE;

 hadc3.Init.NbrOfConversion = 1;

 hadc3.Init.DiscontinuousConvMode = DISABLE;

 hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;

 hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;

 hadc3.Init.OversamplingMode = DISABLE;

 if (HAL_ADC_Init(&hadc3) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_0;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_5;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

 sConfig.OffsetSignedSaturation = DISABLE;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN ADC3_Init 2 */

 /* USER CODE END ADC3_Init 2 */

}

Regards,

Asish Banerjee

1 ACCEPTED SOLUTION

Accepted Solutions
ABane.1
Associate II

Dear All,

My problem solved. It was the resistance of ground wire which was causes problem. It took a bit long time to short out the problem as we was first time using STM32H7 MCU. Thanks TDK for your support.

Regards,

Asish Banerjee

View solution in original post

7 REPLIES 7
ABane.1
Associate II

Hello,

Can anyone help me in this issue? I got stuck as i am working on a project where i have to use 16 bit ADC. That is why i am trying with STM32H743ZI MCU and need to work fast for the prototype.

Regards,

Asish Banerjee

TDK
Guru

> Enabled ADC3 CH0 (PC3_C Pint)

ADC3_CH0 is on PC2, not PC3.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks TDK for your reply. Actually it is PC2 pin which i have used. By mistake i have mentioned PC3 here. Problem has not been shorted out yet. Is any other settings required to make it up?

Regards,

Asish Banerjee

ABane.1
Associate II

Can anyone share NUCLEO-H743ZI2 ADC working sample project for STM32CubeIDE?

Regards,

Asish Banerjee

TDK
Guru
ABane.1
Associate II

Dear TDK,

Thanks for the link. I have tried with that code also and result is if i connect PA6 pin to GND, adc value is around 1400-16000 and if i connect PA6 pin to 3.3V, adc value is around 30000-33000.

Regards,

Asish Banerjee

ABane.1
Associate II

Dear All,

My problem solved. It was the resistance of ground wire which was causes problem. It took a bit long time to short out the problem as we was first time using STM32H7 MCU. Thanks TDK for your support.

Regards,

Asish Banerjee