AnsweredAssumed Answered

[SOLVED] STM32F746 temperature sensor problem

Question asked by Quentin on Jun 27, 2016
Latest reply on Jun 29, 2016 by Quentin

I'm trying to get temperature from internal sensor of the STM32F746.
I'm a begineer and I'm working on a discovery kit directly on mbed.
Currently, the function HAL_ADC_PollForConversion return nothing, because of an infinite loop.
I don't understand why ... 

#include "mbed.h"
float temp = 0;
ADC_HandleTypeDef hadc1;
Serial pc(USBTX, USBRX); // tx, rx
void init(){
    ADC_ChannelConfTypeDef sConfig;
    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV8;
  hadc1.Init.Resolution = ADC_RESOLUTION12b;
  hadc1.Init.ScanConvMode = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.EOCSelection = EOC_SINGLE_CONV;
    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;  //ADC_Channel_TempSensor = ADC_Channel_18 on STM32f7xx*/
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_144CYCLES;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
  /* Then we enable the internal temperature sensor
     * Bit 23 TSVREFE: Temperature sensor and VREFINT enable
     * This bit is set and cleared by software to enable/disable the temperature sensor and the
   * VREFINT channel.*/
   ADC->CCR |= (uint32_t)ADC_CCR_TSVREFE;
  //The next statement enables ADC1
    pc.printf("Init done\n");
float getMCUTemperature() {
    float temp;
    HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
    temp = ((HAL_ADC_GetValue(&hadc1))/4095.0)*3300.0;
    temp = (temp - 760.0)/2.5;
    temp += 25.0;
    return temp;
int main() {
    while(1) {
        temp = getMCUTemperature();
        pc.printf("Temp = %f\n",temp);
        wait(1.0); // 1 sec

I can't use "ADC_TempSensorVrefintCmd()" ( undefined function), so, I put directly the TSVREFE bit myself.

Does anyone have the same problem ? 

Best regards,