1
votes

I have an STM32F411VET and I want to have interrupt triggered after ADC conversion is finished. Documentation says following:

In Single conversion mode the ADC does one conversion. This mode is started with the CONT bit at 0 by either:

  • setting the SWSTART bit in the ADC_CR2 register (for a regular channel only) Once the conversion of the selected channel is complete:

If a regular channel was converted:

  • The converted data are stored into the 16-bit ADC_DR register
  • The EOC (end of conversion) flag is set
  • An interrupt is generated if the EOCIE bit is set

Then the ADC stops.

Thus, I have following code:

Enabling interrupts

SET_BIT(ADC1->CR1, ADC_CR1_EOCIE);      // enable interrupt generation
NVIC_EnableIRQ(ADC_IRQn);       // allow interrupt in NVIC
__enable_irq();     // change cpu flags to enable interrupts

Configuring ADC

void ConfigureADC()
{
    // PA1 - ADC_IN1
    SET_BIT(GPIOA->MODER, GPIO_MODER_MODE1_0 | GPIO_MODER_MODE1_1); 
    SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);      // enable ADC1 clock
    SET_BIT(ADC1->CR2, ADC_CR2_ADON);       // enable ADC1
    SET_BIT(ADC1->CR1, ADC_CR1_RES_1);      // 8-bit conversion
    SET_BIT(ADC->CCR, ADC_CCR_ADCPRE_0);    // prescaler - /4
    SET_BIT(ADC1->SQR3, 1);     // channel 1 (PA1)
    SET_BIT(ADC1->CR2, ADC_CR2_CONT);       // Continious mode
}

Interrupt handler

void ADC_IRQHandler()
{
    vConverted = true;
    CLEAR_BIT(ADC1->SR, ADC_SR_EOC);        // Software clears EOC flag
}

While in debug mode or reading directly from ADC1->DR register I get a fine result.

Thing that make me worry is that I cannot debug interrupt handler in uVision5 (IDE I'm using).

The problem is that interrupt handler is not being executed and I don't know how to debug it properly.


Thank everyone for help.

2
You should be able to debug the interrupt handler in uVision 5 without problem if it is occuring so I would be very concerned about that.Realtime Rik
@RealtimeRik I can't put a breakpoint on any line of the interrupt handlerhrust
You should be able to. Are you sure the handler you are trying to put the breakpoint in is actually included in the final build?. Normally when you can't do this the function is not actually in the the build. Try looking in the map file, you might find you only have the default handler.Realtime Rik
@RealtimeRik All three block of code presented in the question are part on main.c file, which is the only one file I've created. Thus, handler is right next to main function.hrust
Just a thought, but try declaring the function void ADC_IRQHandler( void ).Realtime Rik

2 Answers

2
votes

I should note that C++ is used and, because of that, compiled function names do not match with ones in code, thus they are not binded/replaced. The IRQ handler was not referenced and hence not included in the compiled code.

To make functions 'C' linked extern "C" should be used.

extern "C"
{
    void ADC_IRQHandler();
    // Other handlers
}

To get more information on extern "C" refer to that answer.

1
votes

Just check if you call SET_BIT(ADC1->CR1, ADC_CR1_EOCIE); after the ADC_Configure