pcf8574_arduino_library icon indicating copy to clipboard operation
pcf8574_arduino_library copied to clipboard

Arduino Nano crashing on digitalRead

Open saspol opened this issue 7 years ago • 2 comments

Hello, Im trying to get expander pins state on interrupt receiving and always got crash. Can you please see whats problem with this code?

#include <Wire.h>
#include "PCF8575.h"

PCF8575 expander;

void setup() {
  Serial.begin(57600);
  expander.begin(0x20);
  expander.pinMode(0, INPUT);
  expander.enableInterrupt(2, ISRgateway);
}

void ISRgateway() {
  Serial.println("Board interrupt!");
  Serial.println(expander.read(), DEC);
}

void loop() {

}

On interrupt i see only "Bo" in console, then controller stuck.

saspol avatar Feb 18 '18 02:02 saspol

Hello,

Try replacing the Serial.println with a led blink or something simple to see if the isr is called. Or set a boolean flag in the isr, and print from the loop() function.

This code is like ... 5 year old, I don't really remember how the interruption code work. I still remember something about Wire (which is called by expander.read()) not liking at all to be called from an interruption function. Maybe this is still true today.

skywodd avatar Feb 19 '18 14:02 skywodd

Hi, i set flag in isr and then do read in loop. This working as expected. Thanx!

saspol avatar Feb 19 '18 14:02 saspol