This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

internal temperture sensor

I am trying to get the temperature from the internal temperature sensor in mcbstm32f400 having stm32f407ig. i read the manual too which i found where its configuration is mentioned but not in detail like the temperature sensor is connected to adc1 ch16 but how to enable ch16 is it connected to some gpio pin or directly connected internally to adc in that case we dont have to configure ports , how to give clock to it and what frequency of clock .Please provide some detailed guide or reference or example code(i dont want the whole code but some guidance)

  • None of this has anything to do with Keil - it is all ST-specific hardware details.

    Look to ST for examples of how to use their parts ...

    "how to enable ch16"

    Exactly the same as enabling any other channel?

  • Doesn't go to a pin, but you'll need to enable/turn-on the specific resource.
    Reading channel 16 not functionally different from channel 7, review examples, change the settings.

    STM32Cube_FW_F4_V1.19.0\Projects\STM32F4-Discovery\Examples\ADC\ADC_RegularConversion_DMA

    STM32Cube_FW_F4_V1.19.0\Projects\STM32F413H-Discovery\Applications\WIFI\WiFi_HTTP_Server\Src\main.c

    /**
      * @brief  Configure the ADC.
      * @param  None
      * @retval None
      */
    static uint32_t TEMP_SENSOR_Init(void)
    {
      ADC_ChannelConfTypeDef sConfig;
    
       /* ADC1 Periph clock enable */
      __HAL_RCC_ADC1_CLK_ENABLE();
    
      /* Configure the ADC peripheral */
      AdcHandle.Instance          = ADC1;
    
      AdcHandle.Init.ClockPrescaler        = ADC_CLOCKPRESCALER_PCLK_DIV4;
      AdcHandle.Init.Resolution            = ADC_RESOLUTION_12B;
      AdcHandle.Init.ScanConvMode          = DISABLE;                       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
      AdcHandle.Init.ContinuousConvMode    = ENABLE;                        /* Continuous mode enabled to have continuous conversion */
      AdcHandle.Init.DiscontinuousConvMode = DISABLE;                       /* Parameter discarded because sequencer is disabled */
      AdcHandle.Init.NbrOfDiscConversion   = 0;
      AdcHandle.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE;        /* Conversion start not trigged by an external event */
      AdcHandle.Init.ExternalTrigConv      = ADC_EXTERNALTRIGCONV_T1_CC1;
      AdcHandle.Init.DataAlign             = ADC_DATAALIGN_RIGHT;
      AdcHandle.Init.NbrOfConversion       = 1;
      AdcHandle.Init.DMAContinuousRequests = DISABLE;
      AdcHandle.Init.EOCSelection          = DISABLE;
    
      if (HAL_ADC_Init(&AdcHandle)== HAL_OK)
      {
        /* Configure ADC Temperature Sensor Channel */
        sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
        sConfig.Rank = 1;
        sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
        sConfig.Offset = 0;
    
        if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) == HAL_OK)
        {
          return 0;
        }
      }
      return 1;
    }
    
    
    /**
      * @brief  Get JunctionTemp level in 12 bits.
      * @retval JunctionTemp level(0..0xFFF) / 0xFFFFFFFF : Error
      */
    static uint32_t TEMP_SENSOR_GetValue(void)
    {
    
      if(HAL_ADC_Start(&AdcHandle) == HAL_OK)
      {
        if(HAL_ADC_PollForConversion(&AdcHandle, 1000)== HAL_OK)
        {
          return ((((HAL_ADC_GetValue(&AdcHandle) * VREF)/MAX_CONVERTED_VALUE) - VSENS_AT_AMBIENT_TEMP) * 10 / AVG_SLOPE) + AMBIENT_TEMP;
        }
      }
      return  0xFFFFFFFF;
    }