0
\$\begingroup\$

My code works fine without interrupt (I tried polling the ADC value) but when I enabled the interrupt, it didn't work - while debugging in Keil, it never reaches the ADC_IRQHandler(), Also I found that the EOC flag is always set(in the while loop)

This is my code:

#include "stm32f4xx.h"                  // Device header
volatile int16_t k=0;
int main()
{

RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOAEN ;
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;

GPIOA->MODER |= GPIO_MODER_MODE0; //analog input
GPIOA->PUPDR &=~ GPIO_PUPDR_PUPD0; 
GPIOD->MODER |= GPIO_MODER_MODE13_0;//ouput
GPIOD->MODER &=~ GPIO_MODER_MODE13_1;
GPIOD->OTYPER &=~ GPIO_OTYPER_OT13;
GPIOD->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR13_0 ;
GPIOD->PUPDR &=~ GPIO_PUPDR_PUPD13 ;
GPIOD->ODR &=~ GPIO_ODR_OD13;

ADC1->CR2 |= ADC_CR2_ADON | ADC_CR2_CONT;
ADC1->SMPR2 |= ADC_SMPR2_SMP0_1;
ADC1->SQR3 &=~ ADC_SQR3_SQ1_4; //CHANNEL 0 (PA0)
ADC1->CR1 |= ADC_CR1_EOCIE;
NVIC_EnableIRQ(ADC_IRQn);
NVIC_SetPriority(ADC_IRQn,0);
ADC1->CR2 |= ADC_CR2_SWSTART;

while(1)
{
}

}
void ADC_IRQHandler()
{
     k= ADC1->DR;
     if(k>2000)
     {
        GPIOD->ODR ^= GPIO_ODR_OD13;
     }
}
\$\endgroup\$
2
  • \$\begingroup\$ a guess: you yo need to set or clear an interrupt flag? do you need to associate ADC_IRQHandler with a specific interrupt? \$\endgroup\$ Commented Nov 23, 2018 at 23:44
  • \$\begingroup\$ I tried to clear the eoc flag but it didn't work. I want to run a simple adc interrupt \$\endgroup\$
    – Mourad
    Commented Nov 24, 2018 at 0:07

1 Answer 1

1
\$\begingroup\$

i must add this extern "C" because i'm in c++ not in c :

    extern "C" {
     void ADC_IRQHandler()
     {
           // do whatever
     }
    }

this is the complete answer :Bug in Keil ARM compiler with interrupt handlers and C++?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.