cancel
Showing results for 
Search instead for 
Did you mean: 

ADC multiple Channel issue

ekatpurerohan
Associate II

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.

13 REPLIES 13
ekatpurerohan
Associate II

Can you check, I have attached main.c and ioc file

> 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;

 

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

Above changes i was already doing but its not work.

 

Include your modified main.c file.

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

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]); }

 

Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.

What i include in my main.c file. I can't understand what you are saying.

I'm not sure I can help you further without seeing your current code. I do not want to play a guessing game.

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

Check this is my updated main.c file.

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.

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