cancel
Showing results for 
Search instead for 
Did you mean: 

Internal analogs not working on NUCLEO-F303RE (STM32F303RET6)

diego ambroggi
Associate III

Hello Everyone 😊

I'm trying to evaluate this microcontroller since some days. The goal is to use it into an embedded solution for data acquisition.

Is important to read microcontroller temperature and internal reference to improve precision.

I've successfully read analogs input into polling mode or interrupt mode (with or without DMA).

Unfortunately, in any case, I can't read Internal analogs (VrefInt and Temperature sensor).

Some tips for me.

Thanks in advance

Diego

4 REPLIES 4

From RM0316:

Note: To convert one of the internal analog channels, the corresponding analog sources must first

be enabled by programming bits VREFEN, TSEN or VBATEN in the ADCx_CCR registers.

I don't Cube.

JW

JThev
Associate II

I think the Cube/HAL library should program those bits as long as you select the corresponding ADC channel.

In ainterrupt mode, the callback (HAL_ADC_ConvCpltCallback) should be triggered once per channel, in the order of their rank. Then you only have to keep track of which channel is triggering it and read the value with the HAL_ADC_GetValue (hadc) function.

Hope this hleps

Julien

diego ambroggi
Associate III

Hi waclawek.jan

I checked these bits are already setted by CubeMX generated code in "stm32f3xx_hal_adc_ex.c" file.

Not working anyway

:loudly_crying_face:

   /* If the requested internal measurement path has already been enabled,  */

   /* bypass the configuration processing.                                  */

   if (( (sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) &&

         (HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_TSEN))           ) ||

       ( (sConfig->Channel == ADC_CHANNEL_VBAT)      &&

         (HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_VBATEN))         ) ||

       ( (sConfig->Channel == ADC_CHANNEL_VREFINT)   &&

         (HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_VREFEN)))

      )

   {

     /* Configuration of common ADC parameters (continuation)               */

     /* Set handle of the other ADC sharing the same common register        */

     ADC_COMMON_ADC_OTHER(hadc, &tmphadcSharingSameCommonRegister);

     /* Software is allowed to change common parameters only when all ADCs  */

     /* of the common group are disabled.                                   */

     if ((ADC_IS_ENABLE(hadc) == RESET)                                   &&

         ( (tmphadcSharingSameCommonRegister.Instance == NULL)        ||

           (ADC_IS_ENABLE(&tmphadcSharingSameCommonRegister) == RESET)  )  )

     {

       /* If Channel_16 is selected, enable Temp. sensor measurement path   */

       /* Note: Temp. sensor internal channels available on ADC1 only       */

       if ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && (hadc->Instance == ADC1))

       {

         SET_BIT(tmpADC_Common->CCR, ADC_CCR_TSEN);

         /* Delay for temperature sensor stabilization time */

         /* Compute number of CPU cycles to wait for */

         wait_loop_index = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000U));

         while(wait_loop_index != 0U)

         {

           wait_loop_index--;

         }

       }

       /* If Channel_17 is selected, enable VBAT measurement path           */

       /* Note: VBAT internal channels available on ADC1 only               */

       else if ((sConfig->Channel == ADC_CHANNEL_VBAT) && (hadc->Instance == ADC1))

       {

         SET_BIT(tmpADC_Common->CCR, ADC_CCR_VBATEN);

       }

       /* If Channel_18 is selected, enable VREFINT measurement path        */

       /* Note: VrefInt internal channels available on all ADCs, but only   */

       /*      one ADC is allowed to be connected to VrefInt at the same   */

       /*      time.                                                       */

       else if (sConfig->Channel == ADC_CHANNEL_VREFINT)

       {

         SET_BIT(tmpADC_Common->CCR, ADC_CCR_VREFEN);

       }

     }

Thanks

Diego

diego ambroggi
Associate III

Hi julien1.536826307249236E12

Yes i did but not working :(

Thanks

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){

   if (hadc->Instance == ADC1){

      //end of conversion

      if (__HAL_ADC_GET_FLAG(&hadc1, ADC_FLAG_EOC)){

         /* Get ADC1 converted data */

         ADC1ConvertedValue[ADCIndex] = HAL_ADC_GetValue(&hadc1);

         ADCIndex++;

      }

      //end of sequence, restarting

      if (__HAL_ADC_GET_FLAG(&hadc1, ADC_FLAG_EOS)){

         ADCIndex = 0;

      }

   }

}