2025-02-24 4:28 AM - edited 2025-02-24 4:49 AM
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:
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.
2025-02-24 6:17 AM
> 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.
2025-02-24 10:23 PM
Hello, thanks for your suggestion. As I mentioned in my original post, the issue is that the ADC value (adc_value) is always 0, even though there is a valid 1.6V analog signal at the input. I've tried calling the calibration function just once, but the result remains unchanged.
I don't really know why this is happening, so unfortunately I can't provide any more information. Any further ideas or suggestions on how to troubleshoot this behavior would be greatly appreciated. Thanks in advance for your help!
2025-02-25 6:08 AM
Code seems correct otherwise. If HAL_ADC_PollForConversion returns HAL_OK, the ADC is converting a voltage from somewhere.
Could be that the board is damaged, could be that your assumptions are incorrect. Set the pin as output and toggle and measure with a multimeter to verify connectivity.