cancel
Showing results for 
Search instead for 
Did you mean: 

How to use multiple ADC channels on STM32U575? I have always TIMEOUT error EDIT : Same error with the example "ADC_DifferentialMode"

CSou.1
Associate II

Hi,

I would like to use ADC1_IN5, ADC1_IN6 and ADC1_IN7 on my STM32U575. To init ADC1 I have:

hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  hadc1.Init.Resolution = ADC_RESOLUTION_8B;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
  hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
  hadc1.Init.OversamplingMode = DISABLE;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

After that, to have data for each channel I do this code (I only change sConfig.Channel) :

HAL_StatusTypeDef err;
 
	sConfig.Channel = ADC_CHANNEL_5;
	sConfig.Rank = ADC_REGULAR_RANK_1;
	sConfig.SamplingTime = ADC_SAMPLETIME_5CYCLE;
	sConfig.SingleDiff = ADC_SINGLE_ENDED;
	sConfig.OffsetNumber = ADC_OFFSET_NONE;
	sConfig.Offset = 0;
	sConfig.OffsetRightShift = DISABLE;
	sConfig.OffsetSignedSaturation = DISABLE;
	HAL_ADC_ConfigChannel(&hadc1, &sConfig);
 
	HAL_ADC_Start(&hadc1);
 
	if( (err = HAL_ADC_PollForConversion(&hadc1, 10)) == HAL_OK) {
		*data = HAL_ADC_GetValue(&hadc1);
	} else {
		// nothing to do
	}
 
	HAL_ADC_Stop(&hadc1);

But err is still HAL_TIMEOUT.

I used this method on a STM32L476 and it worked, so I don't understand why I have HAL_TIMEOUT with STM32U575.

EDIT : I have tested the example "ADC_DifferentialMode" and I have a TIMEOUT error in HAL_ADC_PollForConversion, when I place a breakpoint after the call of HAL_ADC_GetValue (in the while).

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

As you said the problem was in HAL_MspInit(). HAL_PWREx_EnableVddA() was missing, but also __HAL_RCC_PWR_CLK_ENABLE(). Now it works.

View solution in original post

5 REPLIES 5
Aime
ST Employee

Hello CSou.1

I will try to help on this issue.

First you should know that there are a lot of differences between the STM32L476 and the STM32U575 (drivers, IPs, etc..) so if your project run on the STM32L476 that's doesn't mean that it will also run the U5.

Are you using the DMA ? Because in the User Manual (UM2911, page 75) in the description of the HAL_ADC_PollForConversion() you can say that :

"This function cannot be used in a particular setup: ADC configured in DMA mode and polling for end of each conversion (ADC init parameter "EOCSelection" set to ADC_EOC_SINGLE_CONV). In this case, DMA resets the flag EOC and polling cannot be performed on each conversion. Nevertheless, polling can still be performed on the complete sequence (ADC init parameter "EOCSelection" set to ADC_EOC_SEQ_CONV)."

Can you increase your SamplingTime in the sConfig structure and your timeout parameter in HAL_ADC_PollForConversion() ?

BR,

AMVE.1

CSou.1
Associate II

Hello,

Thank you for your answer.

I don't use DMA, and I have already tested to increase the SamplingTime and the timeout parameter.

You can reproduce my problem with the example "ADC_DifferentielMode", puting a breakpoint on the call of Error_Handler() in if (HAL_ADC_PollForConversion(&hadc1, 2000) != HAL_OK) and run the programm with the debugger. Normaly you don't have problem.

Click on "suspend" then "resume", and the programm fall in the Error_Handler() because HAL_ADC_PollForConversion return a TIMEOUT.

while (1)
{
    if (HAL_ADC_PollForConversion(&hadc1, 2000) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Read the converted value */
    uhADCxConvertedData = HAL_ADC_GetValue(&hadc1);
 
    /* Computation of ADC conversions raw data to physical values             */
    /* using helper macro.                                                    */
    uhADCxConvertedData_Voltage_mVolt = __HAL_ADC_CALC_DATA_TO_VOLTAGE(hadc1.Instance, VDDA_APPLI, uhADCxConvertedData, \
    ADC_RESOLUTION_14B);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
}

I work with the NUCLEO_U575ZI-Q.

Regards

Nick van IJzendoorn
Associate III

You need to enable the analog power domain with the function: HAL_PWREx_EnableVddA()

I had the same problem and already requested ST to automatically call HAL_PWREx_EnableVddA() in the MSP init.

Hi,

I tested your solution but I still have TIMEOUT error.

Hi,

As you said the problem was in HAL_MspInit(). HAL_PWREx_EnableVddA() was missing, but also __HAL_RCC_PWR_CLK_ENABLE(). Now it works.