AnsweredAssumed Answered

STM32F0 DISCOVERY INTERNAL TEMPERATURE

Question asked by samast.mert on Nov 8, 2016
Latest reply on Nov 8, 2016 by samast.mert
Hello everyone.
I would like to measure the temperature in my discovery kit but I couldn't. Can ou help me? I am using Keil uVision5 and here is my codes;
int main()
{
    ADC_InitTypeDef ADC_InitStructure;
 
 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    ADC_StartOfConversion(ADC1);
    ADC_DeInit(ADC1);
 
 
    ADC_StructInit(&ADC_InitStructure);
    ADC_InitStructure.ADC_Resolution                = ADC_Resolution_12b;
    ADC_InitStructure.ADC_ContinuousConvMode        = ENABLE;
    ADC_InitStructure.ADC_ExternalTrigConvEdge          = ADC_ExternalTrigConvEdge_None;
    ADC_InitStructure.ADC_DataAlign                     = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_ScanDirection                 = ADC_ScanDirection_Backward;
    ADC_Init(ADC1, &ADC_InitStructure);
     
    ADC_TempSensorCmd(ENABLE);
    ADC_ChannelConfig(ADC1, ADC_Channel_16, ADC_SampleTime_239_5Cycles);
     
    ADC_GetCalibrationFactor(ADC1);
    ADC_Cmd(ADC1, ENABLE);
     
     
             
     
    uint16_t ts_cal1, ts_cal2, ts_data, ts_data_norm, vrefint_cal, vrefint_data;
    float a, temperature, vdda, temperature_norm;
    ts_cal1              = *((uint16_t*) ((uint32_t)0x1FFFF7B8));
    ts_cal2              = *((uint16_t*) ((uint32_t)0x1FFFF7C2));
    vrefint_cal              = *((uint16_t*)((uint32_t)0x1FFFF7BA));
         
     
         
    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)
    {      
     
    ts_data                      = ADC1->DR;
    vrefint_data                 = ADC1->DR;
    vdda                         = 3.3 * ( vrefint_cal / vrefint_data);
    ts_data_norm                 = ts_data * vdda / 3.3;
    a                            = (((double)(80)/(ts_cal2-ts_cal1)) * (ts_data-ts_cal1)+30 );
    temperature                  = ((float) a / 2.7713)*10;
    temperature_norm             = (((double)((110-30)/(ts_cal2-ts_cal1)) * (ts_data_norm-ts_cal1)+30 ));
    ADC_GetConversionValue(ADC1);
    //return (temperature);
    }

Outcomes