2016-11-07 09:45 PM
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
2016-11-08 01:00 AM
Hello,
Your code is not visible.The ''ADC_Temperature sensor'' example in
may helps you, which is available at this path: STM32Cube_FW_F0_V1.6.0\Projects\STM32F072RB-Nucleo\Examples_LL\ADC\ADC_TemperatureSensorYou can compare the provided code there with your code to figure out what is missed there. Regards2016-11-08 01:16 AM
Hi samast.mert,
I recommend that you check the example ''ADC_TemperatureSensor'' done for the STM32F072RB'q NUCELO inside at this path: STM32Cube_FW_F0_V1.6.0\Projects\STM32F072RB-Nucleo\Examples_LL\ADC\ADC_TemperatureSensor-Hannibal-2016-11-08 02:11 AM
Hello again.
Thank you for your answers. I will try cubeF0.