0

I am using the STM32CubeMX to generate low level library for the adc. The code I am using so far works normally using the adc in polling mode. However, I would like to improve my program and call an interrupt service routine (ISR).

I am not exactly sure how to make the program go to the ISR. Currently I have tried to write my ISR code in the stm32l4xx_it.c file like so:

void ADC1_IRQHandler(void)
{
  /* USER CODE BEGIN ADC1_IRQn 0 */
    uint8_t i;
    if(LL_ADC_IsActiveFlag_EOC(ADC1))
    {
        adc_value[i] = LL_ADC_REG_ReadConversionData12(ADC1);
        i ++;
        LL_ADC_ClearFlag_EOC(ADC1);
    }
    else if(LL_ADC_IsActiveFlag_EOS(ADC1))
    {
        i = 0;
        LL_ADC_ClearFlag_EOS(ADC1);
    }
  /* USER CODE END ADC1_IRQn 0 */
  /* USER CODE BEGIN ADC1_IRQn 1 */
  /* USER CODE END ADC1_IRQn 1 */
}

However, the program never enters this routine. Is there anyone who has some experience with this? or maybe an example code using stm LL libraries?

Thanks in advance!

Dudo199
  • 11
  • 1

1 Answers1

0

You wrote some handler. But

  1. You need to configure ADC to trigger the interrupt when sequence, conversion or error occurs.

  2. You need to enable this interrupt in the NVIC controller.

Make sure that the handler name matches the weak one in your startup code (from the .s file)

0___________
  • 60,014
  • 4
  • 34
  • 74
  • I have ADC1 Global interrupt enabled on the STM32 Cube. I believe this should configure the adc to trigger the interrupt and is also automatically enabled in the NVIC controller. I am not sure exactly what you mean by the `.s` file. do you mean the `main.c` file? – Dudo199 Mar 16 '20 at 16:00
  • No - in the assembler startup code where the vector table is defined. "*`I believe this should configure`*" never believe cube or HAL. Always **check**. – 0___________ Mar 16 '20 at 16:09