cancel
Showing results for 
Search instead for 
Did you mean: 

Different results for ADC Bat. Measurement on STM32F105 and STM32F411

Haithem sunny
Associate II
Posted on April 11, 2018 at 00:18

Hi everybody, Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.  In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411. Below our configuration for ADC 'STM32F411': Results on the USART terminal:Hi everybody, Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.  In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411. Below our configuration for ADC 'STM32F411': Results on the USART terminal:Hi everybody, Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.  In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411. Below our configuration for ADC 'STM32F411': Results on the USART terminal:Hi everybody, Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.  In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411. Below our configuration for ADC 'STM32F411': Results on the USART terminal:Hi everybody, Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.  In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411. Below our configuration for ADC 'STM32F411': Results on the USART terminal:

void MX_ADC1_Init(void)

{

  ADC_ChannelConfTypeDef sConfig;

  hadc1.Instance = ADC1;

  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;

  hadc1.Init.Resolution = ADC_RESOLUTION_12B;

  hadc1.Init.ScanConvMode = DISABLE;

  hadc1.Init.ContinuousConvMode = ENABLE;

  hadc1.Init.DiscontinuousConvMode = ENABLE;

  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc1.Init.NbrOfConversion = 1;

  hadc1.Init.DMAContinuousRequests = DISABLE;

  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

  if (HAL_ADC_Init(&hadc1) != HAL_OK)

  {

    /* ADC initialization error */

    dlog(DDEBUG, 'Error on adc init\n');

    return;

  }

  sConfig.Channel = ADC_CHANNEL_14;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES/*ADC_SAMPLETIME_28CYCLES

  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

  {

    dlog(DDEBUG, 'Error on adc channel config\n');

   }

  sConfig.Channel = ADC_CHANNEL_VREFINT;

  sConfig.Rank = 2;

  sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;

  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

  {

    dlog(DDEBUG, 'Error on adc channel config\n');

   }

  if (HAL_ADC_Start_DMA(&hadc1,

                        (uint32_t *)aADCxConvertedValues,

                        ADCCONVERTEDVALUES_BUFFER_SIZE

                       ) != HAL_OK)

  {

    dlog(DDEBUG, 'Error on ADC DMA start\n');

  }

  MX_ADC1_GetValue();

 }Hi everybody, Our application measure VBAT voltage using ADC1 regular ADC_CHANNEL_14.  In fact, the ADC Bat. Measurement work fine on the STM32F105 but not on the STM32F411. Below our configuration for ADC 'STM32F411': Results on the USART terminal:

[ADC] Before: 0, Converted 0: 0

[ADC] Before: 0, Converted 1: 0

[ADC] u32ConvertedVal: 0

2 REPLIES 2
Posted on April 11, 2018 at 00:47

The code fragment won't compile and doesn't provide any output. Number of settings don't look right/workable.

If you have multiple channels wouldn't you have to get the ADC to scan them? Where are the data structures, or the code to printf() to the USART?

The thing with static code analysis is to show enough detail to be worth looking at.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Haithem sunny
Associate II
Posted on April 12, 2018 at 08:11

Thanks for your help.

Problem resolved by updating the settings of ADC.