cancel
Showing results for 
Search instead for 
Did you mean: 

read 8 channels from ADC2 in regular mode

ARost.2
Associate II

Hi,

While I can read one channel from both ADC1 & ADC3 in injected interrupt mode, till can not find a solution to read 8 channels from ADC2 in regular mode. Please send me sample code.

Thanks

5 REPLIES 5
ARost.2
Associate II

adc2 interrupt flag is activated

adc2 triggered by timer 3 rising edge

timer 3 work good

ARost.2
Associate II

...

//

HAL_ADC_Start(&hadc2);

//

while(1)

{

}

//

}

HAL_TIM_PeriodElapsedCallback{

if(htim->Instance == TIM3)

 {

how to code here ?

}

}

ARost.2
Associate II

/* ADC2 init function */

void MX_ADC2_Init(void)

{

 ADC_ChannelConfTypeDef sConfig = {0};

 /** Common config

 */

 hadc2.Instance = ADC2;

 hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV16;

 hadc2.Init.Resolution = ADC_RESOLUTION_12B;

 hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;

 hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc2.Init.LowPowerAutoWait = DISABLE;

 hadc2.Init.ContinuousConvMode = ENABLE;

 hadc2.Init.NbrOfConversion = 8;

 hadc2.Init.DiscontinuousConvMode = DISABLE;

 hadc2.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T3_TRGO;

 hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;

 hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;

 hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;

 hadc2.Init.OversamplingMode = DISABLE;

 if (HAL_ADC_Init(&hadc2) != HAL_OK)

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_3;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_4;

 sConfig.Rank = ADC_REGULAR_RANK_2;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_5;

 sConfig.Rank = ADC_REGULAR_RANK_3;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_7;

 sConfig.Rank = ADC_REGULAR_RANK_4;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_8;

 sConfig.Rank = ADC_REGULAR_RANK_5;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_9;

 sConfig.Rank = ADC_REGULAR_RANK_6;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_10;

 sConfig.Rank = ADC_REGULAR_RANK_7;

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

 {

   Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_11;

 sConfig.Rank = ADC_REGULAR_RANK_8;

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

 {

   Error_Handler();

 }

}

ARost.2
Associate II

how can I read 8 channels?

ARost.2
Associate II

please help anybody !