2019-01-23 4:12 AM
Dear ST Community Members,
I want to read a value from 2 ADC channels on STM32L031,
How can I do that using polling conversion ?
Thanks
2019-01-23 4:27 AM
Spin in a loop waiting for the content of the DMA buffer to change?
2019-01-23 4:34 AM
Thanks Clive for the answer,
My code already with poll conversion, how can I separate ADC_result from CH0 and CH3 ?
ADC_raw = HAL_ADC_GetValue(hadc); 
 
How can GetValue(hdc) CH0 and CH3 ?
 
currently I comment out one of the setting :
 
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 = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ContinuousConvMode = DISABLE;
  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 = DISABLE;
  hadc.Init.LowPowerFrequencyMode = DISABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  if (HAL_ADC_Init(&hadc) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure for the selected ADC regular channel to be converted. 
    */
 
	sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure for the selected ADC regular channel to be converted.*/ 
    
  //sConfig.Channel = ADC_CHANNEL_3; //comment out for reading only one ADC
 
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
}
 
on the callback :
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
  if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC)) 
    { 
			ADC_raw = HAL_ADC_GetValue(hadc); 
			
		//	HAL_GPIO_TogglePin(OUT1_GPIO_Port, OUT1_Pin);		
			
			if(Index < 100)
			{
			//	HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
				ADC_Cplt = 0;				
				Value[Index] = ADC_raw;
				Index++;
			}
				
			else
				{
					ADC_Cplt = 1;
				//	HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
				}    
		
			
    } 
}Any ideas ?
2019-01-23 4:36 AM
Try to follow the example projects from Cube. Then if you have questions, you can ask here.
Install STM32CubeMX, download and install the STM32L0 package from the there (Alt+U).
Open Help->Updater Settings (Alt+S). [Click Show More to see the whole post]
Press the Browse button next to Repository Folder box
For HAL example project, go to STM32Cube_FW_L0_V1.11.0/Projects/NUCLEO-L031K6/Examples/ADC/ADC_RegularConversion_Polling
For LL example project, go to STM32Cube_FW_L0_V1.11.0/Projects/NUCLEO-L073RZ/Examples_LL/ADC/ADC_SingleConversion_TriggerSW