cancel
Showing results for 
Search instead for 
Did you mean: 

ADC doesn't work

proyo
Associate II

Hi all, 

I have created a new project for the STM32U575RIT6 microcontroller using the attached .ioc file. On top of the auto-generated code, I have made the following modifications:

In main.c:

 

 

 

  while (1)
  {
	uint32_t bits = 0;
	uint16_t adc_value = 0;
	uint16_t n_samples = 50;
	do
	{
		// Start the conversion process
		HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
		HAL_ADC_Start(&hadc1);
		HAL_Delay(10);

		// Average value of nSamples
		if (HAL_ADC_PollForConversion(&hadc1, 5000) == HAL_OK)
		{
			adc_value = (uint16_t) HAL_ADC_GetValue(&hadc1);
			if (adc_value > 0)
			{
				bits += adc_value;
			}
		}
		}
	}while(bits == 0);
	HAL_Delay(1000);
}

 

 

In stm32u5xx_hal_msp.c:

 

 

void HAL_MspInit(void)
{

  /* USER CODE BEGIN MspInit 0 */

  /* USER CODE END MspInit 0 */

  __HAL_RCC_PWR_CLK_ENABLE();

  /* System interrupt init*/

  /* USER CODE BEGIN MspInit 1 */

  HAL_PWREx_EnableVddA();
  HAL_PWREx_EnableVddIO2();
  /* USER CODE END MspInit 1 */
}

 

 


However, the ADC always reads 0. I have verified the following:

  • ADC Configuration: The ADC is set up correctly, with the appropriate channel and reference voltage selected.
  • Pin Setup: The pin connected to the ADC channel is initialized as an analog input.
  • Input Signal: A valid analog signal is present at the ADC input pin (1.6V).

Has anyone experienced similar issues or have suggestions on how to resolve this? Any help or advice would be greatly appreciated.

Thank you in advance for your assistance.

1 REPLY 1
TDK
Guru

> Has anyone experienced similar issues or have suggestions on how to resolve this? 

You haven't actually described what your issue is. Only that it "doesn't work".

Calibration should only be called once.

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