Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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:
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.