cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l053 adc multiple channel without DMA

LRPS_92
Associate II
Posted on September 05, 2017 at 14:24

Hi,

                I'm trying to read 2 number of ADC channels on stm32l053 without DMA by initializing channel 1, reading  & deinitializing channel 1 then 

initializing channel 2, reading  & deinitializing channel 2.

I can read ADC count, but both the values are similar.

Is there any way i can use ranks (like it is used in stm32f0's) in stm32l053 to convert multiple channels without using DMA?? & I've posted my init, deinit codes for your consideration, if anything i was missing please suggest me the way out.

Thanks in advance.

/* ADC init function */

void MX_ADC_Init(int ch)

{

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_CLOCKPRESCALER_PCLK_DIV1;

hadc.Init.Resolution = ADC_RESOLUTION12b;

hadc.Init.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

hadc.Init.ScanDirection = ADC_SCAN_DIRECTION_UPWARD;

hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc.Init.ContinuousConvMode = DISABLE;

hadc.Init.DiscontinuousConvMode = DISABLE;

hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE;

hadc.Init.DMAContinuousRequests = DISABLE;

hadc.Init.EOCSelection = EOC_SINGLE_CONV;

hadc.Init.Overrun = OVR_DATA_PRESERVED;

hadc.Init.LowPowerAutoWait = DISABLE;

hadc.Init.LowPowerFrequencyMode = DISABLE;

hadc.Init.LowPowerAutoOff = DISABLE;

HAL_ADC_Init(&hadc);

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

*/

if( ch == 0 ){

sConfig.Channel = ADC_CHANNEL_0;

}else if ( ch == 1){

sConfig.Channel = ADC_CHANNEL_1;

}

HAL_ADC_ConfigChannel(&hadc, &sConfig);

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

{

/* Calibration Error */

// Error_Handler();

}

}

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)

{

GPIO_InitTypeDef GPIO_InitStruct;

__GPIOA_CLK_ENABLE();

__ADC1_CLK_ENABLE();

GPIO_InitStruct.Pin = GPIO_PIN_1;

GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_0;

GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)

{

/* USER CODE BEGIN ADC1_MspDeInit 0 */

HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0);

HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1);

__ADC1_CLK_DISABLE();

__GPIOA_CLK_DISABLE();

/* USER CODE BEGIN ADC1_MspDeInit 1 */

/* USER CODE END ADC1_MspDeInit 1 */

}

#stm32l053 #adc
0 REPLIES 0