Issues with more than 8 interrupt with arduino GIGA R1

Hi there!
I have a problem with interrupts on a Giga R1. I have written a program that controls relays, acquires data from various sensors, and uses interrupts to count pulses and increment the values of some variables.

// Configurazione interrupt

  attachInterrupt(digitalPinToInterrupt(contatore_1), conta_impulsi_1, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_2), conta_impulsi_2, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_3), conta_impulsi_3, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_4), conta_impulsi_4, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_5), conta_impulsi_5, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_6), conta_impulsi_6, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_7), conta_impulsi_7, RISING);
  attachInterrupt(digitalPinToInterrupt(contatore_8), conta_impulsi_8, RISING);
  Serial.print("uno");

   /*attachInterrupt(digitalPinToInterrupt(cont_EV_1), conta_impulsi_EV_1, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_2), conta_impulsi_EV_2, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_3), conta_impulsi_EV_3, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_4), conta_impulsi_EV_4, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_5), conta_impulsi_EV_5, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_6), conta_impulsi_EV_6, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_7), conta_impulsi_EV_7, RISING);
  attachInterrupt(digitalPinToInterrupt(cont_EV_8), conta_impulsi_EV_8, RISING);
*/
Serial.print("due");
  pinMode(contatore_1, INPUT_PULLUP);
  pinMode(contatore_2, INPUT_PULLUP);
  pinMode(contatore_3, INPUT_PULLUP);
  pinMode(contatore_4, INPUT_PULLUP);
  pinMode(contatore_5, INPUT_PULLUP);
  pinMode(contatore_6, INPUT_PULLUP);
  pinMode(contatore_7, INPUT_PULLUP);
  pinMode(contatore_8, INPUT_PULLUP);

  pinMode(cont_EV_1, INPUT_PULLUP);
  pinMode(cont_EV_2, INPUT_PULLUP);
  pinMode(cont_EV_3, INPUT_PULLUP);
  pinMode(cont_EV_4, INPUT_PULLUP);
  pinMode(cont_EV_5, INPUT_PULLUP);
  pinMode(cont_EV_6, INPUT_PULLUP);
  pinMode(cont_EV_7, INPUT_PULLUP);
  pinMode(cont_EV_8, INPUT_PULLUP);
Serial.print("tre");
  connessione_al_server();

  reset_all();`

So far, I have used 8 pins with interrupts: PIN 40, 41, 42, 43, 48, 49, 50, 51. Now I need to use at least 4 more pins with interrupts. The problem is that as soon as I add even one new interrupt and upload the Arduino program, it freezes!
I have tried various pins, but it freezes every time. Any ideas?

Very basic question : shouldn't the pinMode() be set (and the pins Pulled Up) before attaching the interrupt ?

Any luck?

As for calling pinMode, I know some versions of the attachInterrupt I believe do it internally. Don't remember if it was the pin number version or the pin name version.

Hopefully at some point someone from Arduino and/or ones who use the STM32 boards a lot can give a better answer.

With my limited knowledge of these boards, I believe the pin change interrupts are handled by EXTI (chapter 21). I believe there are a limit of maybe 16 EXTI events.

Maybe the system has already used up some of them. Not sure of the best way to check.

It is sort of difficult to navigate to the underlying source code. I believe most of the interesting stuff is in the mbed-os stuff that comes in as a precompiled library.

Good luck.

1 Like

I discovered that if I use pins 1, 2, 3, 4, 6, 40, 41, 42, 43, 48, 49, 50, 51 together, Arduino doesn't crash! However, it's not true that all 57 digital pins can be used with interrupts....

1 Like

I am wondering :thinking: I am trying to remember if it was these boards or another I have played with over the last year or so, that Pin Interrupts are setup for Specific pins of a port.
That is there is one interrupt for pin 0 of all ports (PA0, PE0, PJ0...) and another for pin 1...

So if My Excel document is correct:

Arduino Pin Port/Pin
1 PA9
2 PA3
3 PA2
4 PJ8
6 PD13
40 PE6
41 PK7
42 PI15
43 PI10
48 PK0
49 PE4
50 PI11
51 PE5

They might all be unique. You have Port pins(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15)
So no 1, 12, 14.

So for Port pin 1 you might be able to use (10 - PK1, 27-Pj1, 66 PA1, 70-PI1...

But again could be a different board I am thinking about

I see some useful information here:

https://github.com/arduino/ArduinoCore-mbed/issues/789#issuecomment-1840246454

the Giga allows a maximum of 16 interrupts at the same time, and the coexistence is based on STM32 peculiar way of handling them (like, PA_0 will share the interrupt with PB_0 , PC_0 and so on). If you instantiate 2 interrupts on the same line the board will "crash" (report it as invaliud).
To associate pin name and pin number you can use this table ArduinoCore-mbed/variants/GIGA/variant.cpp at main · arduino/ArduinoCore-mbed · GitHub

2 Likes