stm32-h743zi nucleo-144 ADC

270 views Asked by At

i have a problem with getting value from ADC on the nucleo144 board. I connected a potentiometer to the pin A0, but the ADC is stuck in the HAL_PollForConversion function and returns 0 if the delay is set to less then HAL_MAX_DELAY.

enter image description here

Here is my code. What am I doing wrong?

while(1){
  HAL_ADC_Start(&hadc1); // start the adc

  HAL_ADC_PollForConversion(&hadc1, 100); // poll for conversion

  adc_val = HAL_ADC_GetValue(&hadc1); // get the adc value

  HAL_ADC_Stop(&hadc1); // stop adc

  buff_len = sprintf((char*)buff,"ADC: %d\n", adc_val);
  HAL_UART_Transmit(&huart3,buff, buff_len, HAL_MAX_DELAY);

  HAL_Delay (500); // wait for 500ms
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */}

ADC config: enter image description here

1

There are 1 answers

2
DaveR On

Can you provide the code of the MX_ADC1_Init() function?

I've had a similar behavior, this solved it for me:

In the MX_ADC1_Init() function, there was the line hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1 missing to set the adc clock. There was no option to select this setting in the .ioc file ;-/ Turns out that with the default value for hadc1.Init.ClockPrescaler in the HAL, the adc won't work (see: enter link description here).