Why does call to digitalWrite(11, LOW) fails to change pin state?

I have this code in an ISR that is successfully being triggered continuously from an MCP23017.

There is a LED attached to pin 11.

void ISR1()
{
  digitalWrite(11, HIGH);
  bISR1 = true;
}

At the top of my loop function I have this code that is supposed to turn the LED off but the call to digitalWrite(11, LOW); is failing for some reason.

	if (bISR1)
	{
		digitalWrite(11, LOW);
		mcp.clearInts();
                bISR1 = false;
                Serial.println(F("Interrupt 1 generated..."));
	}

Every time I trigger the interrupt on the MCP I see the text "Interrupt 1 generated..." in my serial monitor.

So the only thing that is wrong is the call to digitalWrite(11, LOW) that is failing to change the pin state.

Why would this be occurring?

Are there issues with using digitalWrite(...) in an ISR?

Is bISR1 declared as volatile?
Is pin 11 set to output?

To get help, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.

  1. Read and follow the posting rules for this forum 0 POST ALL YOUR CODE. That's your first stupid mistake.

  2. Even thinking that there could be such a simple error in a function such as digitalRead/Write is your second stupid mistake.

Mark

An excellent example of a race condition.

The bISR1 related code in loop is not atomic. Until it is there will always be a bug-in-waiting.