2

I'm currently using the STM32F1xx boards from http://dan.drown.org/stm32duino/package_STM32duino_index.json To program my blue pill but I can’t find how to write the interrupt for the ADC. I’ve set the registers to output an interrupt when it finishes but I can’t find how to write the code for the interrupt.

I’ve tried the ”ISR(ADC_vect)” function which works for arduino, but the compiler is complaining that ”ISR” is not recognized. I’ve tried to look for the documentation for the STM32duino, but the little I could find didn’t even mention the ADC or any interrupt routines. I’ve searched though the STM32duino forum without any luck. If anyone knows how to solve this or where to find information about interrupt code for the STM32 boards I would be very happy :)

3 Answers3

1

I couldn't find the function being called directly, but there's a good example explaining how to attach interrupts to the ADC which works well: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/libraries/STM32ADC/examples/SingleConversionInterrupt/SingleConversionInterrupt.ino

If anyone knows the actual function being called directly that would be great to add on here, but until then this example does what I need and will hopefully help others having the same problem.

1

As you already found, the function to override is __irq_adc() defined weakly here and bound to the interrupt vector table here.

If you've defined it and it's not working, it's probably because you got rid of the attachInterrupt() call entirely, which does more than just assign an interrupt handler; it also enables the interrupt for that ADC. So:

myADC.calibrate();
myADC.setSampleRate(ADC_SMPR_1_5);
adc_enable_irq(ADC1, ADC_EOC);
myADC.setPins(&pin, 1);

extern "C" void __irq_adc() { // handle the interrupt // make sure to check statuses and clear flags as shown in the default handler }

Not sure if the extern "C" will be needed, probably will be, you'll have to check and find out.

SoreDakeNoKoto
  • 2,422
  • 2
  • 14
  • 23
0

first you need to enable the interrupt (I don't know if the stm32 wrapper for arduino does it or not):

NVIC_EnableIRQ(ADC1_IRQn);

then you have to write ISR as gerben said:

extern "C" void ADC1_IRQHandler()
{
    //clear ADC flag
}

extern "C" because [as far as I know] the arduino projects are C++.