2026-03-06 5:15 AM - last edited on 2026-03-09 3:35 AM by KDJEM.1
Hi! I'm using a STM32N657 Nucleo Board, and, considering the 1.8 V reference voltage for the ADC, the value returned by the ADC is half of what it should be. For example, for a 1,410 V value in the pin, the reading is 1742. Here is the initialization for reference:
static void MX_ADC2_Init(void)
{
/* USER CODE BEGIN ADC2_Init 0 */
/* USER CODE END ADC2_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
ADC_AnalogWDGConfTypeDef AnalogWDGConfig = {0};
/* USER CODE BEGIN ADC2_Init 1 */
/* USER CODE END ADC2_Init 1 */
/** Common config
*/
hadc2.Instance = ADC2;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.GainCompensation = 0;
hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc2.Init.LowPowerAutoWait = DISABLE;
hadc2.Init.ContinuousConvMode = DISABLE;
hadc2.Init.NbrOfConversion = 1;
hadc2.Init.DiscontinuousConvMode = DISABLE;
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc2.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_1499CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure the regular channel to be monitored by WatchDog 2 or 3
*/
AnalogWDGConfig.FilteringConfig = ADC_AWD_FILTERING_NONE;
if (HAL_ADC_AnalogWDGConfig(&hadc2, &AnalogWDGConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC2_Init 2 */
if (HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END ADC2_Init 2 */
}
Any ideas what can be happening? Thank you!
Solved! Go to Solution.
2026-03-06 5:32 AM
Hello @guillerminaborrazas
I understand that you are converting external voltage on PG15 (ADC2_INP7) using CN4 #A5 connector.
Refer to NUCLEO-N657X-0Q schematic in page 10 for Arduino connectors below:
https://www.st.com/resource/en/schematic_pack/mb1940-n657x0q-c02-schematic.pdf
There is an operational amplifier in follower mode U9B with divider resistor (ratio 0.54) between signal ARD_A5R to ARD_A5 (PG15). You can recompute it by firmware using the same ratio.
This is why you measure input voltage less than expected. The resistor divider is used to be able to measure external voltage up to 3.3V while all ADC inputs are only 1.8V tolerant on STM32N6.
I hope it answer to your question.
Best regards,
Romain,
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2026-03-06 5:32 AM
Hello @guillerminaborrazas
I understand that you are converting external voltage on PG15 (ADC2_INP7) using CN4 #A5 connector.
Refer to NUCLEO-N657X-0Q schematic in page 10 for Arduino connectors below:
https://www.st.com/resource/en/schematic_pack/mb1940-n657x0q-c02-schematic.pdf
There is an operational amplifier in follower mode U9B with divider resistor (ratio 0.54) between signal ARD_A5R to ARD_A5 (PG15). You can recompute it by firmware using the same ratio.
This is why you measure input voltage less than expected. The resistor divider is used to be able to measure external voltage up to 3.3V while all ADC inputs are only 1.8V tolerant on STM32N6.
I hope it answer to your question.
Best regards,
Romain,
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.