Solved
The sequence from the ADC_SQR3 register does not work.
My goal now is to understand how ADC works.
I know that with the HAL_ADC_Start_DMA function, I can easily read data from multiple pins.
Now I want to set up data transfer from pins in semi-automatic mode, without the HAL_ADC_Start_DMA function.
I know how to do it when sConfig.Rank == 1
My task is to transfer data from several pins when sConfig.Rank is greater than 1.
In Cube MX this parameter is called: Number of Conversion.
-----------------------------------------------
Scan Conversion Mode enabled.
In the while loop, I set up the sequence in the ADC_SQR3 register:
Channel Five, First Rank
sConfig.Channel = ADC_CHANNEL_5;
sConfig.Rank = 1;
Channel six, second rank
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = 2;
(The code is a little more complicated of course, I write the most important thing so as not to complicate.)
A sequence appears in the ADC_SQR3 register.
But when I then write HAL_ADC_PollForConversion(&hadc1, 1000);
That conversion occurs only for the first Rank, in this case for the fifth channel.
The second Rank is not converted. Why?

Full code:
static void MX_ADC1_Init(void)
{
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 3;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
}
void ADC_Select_CH0 (void)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_5;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
void ADC_Select_CH1 (void)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = 2;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
uint16_t a[10]={0};
while (1)
{
ADC_Select_CH5();
ADC_Select_CH6();
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 1000);
a[0] = HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
}

