cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030CC ADC reads 0

Jpj.1
Associate II

Hi,

I am using stm32f030 to read adc value(truestudio). ADC reads value on an interval of 10 minutes. It is observer that ADC reads value for first 5-6 times,and after that it reads 0v.The readings we get is also different from what is measured on adcpin. what may be the issue??

static void MX_ADC_Init(void)

{

/* USER CODE BEGIN ADC_Init 0 */

/* USER CODE END ADC_Init 0 */

ADC_ChannelConfTypeDef sConfig = {0};

/* USER CODE BEGIN ADC_Init 1 */

/* USER CODE END ADC_Init 1 */

/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc.Instance = ADC1;

hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;

hadc.Init.Resolution = ADC_RESOLUTION_12B;

hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

hadc.Init.LowPowerAutoWait = DISABLE;

hadc.Init.LowPowerAutoPowerOff = DISABLE;

hadc.Init.ContinuousConvMode = ENABLE;

hadc.Init.DiscontinuousConvMode = DISABLE;

hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

hadc.Init.DMAContinuousRequests = DISABLE;

hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

if (HAL_ADC_Init(&hadc) != HAL_OK)

{

Error_Handler();

}

/** Configure for the selected ADC regular channel to be converted.

*/

sConfig.Channel = ADC_CHANNEL_8;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

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

{

Error_Handler();

}

/* USER CODE BEGIN ADC_Init 2 */

/* USER CODE END ADC_Init 2 */

}

code for reading value:

while(1){

HAL_ADC_Start(&hadc);

HAL_ADC_PollForConversion(&hadc,100);

u16_adcVal = HAL_ADC_GetValue(&hadc);

HAL_ADC_Stop(&hadc);

}

This discussion is locked. Please start a new topic to ask your question.
5 REPLIES 5

Hello

> sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5

Try to increase the sample time.

Regards

Should I disable this or enable:

hadc.Init.ContinuousConvMode

Also sample time to ADC_SAMPLETIME_7CYCLES_5

Along with ADC I also use UART. A GSM module is connected to it. In an interval of 10 min, at 2 minute GSM is made off and at 8th minute GSM is turned on. ADC reads value on every 10th minute. it reads value for first 5 -6 cycle. after that it reads 0.

Ozone
Principal III

A sample time of 1,5 cycle is very short, for sure.

But it is not a reasonable explanation for the observed effect.

I strongly suspect there is something wrong in your code processing sample date, and not the ADC.

You can try data breakpoints in your debugger - if it supports it.

I.e. a conditional BP at a location, if a variable matches a certain condition (like being 0).

"I strongly suspect there is something wrong in your code processing sample date, and not the ADC." Sorry,I didnt get you

Ozone
Principal III

You probably have a bug elsewhere.

The ADC value gets overwritten during processing.