AnsweredAssumed Answered

ADC DMA Continues Mode and enable/disable VBAT channel

Question asked by Jim on Dec 6, 2016
Latest reply on Dec 8, 2016 by Jeroen3

Hello, We are using STM32F072 series MCU with 8 physical ADC input channels and VBAT internal by configuring DMA with continues conversion mode:


/* ADC init function */ void MX_ADC_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc.Instance = ADC1; hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC; hadc.Init.Resolution = ADC_RESOLUTION10b; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; hadc.Init.EOCSelection = EOC_SINGLE_CONV; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerAutoPowerOff = DISABLE; hadc.Init.ContinuousConvMode = ENABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc.Init.DMAContinuousRequests = ENABLE; hadc.Init.Overrun = OVR_DATA_PRESERVED; HAL_ADC_Init(&hadc); //Configure for the selected ADC regular channel to be converted. //Vehicle BATT_VOLT_MON sConfig.Channel = ADC_CHANNEL_4; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_5; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_6; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_7; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_8; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_9; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_14; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_15; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_VBAT; //ADC_CHANNEL_18; HAL_ADC_ConfigChannel(&hadc, &sConfig); }


By enabling : 

HAL_ADC_Start_DMA(&hadc, (uint32_t*)&ADCRawReadValues,TOTAL_DMA_CONFIG_ADC_CHANNELS);


With this configuration, we are able to read all the configured channels without any issues and unit works perfectly.


As we learned, to save battery life at Internal VBAT ADC channels VABTE bit needs to control. In our case, reading VABT ADC not required continues scan mode. Planning to read this particular channel whenever user requested on demand and all other channels we would like to read DMA continues mode.


Is there a code example to enable and disable VBATE control line? Tried to enable and disable this particular channel through following code sample when user requested. But not suceeded:

  ADC->CCR &= (uint32_t)(~ADC_CCR_VBATEN);


Please help us on this.