cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 DISCOVERY INTERNAL TEMPERATURE

mertsamast2
Associate
Posted on November 08, 2016 at 06:45

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);
}

#!stm32-!adc #internal-temperature-sensor
3 REPLIES 3
slimen
Senior
Posted on November 08, 2016 at 10:00

Hello,

Your code is not visible.

The ''ADC_Temperature sensor'' example in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

may helps you, which is available at this path: STM32Cube_FW_F0_V1.6.0\Projects\STM32F072RB-Nucleo\Examples_LL\ADC\ADC_TemperatureSensor

You can compare the provided code there with your code to figure out what is missed there.

 

Regards

Walid FTITI_O
Senior II
Posted on November 08, 2016 at 10:16

Hi samast.mert, 

I recommend that you check the example ''ADC_TemperatureSensor'' done for the STM32F072RB'q NUCELO inside

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

at this path: STM32Cube_FW_F0_V1.6.0\Projects\STM32F072RB-Nucleo\Examples_LL\ADC\ADC_TemperatureSensor

-Hannibal-

mertsamast2
Associate
Posted on November 08, 2016 at 11:11

Hello again.

Thank you for your answers. I will try cubeF0.