cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L011K4 ADC input never reach 0. Always ADC_GetValue=64 or more

SSerr.1
Associate

Hi community I'm using Nucleo-L011K4 board ADC to read analog level. Adjusting analog input to any value different that 0 works flawlessly but when I adjust input level to something <50mV ADC_GetValue return a digital value of 64 even if I wire ADC input directly to GND.

I've test different boards with same result, I'm supossing that it's something wrong in my code.

Are you so kind to let me know where is the problem?

HAL_ADC_Start(&hadc);                                        /* start ADC conversion */
  /* USER CODE END 2 */
 
 
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
 
 
	     if (HAL_ADC_PollForConversion(&hadc, 10000) == HAL_OK) {     /* wait for the conversion to be done and get data */
	       uint32_t adc_val = HAL_ADC_GetValue(&hadc);                         /* get the value */
// adc_val >= 64 always!
	       __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_EOC);
 	     }
  }
 
...
 
 
static void MX_ADC_Init(void)
{
 
  /* USER CODE BEGIN ADC_Init 0 */
 
  /* USER CODE END ADC_Init 0 */
 
  ADC_ChannelConfTypeDef sConfig = {0};
 
  /* USER CODE BEGIN ADC_Init 1 */
 
  /* USER CODE END ADC_Init 1 */
  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
  */
  hadc.Instance = ADC1;
  hadc.Init.OversamplingMode = DISABLE;
  hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV64;
  hadc.Init.Resolution = ADC_RESOLUTION_12B;
  hadc.Init.SamplingTime = ADC_SAMPLETIME_12CYCLES_5;
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ContinuousConvMode = ENABLE;
  hadc.Init.DiscontinuousConvMode = DISABLE;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc.Init.DMAContinuousRequests = DISABLE;
  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  hadc.Init.LowPowerAutoWait = DISABLE;
  hadc.Init.LowPowerFrequencyMode = DISABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  if (HAL_ADC_Init(&hadc) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel to be converted. 
  */
  sConfig.Channel = ADC_CHANNEL_4;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC_Init 2 */
 
  /* USER CODE END ADC_Init 2 */
 
}

1 ACCEPTED SOLUTION

Accepted Solutions

Did you perform calibration as outlined in the ADC chapter of RM?

JW

View solution in original post

2 REPLIES 2

Did you perform calibration as outlined in the ADC chapter of RM?

JW

SSerr.1
Associate

Thank JW, it fix the issue.

I'm affraid that I've been overconfidence in this case :ghost: