I'm using the MCU STM32F4 and I want to read the ADC inputs using Hal Library and show these on the Terminal. My ADCs inputs are running in continuous convertion mode and the convertion is called by tick of a Timer.
ADC_HandleTypeDef hadc1;
TIM_HandleTypeDef htim2;
char buffer[10];
uint32_t adc1, adc2, adc3;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
if(htim->Instance == TIM2)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,300);
adc1 = HAL_ADC_GetValue(&hadc1);
sprintf(buffer,"A1: %d ",(int)adc1);
CDC_Transmit_FS((uint8_t*)buffer,9);
HAL_ADC_PollForConversion(&hadc1,300);
adc2 = HAL_ADC_GetValue(&hadc1);
sprintf(buffer,"A2: %d ",(int)adc2);
CDC_Transmit_FS((uint8_t*)buffer,5);
HAL_ADC_Stop(&hadc1);
if(adc1 > 1000)
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);
}
else
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);
}
}
}
This code above works if I have a single channel to monitorate. But, if I use more than one channel, the output show only the channel 2 values, like the image shown below.
I dont know what is happening. Do can you help me?