2024-10-01 2:58 AM
I have issue for ADC multiple channel not working. I am using nucleo-H503RB board. I am select ADC1 of IN0,IN1,IN3,IN5,IN14,IN19. But its read value only IN0.
2024-10-01 3:01 AM
2024-10-01 5:52 AM
> hadc1.Init.NbrOfConversion = 6;
Se up the ADC to convert only a single channel, not all 6.
Before conversion, set the channel in rank 1 to what you want it to be. Only change the channel number here.
  sConfig.Channel = ADC_CHANNEL_0;  // <-- only change this each iteration
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
2024-10-01 6:22 AM
Above changes i was already doing but its not work.
2024-10-01 7:44 AM
Include your modified main.c file.
2024-10-01 8:54 AM
You are calling this function in main while loop, passing adc_readings argument.
while (1)
  {
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
	  // Call the function to read ADC values and store them in adc_readings
	  	  ADC_Read_Value(adc_readings);   			// Now adc_readings contains the values for channels 0, 1, 3, 5, 14, and 19
  }
But your function doesn't accept an argument. Not sure how it even compiled without errors?
void ADC_Read_Value()
{
	// Read ADC values for each specified channel
	        for (uint32_t i = 0; i < sizeof(adc_channels) / sizeof(adc_channels[0]); i++)
	        {
	            // Configure the current channel
	            ADC_ChannelConfTypeDef sConfig = {0};
	            sConfig.Channel = adc_channels[i]; // Use the channel from the array
	            sConfig.Rank = 1; // Only one conversion at a time
//	            sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; // Adjust as needed
	            HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	            // Start ADC conversion
	           	 HAL_ADC_Start(&hadc1);
	            // Poll for the conversion to complete
	            HAL_ADC_PollForConversion(&hadc1, 1000);
	            // Get the ADC value
	            adc_values[i] = HAL_ADC_GetValue(&hadc1);
	            ADCdataToSend[i]= adc_values[i];
	            printf("ADC Channel = %d ADC = %lu\n",i,ADCdataToSend[i]);
	            // Stop ADC to save power
	            HAL_ADC_Stop(&hadc1);
	            HAL_Delay(1000);
	        }
//	        printf("ADC = %lu  %lu  %lu  %lu  %lu  %lu\n",ADCdataToSend[0],ADCdataToSend[1],ADCdataToSend[2],ADCdataToSend[3],ADCdataToSend[4],ADCdataToSend[5]);
}
2024-10-03 12:07 AM
What i include in my main.c file. I can't understand what you are saying.
2024-10-03 5:23 AM - edited 2024-10-03 5:27 AM
I'm not sure I can help you further without seeing your current code. I do not want to play a guessing game.
2024-10-03 5:38 AM
2024-10-03 5:51 AM
It looks like you still have the ADC configured to convert all 6 channels during setup. Change it to a single channel.
It looks like you're still not using the correct format to initialize each channel in the loop. A rank of "1" is not valid. It should be ADC_REGULAR_RANK_1.