2015-10-29 12:47 AM
Hi,
I am using STM32F051R8 eval board I am trying to read temperature sensor and internal voltage values but some times I am getting wrong ADC conversion valuesvoid MX_ADC_Init(void){ ADC_ChannelConfTypeDef sConfig; ADC_AnalogWDGConfTypeDef AnalogWDGConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc.Instance = ADC1; hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC; hadc.Init.Resolution = ADC_RESOLUTION12b; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; hadc.Init.EOCSelection = EOC_SINGLE_CONV; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerAutoPowerOff = DISABLE; hadc.Init.ContinuousConvMode = ENABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc.Init.DMAContinuousRequests = DISABLE; hadc.Init.Overrun = OVR_DATA_PRESERVED; HAL_ADC_Init(&hadc); /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; HAL_ADC_ConfigChannel(&hadc, &sConfig); /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_VREFINT; HAL_ADC_ConfigChannel(&hadc, &sConfig);}void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){ value++; if(value == 1) { buf[0] = HAL_ADC_GetValue(hadc); } else if(value == 2) { buf[1] = HAL_ADC_GetValue(hadc); value =0;}int32_t calTemperatureVal(void){ int32_t temperature; temperature = buf[0]; temperature = ((temperature* VDD_APPLI /VDD_CALIB) - (int32_t)*TEMP30_CAL_ADDR); temperature = temperature * (int32_t)(110 -30); temperature = temperature / ((int32_t)*TEMP110_CAL_ADDR - (int32_t)*TEMP30_CAL_ADDR); temperature = temperature +30; return temperature;} #stm32-stm32f0-adc