Interrupts on pin D0 not working on Photon

This code works fine on a core, but not on a Photon. ISR is never executed when D0 pulled to GND.

void setup() {
  Serial.begin(19200);

  pinMode(D0,INPUT_PULLUP);
  attachInterrupt(D0,ISR,FALLING);
}

void loop() {
}

void ISR() {
  Serial.println("ISR");
}

@steelydev

are you running into a (known) problem with interrupts conflicting with Serial?

try without using Serial.print( ) (untested)

void setup() 
{
  Serial.begin(19200);
  pinMode(D7,OUTPUT);
  digitalWrite(D7, HIGH);
  pinMode(D0,INPUT_PULLUP);
  attachInterrupt(D0, ISR, FALLING);
}

void loop() 
{
  
}

void ISR(void) 
{
  digitalWrite(!digitalRead(D7));
}

Do you mean I can’t use Serial at all or just in the ISR? Where is that thread?

In any case, this does not use Serial and runs on Core but not on Photon:

volatile bool interrupt = false;

void setup() {
  pinMode(D0,INPUT_PULLUP);
  attachInterrupt(D0,ISR,FALLING);
}

void loop() {
  if (interrupt) {
    blinkD7();
    interrupt = false;
  }
}

void ISR() {
  interrupt = true;
}

void blinkD7() {
  pinMode(D7,OUTPUT);
  digitalWrite(D7, HIGH);
  delay(50);
  digitalWrite(D7, LOW);
  delay(50);
}

@mdma Is there an ETA for working attachInterrupt on Photon or a workaround in the interim?

I have a meeting now and will look at it after then. Hopefully get a fix in the 0.4.2 release which should also go out today.

1 Like

There is an issue specifically with D0, but other pins are working as expected. (I tested D1-D3.)

The workaround is to not use pin D0.

tnx, for the update.

The docs state that all Photon pins except D0 can be used for interrupts. But has anyone tested D5 (or other pins not allowed on the Core)?? Compiling from cmdline (particle flash XXX) does not yield a program that responds to D5, although D4 works. I wonder if illegal parameter code for the Core is still in place? Or is there a way to make sure you compile for Photon and not Core?

@johnshifflett, check this out:

Woot! That’s great info, thanks a million for the pointer; will use that method from now on.
Unfortunately, after updating and doing a photon compile followed by flash, I’m still showing no response to interrupt transitions on D5 or D6. This would be expected for Core but had hoped Photon was different.
Any additional suggestions?

Might be related to this: https://github.com/spark/firmware/issues/443

@kennethlimcp, it seems like that is the problem! @satishgn, would it not be possible to cascade shared interrupts by testing each respective interrupt condition? Is this a conversation I should have with @mdma?

If there are flags that are set to indicate the interrupt trigger that would be a perfect solution. I’ve not found any such flags so far, but I’m far from a STM32 guru. (Although searching brings me to threads like this one, which claim it’s not possible to service two different GPIOs on the same EXTI line because the internal N-to-1 demultiplexer.)

For the issue with Mode/D0/A5, it may be possible to rework the way the system handles the mode button to free up D0/A5 interrupts.

I have the same issue. I were running interrupt on few Photon from D0 to D4, D0 is the only one does not receipt anything. Glad that I only need to use 4 pins, so I use D4 instead of D0. I would love to see if there is any solution for this in the future.

Maybe consulting the docs would clear that up
https://docs.particle.io/reference/firmware/photon/#interrupts

I doubt this will be something to see soon, there are more pressing things in the back log.