Sterling
Sterling
DIIDevHeads IoT Integration Server
Created by Sterling on 8/23/2024 in #firmware-and-baremetal
What is the purpose of HAL_ADC_PollForConversion in STM32 HAL ADC code?
So I've been experimenting with the STM32 (F103RB) for a few weeks, but I'm unclear about the purpose of the HAL_ADC_PollForConversion function. It seems to have no effect on the ADC readings in my code. Here’s an example: The 1st (with PollForConversion):
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);

uint32_t value = HAL_ADC_GetValue(&hadc1);
float voltage = 3.3f * value / 4096.0f;

printf("ADC = %lu (%.3f V)\n", value, voltage); // send the value via UART
HAL_Delay(250);
}
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);

uint32_t value = HAL_ADC_GetValue(&hadc1);
float voltage = 3.3f * value / 4096.0f;

printf("ADC = %lu (%.3f V)\n", value, voltage); // send the value via UART
HAL_Delay(250);
}
Then the 2nd (without PollForConversion):
while (1)
{
HAL_ADC_Start(&hadc1);
//HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);

uint32_t value = HAL_ADC_GetValue(&hadc1);
float voltage = 3.3f * value / 4096.0f;

printf("ADC = %lu (%.3f V)\n", value, voltage); // send the value via UART
HAL_Delay(250);
}
while (1)
{
HAL_ADC_Start(&hadc1);
//HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);

uint32_t value = HAL_ADC_GetValue(&hadc1);
float voltage = 3.3f * value / 4096.0f;

printf("ADC = %lu (%.3f V)\n", value, voltage); // send the value via UART
HAL_Delay(250);
}
From what I can see, whether I include PollForConversion or not, the UART readings appear the same (although I’m not entirely sure if they truly are). Continuous mode is disabled. Could someone clarify what I might be missing?
2 replies