2026-03-05 5:21 PM - last edited on 2026-03-06 1:15 AM by Gyessine
Hello,
I am experiencing a problem with ADC1 and ADC2. I configured them in Dual Regular Simultaneous Mode, where ADC1 acts as the master and ADC2 acts as the slave.
The ADC channel connections are as follows:
ADC1 Channel 1: 24V_Sense
ADC1 Channel 2: 5V_Sense
ADC2 Channel 14: IOut_Sense
ADC2 Channel Vrefint: Internal reference voltage
However, I noticed that IOut_Sense always has a value, while 24V_Sense is unstable and fluctuating.
OUTPUT:
V24:24011 mV | V5:3 mV | I:23653 mA
V24:8807 mV | V5:3 mV | I:8675 mA
V24:8726 mV | V5:1 mV | I:8675 mA
V24:8844 mV | V5:3 mV | I:8675 mA
V24:23767 mV | V5:1 mV | I:23528 mA
V24:23853 mV | V5:0 mV | I:23590 mA
V24:23727 mV | V5:0 mV | I:23435 mA
V24:23968 mV | V5:0 mV | I:23481 mA
V24:8832 mV | V5:3 mV | I:8675 mA
V24:23541 mV | V5:0 mV | I:23388 mA
uint32_t adc_dual_buffer[4];
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_USART1_UART_Init();
MX_I2C1_Init();
MX_DMA_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, &rxByte, 1);
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);
// 2️⃣ Start slave ADC first
HAL_ADC_Start(&hadc2);
// 3️⃣ Start dual mode DMA from master
HAL_ADCEx_MultiModeStart_DMA(&hadc1,
(uint32_t*)adc_dual_buffer,
4);
while (1)
{
Read_ADC_Values();
}
}
ADC configuration:
void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
ADC_MultiModeTypeDef multimode = {0};
__HAL_RCC_ADC12_CLK_ENABLE();
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.NbrOfConversion = 2;
hadc1.Init.DMAContinuousRequests = ENABLE;
HAL_ADC_Init(&hadc1);
// Rank 1 - Vout24V
sConfig.Channel = ADC_CHANNEL_1; // change to your real pin
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_601CYCLES_5;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
// Rank 2 - Vout5V
sConfig.Channel = ADC_CHANNEL_2; // change to your real pin
sConfig.Rank = ADC_REGULAR_RANK_2;
sConfig.SamplingTime = ADC_SAMPLETIME_601CYCLES_5;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
// MULTIMODE CONFIG
multimode.Mode = ADC_DUALMODE_REGSIMULT;
multimode.DMAAccessMode = ADC_DMAACCESSMODE_12_10_BITS;
multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_5CYCLES;
HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode);
}
void MX_ADC2_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
__HAL_RCC_SYSCFG_CLK_ENABLE();
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc2.Init.ContinuousConvMode = ENABLE;
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc2.Init.NbrOfConversion = 2;
HAL_ADC_Init(&hadc2);
// Rank 1 - Iout (CH14)
sConfig.Channel = ADC_CHANNEL_14;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_601CYCLES_5;
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
// Rank 2 - Vrefint
sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.Rank = ADC_REGULAR_RANK_2;
sConfig.SamplingTime = ADC_SAMPLETIME_601CYCLES_5; // VERY IMPORTANT
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
}
static void MX_DMA_Init(void)
{
__HAL_RCC_DMA1_CLK_ENABLE();
hdma_adc1.Instance = DMA1_Channel1;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_adc1.Init.Mode = DMA_CIRCULAR;
hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(&hadc1, DMA_Handle, hdma_adc1);
}
2026-03-09 3:09 AM
Hello,
@Jaybitbyte wrote:However, I noticed that IOut_Sense always has a value, while 24V_Sense is unstable and fluctuating.
OUTPUT:
V24:24011 mV | V5:3 mV | I:23653 mAV24:8807 mV | V5:3 mV | I:8675 mA
V24:8726 mV | V5:1 mV | I:8675 mA
V24:8844 mV | V5:3 mV | I:8675 mA
V24:23767 mV | V5:1 mV | I:23528 mA
V24:23853 mV | V5:0 mV | I:23590 mA
V24:23727 mV | V5:0 mV | I:23435 mA
V24:23968 mV | V5:0 mV | I:23481 mA
V24:8832 mV | V5:3 mV | I:8675 mA
V24:23541 mV | V5:0 mV | I:23388 mA
It could be something related to the 24V source you are measuring perhaps affected by a noise.
Add a capacitor at that 24V source output..
Check also with an oscilloscope if that source is stable and it is not fluctuating.
2026-03-10 6:56 PM
Hello,
The source 24V is stable it is an SMPS.
Thank you
2026-03-11 1:33 AM
SMPS is a bit noisy source due to the internal switching to regulate the voltage.
To confirm that, use a voltage source based on LDO.
2026-03-11 6:12 AM
Hello @Jaybitbyte
STM32F3 ADC can measure voltages in range [0; 3.3V], so I assume you have a resistive voltage ladder to divide 24V voltage.
If it is the case, resistances values must be selected:
- highest possible to reduce leakage in your application
- not too high: ADC input impedance has some constraints, refer to datasheet table "Maximum ADC RAIN" (highest impedance max with ADC kernel clock 72MHz and sampling time 601.5 clock cycles is order of 80kOhm).
Also, for hypothesis of noisy signal: a decoupling capacitor can be added on signal to ADC input.