cancel
Showing results for 
Search instead for 
Did you mean: 

How do I start the ADC channel switching

nm1120
Associate
Posted on December 12, 2015 at 23:28

Guys

I have included a copy of my sample test code, currently, when debugging, the only channel that is being read is ADC_CHANNEL_ I would appreciate any insight as to why the sequencer does not ''cycle'' through channels 10, 11, 12, 13 and repeat. I'm using the following: STM32CubeMX v4.12 STM32F446RET6 Keil uVision v5.15 Thank you!!!

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc1)
{
switch(sConfigADC.Channel)
{
case ADC_CHANNEL_10:
uhADC_ConvValue = HAL_ADC_GetValue(hadc1);
break;
case ADC_CHANNEL_11:
uhADC_ConvValue = HAL_ADC_GetValue(hadc1);
break;
case ADC_CHANNEL_12:
uhADC_ConvValue = HAL_ADC_GetValue(hadc1);
break;
case ADC_CHANNEL_13:
uhADC_ConvValue = HAL_ADC_GetValue(hadc1);
break;
}
}
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
while (1)
{
}
}
/* ADC1 init function */
void MX_ADC1_Init(void)
{
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV8;
hadc1.Init.Resolution = ADC_RESOLUTION12b;
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 4;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = DISABLE;
HAL_ADC_Init(&hadc1);
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
*/
sConfigADC.Channel = ADC_CHANNEL_10;
sConfigADC.Rank = 1;
sConfigADC.SamplingTime = ADC_SAMPLETIME_56CYCLES;
HAL_ADC_ConfigChannel(&hadc1, &sConfigADC);
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
*/
sConfigADC.Channel = ADC_CHANNEL_11;
sConfigADC.Rank = 2;
HAL_ADC_ConfigChannel(&hadc1, &sConfigADC);
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
*/
sConfigADC.Channel = ADC_CHANNEL_12;
sConfigADC.Rank = 3;
HAL_ADC_ConfigChannel(&hadc1, &sConfigADC);
/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
*/
sConfigADC.Channel = ADC_CHANNEL_13;
sConfigADC.Rank = 4;
HAL_ADC_ConfigChannel(&hadc1, &sConfigADC);
HAL_ADC_Start_IT(&hadc1);
}
/** Configure pins as 
* Analog 
* Input 
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{
/* GPIO Ports Clock Enable */
__GPIOH_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
}

0 REPLIES 0