2019-02-21 07:02 PM
void ADC3_config(void)
{
AdcHandle.Instance = ADC3;
if (HAL_ADC_DeInit(&AdcHandle) != HAL_OK)
{
/* ADC de-initialization Error */
//Error_Handler();
}
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; /* Synchronous clock mode, input ADC clock divided by 4*/
AdcHandle.Init.Resolution = ADC_RESOLUTION_16B; /* 16-bit resolution for converted data */
AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode enabled (automatic conversion restart after each conversion) */
AdcHandle.Init.NbrOfConversion = 1; /* Parameter discarded because sequencer is disabled */
AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
AdcHandle.Init.NbrOfDiscConversion = 1; /* Parameter discarded because sequencer is disabled */
AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
AdcHandle.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR; /* DR register used as output (DMA mode disabled) */
AdcHandle.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; /* Left shift of final results */
AdcHandle.Init.BoostMode = ENABLE; /* Enable Boost mode as ADC clock frequency is bigger than 20 MHz */
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
AdcHandle.Init.OversamplingMode = DISABLE; /* Oversampling disable */
/* Initialize ADC peripheral according to the passed parameters */
if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
{
// Error_Handler();
}
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
//Error_Handler();
}
}
void ADC3_configChannel_TEMPSENSOR(void)
{
/* ### - 3 - Channel configuration ######################################## */
sConfig_ADC.Channel = ADC_CHANNEL_TEMPSENSOR; /* Sampled channel number */
sConfig_ADC.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
sConfig_ADC.SamplingTime = ADC_SAMPLETIME_810CYCLES_5; /* Sampling time (number of clock cycles unit) */
sConfig_ADC.SingleDiff = ADC_SINGLE_ENDED; /* Single input channel */
sConfig_ADC.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
sConfig_ADC.Offset = 0; /* Parameter discarded because offset correction is disabled */
sConfig_ADC.OffsetRightShift = DISABLE; /* No Right Offset Shift */
sConfig_ADC.OffsetSignedSaturation = DISABLE; /* No Signed Saturation */
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig_ADC) != HAL_OK)
{
//Error_Handler();
}
}
/* Read the converted value */
uwConvertedValue = HAL_ADC_GetValue(&AdcHandle);
TEMPVoltage = uwConvertedValue;
The TEMPVoltage is only 1400, but TS_CAL1 of the chip is 12275.
What's problem in my code?