STM327H753-Eval : Temperature Sensor Reading Issue
Hi All,
Recently, I tried to read temperature sensor from ADC. I setup using STM32CubeMx and below is generated code:
/* ADC3 init function */
void MX_ADC3_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Common config */ hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2; hadc3.Init.Resolution = ADC_RESOLUTION_16B; hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE; hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc3.Init.LowPowerAutoWait = DISABLE; hadc3.Init.ContinuousConvMode = DISABLE; hadc3.Init.NbrOfConversion = 1; hadc3.Init.DiscontinuousConvMode = DISABLE; hadc3.Init.NbrOfDiscConversion = 1; hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR; hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED; hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; hadc3.Init.BoostMode = ENABLE; hadc3.Init.OversamplingMode = DISABLE; if (HAL_ADC_Init(&hadc3) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } }I read the value like:
adcConVal = HAL_ADC_GetValue(&hadc3);
Fortunately, I got 'wrong value' (concluded after calculating temperature) then i changed
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; to
sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_5; and It worked but it raises two points
1) I generated the code using STM32CubeMx and it should work fine with default. There
is no option in STM32CubeMx to change Sampling Time.
2) Secondly, How did it work with new cycling time i.e. ADC_SAMPLETIME_64CYCLES_5 ? I could not reach
to exact reason so kindly help.
Regards,
Manish
#stm32h7 #adc-sampling-time #stm32h7-adc