cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable on-board temperature sensor on STM32G491

JBend.6
Associate III

On STM32G491 (and family) MCUs the on-board temperature sensor can be read by ADC1 or ADC5 to provide junction temperature.

RM0440 Rev 7 informs us:

In order to read the temperature sensor we must "wake" it from power-down mode by setting the VSENSESEL bit in the ADCx_CCR register. Two such registers exist which I assume to be: ADC12_CCR and ADC345_CCR.

I cannot find any documentation on how to do this and there does not seem to be any example projects.

How to enable this bit please?

2 REPLIES 2

ADC12_COMMON->CCR |= ADC_CCR_VSENSESEL;

ADC345_COMMON->CCR |= ADC_CCR_VSENSESEL;

JW

JBend.6
Associate III

That is what I thought, but no! My raw read values are still nonsense.

My ADC config code (from STM config tool)

static void MX_ADC5_Init(void)
{
 
  /* USER CODE BEGIN ADC5_Init 0 */
 
  /* USER CODE END ADC5_Init 0 */
 
  /* USER CODE BEGIN ADC5_Init 1 */
 
  /* USER CODE END ADC5_Init 1 */
 
  /** Common config
  */
  hadc5.Instance = ADC5;
  hadc5.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8;
  hadc5.Init.Resolution = ADC_RESOLUTION_12B;
  hadc5.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc5.Init.GainCompensation = 0;
  hadc5.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc5.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc5.Init.LowPowerAutoWait = DISABLE;
  hadc5.Init.ContinuousConvMode = DISABLE;
  hadc5.Init.NbrOfConversion = 1;
  hadc5.Init.DiscontinuousConvMode = DISABLE;
  hadc5.Init.DMAContinuousRequests = DISABLE;
  hadc5.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc5.Init.OversamplingMode = DISABLE;
  if (HAL_ADC_Init(&hadc5) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC5_Init 2 */
 
  /* USER CODE END ADC5_Init 2 */
 
}

This is how I trigger a read (every 1-second)

/* Trigger MCU Temp ADC read */
ADC345_COMMON->CCR |= ADC_CCR_VSENSESEL;
HAL_ADC_Start_IT(&hadc5);

Then I save the raw value in my IRQ handler

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc) {
	/* MCU temperature */
	TempValue = HAL_ADC_GetValue(&hadc5);
}

The resulting TempValue is either 0, 1 or 2.