cancel
Showing results for 
Search instead for 
Did you mean: 

Multichannel conversion in Interrupt mode STM32G474

JPiet.3
Associate II

Hello,

I wan't to read out a few ADC Channels, timer based in single convertion mode as a sequence. From my perspective, it is correct configured with CubeMX (Ver 1.16.0). But the result is not as expected. From my perspective and when I compare it with the diagram from RM0440 pg. 640, if I have 4 ranks in my ADC configured, I expect in my code below, the variable for EOC is 4 times higher than the EOS conter. 

But both have the same value. I set also an GPIO, when the timer starts the ADC_IT. If conversion is finishedand the GPIO is pulled low, I see even two pulses, one from EOS, one from EOC. Can somebody explain, what happen here? My strategy was to count the index at each EOC trigger ad grab the ADC-Values, than reset the counter with EOS. 

My ADC1 configuration from CubeMX, you see below.

Before someone is suggesting, use the DMA, of course, it is working here. But I will do the same on STM32H745, and here the DMA is not working. Because of some reasons, I use the STM32G474 just es test environment.

 

Thanks for help in advance

 

 

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
	static __IO uint16_t cnt_adc1=0, cnt_adc2=0;
	if (hadc->Instance == ADC1)
	{
		ADC_FLAG++;
		if ( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS))
		{
			  HAL_GPIO_WritePin(ADC_INT_GPIO_Port, ADC_INT_Pin, GPIO_PIN_SET);
			myEOS_FLAG++;
			HAL_GPIO_WritePin(ADC_INT_GPIO_Port, ADC_INT_Pin, GPIO_PIN_RESET);
		}
		if ( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC))
		{
			HAL_GPIO_WritePin(ADC_INT_GPIO_Port, ADC_INT_Pin, GPIO_PIN_SET);
			myEOC_FLAG++;
			HAL_GPIO_WritePin(ADC_INT_GPIO_Port, ADC_INT_Pin, GPIO_PIN_RESET);
		}
		HAL_GPIO_WritePin(GPIOA, ADC_TEST_Pin, GPIO_PIN_RESET);
}
}

 

 

 

 hadc1.Instance = ADC1;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
 hadc1.Init.Resolution = ADC_RESOLUTION_12B;
 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
 hadc1.Init.GainCompensation = 0;
 hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
 hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
 hadc1.Init.LowPowerAutoWait = DISABLE;
 hadc1.Init.ContinuousConvMode = DISABLE;
 hadc1.Init.NbrOfConversion = 4;
 hadc1.Init.DiscontinuousConvMode = DISABLE;
 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 hadc1.Init.DMAContinuousRequests = DISABLE;
 hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
 hadc1.Init.OversamplingMode = DISABLE;

 

  

2 REPLIES 2
raptorhal2
Lead

Check register ADC_IER to determine if both EOCIE and EOSIE bits are set to ENABLE

I had written a short code snippet to read out my register during runtime. I added ADC2 here because I want to read out ADC-Values from 2 ADC. The initialitation is the same. Difference is just, ADC1 is started by the timer during the timer interrupt, ADC2 is direct coupled and triggered from timer event.

 

adc_result[0]= ADC1->IER;
HAL_ADC_Start_IT(&hadc1);
adc_result[1]= ADC1->IER;
adc_result[2]= ADC2->IER;

 

 

When I let run my code, this timer interrupt is triggered and I read the registers for ADC1 and ADC2. ADC2 is started before because of the different triggers. At this point, the EOSIE in set for both ADC.

When the interrupt triggers my ADC1_Interrupt callback-function, the EOSIE and EOCIE is zero, but the EOS and EOC-Flags are set to one, visible in my CubeIDE Debug environment. 

For ADC2, the EOSIE-Flag is one over the whole time. But the resulte is still the same, I have just one data event during the ADC-Cycle. 

JPiet3_0-1720441071308.png

I see also, the callback-function is never reached, rather from ADC1 nor from ADC2. 

HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc)

But as mentioned above, the EOS flag is raised.