Skip to main content
Visitor II
April 19, 2021
Question

STM32F7 ADC driver issue when changing channel from vbat to temp sensor.

  • April 19, 2021
  • 1 reply
  • 982 views

file - stm32f7xx_hal_adc.c

function - HAL_ADC_ConfigChannel

issue - The ADC_CHANNEL_VBAT and ADC_CHANNEL_TEMPSENSOR channels are shared so only one can be used at a time. If you want to use both, you will need to swap between the two. When swapping from VBAT to TS, the VBAT flag remains enabled in ADC->CCR causing ADC_CHANNEL_VREFINT to read unexpected values.

work around - when changing channels from vbat to the temp sensor, also clear:

CLEAR_BIT(ADC->CCR,ADC_CCR_VBATE);

suggested driver update -

if(sConfig->Channel == ADC_CHANNEL_TEMPSENSOR)
 {
 /* Ensure the vBat channel is disabled */
 CLEAR_BIT(ADC->CCR,ADC_CCR_VBATE);
 
 /* Delay for temperature sensor stabilization time */
 /* Compute number of CPU cycles to wait for */
 counter = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000));
 while(counter != 0)
 {
 counter--;
 }
 }

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    April 19, 2021

    Hi @HMcKi​ ,

    Your request is relevant as it is aligned with the description of TSVREF in the reference manual:

    Note: VBATE must be disabled when TSVREFE is set. If both bits are set, only the VBAT conversion is performed.

    I'll share it with development team in order to take care to provide a fix.

    However, I would like to understand more the issue reading ADC_CHANNEL_VREFINT: do you confirm that expected values are read when implementing the workaround you are suggesting?

    -Amel

    HMcKiAuthor
    Visitor II
    April 19, 2021

    Hi Amel,

    Thanks for the hasty reply.

    Confirmed.

    Cheers,

    Hamish.