cancel
Showing results for 
Search instead for 
Did you mean: 

How to measure VBAT, Tempsensor and VREFINT on STM32H753IIK?

MRex
Associate III

I have single channel ADC measurements on ADC1 and ADC2 working with an STM32H753IIK.

I need to measure VBAT, Tempsensor and VREFINT, which the source code says is ONLY on ADC3.

I generated the following init code:

void MX_ADC3_Init(void)
{
  ADC_ChannelConfTypeDef sConfig = {0};
 
  /**Common config
  */
 
 
  hadc3.Instance = ADC3;
  hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  hadc3.Init.Resolution = ADC_RESOLUTION_16B;
//  hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  //  hadc3.Init.EOCSelection =   ADC_EOC_SEQ_CONV;
  hadc3.Init.LowPowerAutoWait = DISABLE;
//  hadc3.Init.ContinuousConvMode = DISABLE;
  hadc3.Init.ContinuousConvMode = ENABLE;
  hadc3.Init.NbrOfConversion = 3;
  hadc3.Init.DiscontinuousConvMode = DISABLE;
  hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
  hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
//  hadc3.Init.BoostMode = DISABLE;
  hadc3.Init.OversamplingMode = DISABLE;
 
  if (HAL_ADC_Init(&hadc3) != HAL_OK)
  {
	  printf("\r\nADC3 Error_handler\r\n");
	  //Error_Handler();
  }
 
  /**Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_VBAT_DIV4;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
	  printf("\r\n* Channel Configuration Error *\r\n");
     //Error_Handler();
  }
 
  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
	  printf("\r\n* Channel Configuration Error *\r\n");
     //Error_Handler();
  }
 
 
  sConfig.Channel = ADC_CHANNEL_VREFINT;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
	  printf("\r\n* Channel Configuration Error *\r\n");
     //Error_Handler();
  }
 
 
}

The problem is, it fails the HAL_ADC_Init(&hadc3) call. When I look at that function, there is an internal error only when initing ADC3. In stm32h7xx_hal_adc.c:

  if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL) &&
      (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)  )

When I check hadc->State, it is the value of HAL_ADC_STATE_ERROR_INTERNAL (0x00000010) and then goes to an error handler.

Anyone know why ADC3 has an internal error right off the bat?

Thanks

1 REPLY 1
S.Ma
Principal

Looks like immature delivery.

First, check the official reference manual and datasheet to make sure what you want is there. Trust only these 2 documents.

If not there, game over

If there, then check which ADC and which channel has the feature.

Check if there is a ADC example in Cube library for Nucleo board of the STM32 you chose.

In the exemple, there should be one with what you want.

If not, dare to directly force register write even if HAL or LL or definitions of the HW registers for the STM32 is missing and give it a try.