cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MP157A M4, the result of ADC_1 always is odd value. (the DR LSB is '1' always.)

fctu
Associate II

Hi,

I'm porting ADC on M4, but some how the converting result is odd value always, seems the DR bit-0 is always '1'.

I tested it by VR, range from 0v to 3.3v, the ADC suppose to convert it from 0 to 255, but I don't know why, I just get odd value back, like 1, 3,5....197,199,201....255. No even number at all.

---------------------------------------------

H/W configuration:

ADC Input: ANA0

Vref+ = 3.3V

---------------------------------------------

Here are the ADC configuration...

int SensorAdc_Init(void)

{

  ADC_ChannelConfTypeDef  channel_cfg;

  hSensorAdc.Instance = ADC1;

  hSensorAdc.Init.ClockPrescaler    = ADC_CLOCK_SYNC_PCLK_DIV2;

  hSensorAdc.Init.Resolution      = ADC_RESOLUTION_8B;

  hSensorAdc.Init.ScanConvMode     = ADC_SCAN_DISABLE;       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */

  hSensorAdc.Init.EOCSelection     = ADC_EOC_SINGLE_CONV;

  hSensorAdc.Init.LowPowerAutoWait   = DISABLE;

  hSensorAdc.Init.ContinuousConvMode  = DISABLE;            /* Continuous mode disabled to have only 1 conversion at each conversion trig */

  hSensorAdc.Init.NbrOfConversion    = 1;               /* Parameter discarded because sequencer is disabled */

  hSensorAdc.Init.DiscontinuousConvMode = DISABLE;            /* Parameter discarded because sequencer is disabled */

  hSensorAdc.Init.NbrOfDiscConversion  = 1;               /* Parameter discarded because sequencer is disabled */

  hSensorAdc.Init.ExternalTrigConv   = ADC_SOFTWARE_START;       //ADC_EXTERNALTRIG_T2_TRGO;   /* Trig of conversion start done by external event */

  hSensorAdc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; //ADC_EXTERNALTRIGCONVEDGE_RISING; /* Parameter discarded because trig of conversion by software start (no external event) */

  hSensorAdc.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;

  hSensorAdc.Init.Overrun        = ADC_OVR_DATA_OVERWRITTEN;

  hSensorAdc.Init.OversamplingMode   = DISABLE;

  if (HAL_ADC_DeInit(&hSensorAdc) != HAL_OK){

    /* ADC Deinitialization error */

    Error_Handler();

    return -1;

  }

   

  if (HAL_ADC_Init(&hSensorAdc) != HAL_OK){

    /* ADC initialization error */

    Error_Handler();

    return -1;

  }

  channel_cfg.Channel   = ADC_CHANNEL_0;        /* ADC channel selection */

  channel_cfg.Rank     = ADC_REGULAR_RANK_1;     /* ADC group regular rank in which is mapped the selected ADC channel */

  channel_cfg.SamplingTime = ADC_SAMPLETIME_810CYCLES_5; /* ADC channel sampling time */

  channel_cfg.SingleDiff  = ADC_SINGLE_ENDED;      /* ADC channel differential mode */

  channel_cfg.OffsetNumber = ADC_OFFSET_NONE;       /* ADC channel affected to offset number */

  channel_cfg.Offset    = 0;              /* Parameter discarded because offset correction is disabled */

  if (HAL_ADC_ConfigChannel(&hSensorAdc, &channel_cfg) != HAL_OK)

  {

    /* Channel Configuration Error */

Error_Handler();

    return -1;

  }

  if (ret = HAL_ADC_Start_DMA(&hSensorAdc, (uint32_t *)AdcConvData, ADC_CONVERTED_DATA_BUFFER_SIZE) != HAL_OK){/* ADC conversion start error */

Error_Handler();

    return -1;

  }

   return 0;

}

----------------------------------------------

Please advise .

Many thanks.

FC

1 REPLY 1
PatrickF
ST Employee

Please check if your other platform settings are fulfilling the ADC characteristics of datasheet, especially ADC maximum operating frequency of 20MHz (or 36MHz with BOOST=1).0693W000004GgvbQAC.png

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.