2023-02-09 12:40 AM
Hi I created a very simple ADC polling project using Nucleo-U575ZI-Q board. The settings of CubeMX is attached below. The code is very simple, just start the ADC1 and wait for polling then read the result from ADC1_IN8. The ADC polling code in my own project is not working. But when putting the same code in the ST ADC example project, it can work. I assume some settings must be missed but I checked all the settings and functions used and they are the same for my project and example project. Can anyone figure out which key steps are missed? Thanks.
2023-02-09 12:57 AM
Check whether you may need some extra codes...
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the System Power */
SystemPower_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ICACHE_Init(); // check if needed
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
/* Initialize LED on board */
BSP_LED_Init(LED1);
/* Perform ADC calibration */
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
/* Calibration Error */
Error_Handler();
}
2023-02-09 08:33 PM
I don't think it needs extra code, as the code I run in my main.c is the same as the one in ST example project. When I debug I found my code is stuck in
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
So I guess there must be some settings wrong/missed in my project. But I cannot figure it out as I followed the exact steps for ADC polling project.
2023-02-10 09:25 AM
Is this not needed?
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
2023-02-11 01:45 AM
Yes, not needed. This is for accuracy. But for simple use of ADC, this is not necessary.
2023-02-11 07:52 AM
This is the only difference between all the examples and your code.
Maybe you try to add it.
All the examples have this code except yours.
Some examples are inside the MX_ADC_Init() ending user code section.
/* USER CODE BEGIN ADC4_Init 2 */
if (HAL_ADCEx_Calibration_Start(&hadc4, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END ADC4_Init 2 */
2023-02-14 06:28 PM
Yes, I know. But when I delete these lines of code the ADC can still work. So I assume the issue is not there.