AnsweredAssumed Answered

HAL_ADC_ConvCpltCallback triggers only once (STM32F103)

Question asked by danylchyk.nikolai on Mar 4, 2018
Latest reply on Mar 5, 2018 by William chang

Good afternoon ladies and gentlemen.

I've been trying to put analog read to work and been partially successful.

First of all I tried using CubeMX for generating most of the init code and in "manual pull mode" everything works fine:

...
HAL_ADC_Start(&hadc1);
...

  while (1)
  {
        if (HAL_ADC_PollForConversion(&hadc1, 10000) == HAL_OK)
        {
            ADC_val = HAL_ADC_GetValue(&hadc1);
        }
        ...

}

...

  hadc1.Init.ContinuousConvMode = ENABLE;

But I want to have this working via callback function that is described in many places. In CubeMX I set up pretty much everything I could find, especially inside NVIC -> ADC1 and ADC2 global interrupts. Got all the generated code and implemented weak methods as necessary

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
    ADC_val = HAL_ADC_GetValue(hadc);
}

// I'm not sure about this one cause I cannot see any override reference calls to this one! Something changed recently?
void ADC_IRQHandler()
{
    HAL_ADC_IRQHandler(&hadc1);
}

IRQs are set properly in the generated code:

static void MX_NVIC_Init(void)
{
  /* ADC1_2_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
}

Also I start ADC with suggested  HAL_ADC_Start_IT(&hadc1); call.

What happens is that the HAL_ADC_ConvCpltCallback is called only once, and not whenever I touch my rotation sensor. So it seems like IRQ handler is not properly registered but after several hours I cannot figure out what's up.

Anyone has suggestions?

 

P.S. For the sake of stupid test, I put the HAL_ADC_Start_IT(&hadc1); within the while loop and it started triggering every time, but this is of course stupid and shouldn't be like that. Full source of my main file can be seen here:

 

[C++] /** ************************************************************************* - Pastebin.com 

Outcomes