7 years, 5 months ago.

PG_0 INTERRUPT IN

Hi all, I'm having same troubles with Interrupts with pin PG_0 on my NUCLEO-F767ZI board. I have all configured properly and other pins that I used for InterruptIn are all working as they should.

Snippet from my code:

InterruptIn  in0(PG_0);

int in0_ = 0;

void in0_change()
{
    in0_ = in0.read();
}

int main(){
   in0.mode(PullUp);
   in0.rise(&in0_change);
   in0.fall(&in0_change);

  while(1){
    //...code
  }
}

But if I do in0.read() it works just fine.

Why is then pin PG_0 special? Where can I find a list of pins that can be used as Interrupt input?

Thanks for the help.

Question relating to:

STM32 Nucleo-144 development board with STM32F767ZIT6 MCU, supports Arduino, ST Zio and morpho connectivity

2 Answers

7 years, 5 months ago.

Try changing it to

volatile int in0_ = 0;

Any variable which is changed in an interrupt and read in the main loop should be set to volatile. If you don't do this the compiler could make optimizations that result in you missing changes in value.

Accepted Answer
7 years, 5 months ago.

Don't you also need this?

in main.c before while(1)

  in0.enable_irq();