cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 - How to set Single-Ended Mode on an ADC Channel on STM32 using the HAL library?

David Smith
Associate II

Current settings seem to only produce 0x000 to 0x7FF . The HAL API on the STM32L0 only has 2 Parameters in the ADC ChannelConf Type:

typedef struct

{

 uint32_t Channel;   

 uint32_t Rank;         

}ADC_ChannelConfTypeDef;

Which is Clearly missing the : sConfig.SingleDiff = ADC_SINGLE_ENDED; feature....

Our current Settings:

static 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.OversamplingMode = DISABLE;

 hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;

 hadc.Init.Resolution = ADC_RESOLUTION_12B;

 hadc.Init.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

 hadc.Init.ScanConvMode = ENABLED;

 hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

 hadc.Init.ContinuousConvMode = ENABLED;

 hadc.Init.DiscontinuousConvMode = DISABLE;

 hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

   

 hadc.Init.DMAContinuousRequests = DISABLE;

  

 hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 hadc.Init.LowPowerAutoWait = ENABLE; // new..

 hadc.Init.LowPowerFrequencyMode = DISABLE;

 hadc.Init.LowPowerAutoPowerOff = DISABLE;

 if (HAL_ADC_Init(&hadc) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

// Had hoped THIS would work - but no

 if (HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED) != HAL_OK) {

   Error_Handler();

 }

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

   

 sConfig.Rank   = 1;

 sConfig.Channel = ADC_CHANNEL_8;

  

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

 {

  _Error_Handler(__FILE__, __LINE__);

 }

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

  */

 sConfig.Rank   = 2;

 sConfig.Channel = ADC_CHANNEL_9;

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

 {

  _Error_Handler(__FILE__, __LINE__);

 }

}

Anyone have some thoughts on this? Would REALLY like to get to 0x000 to 0xFFF

2 REPLIES 2
David Smith
Associate II

Anyone??

FMuel.2
Associate

Hi @Community member​ - could you solve the problem? I would higly appreciate a solution or advice to your problem since I have the same issue.