xreef/PCF8574_library

Example interruptWemos crash

Tommamgo opened this issue · 3 comments

Hello,
Every time I try the example interruptWemos on my Wemos D1 Mini, it crashes. At the beginning I thought I connected something wrong, but with the example LedWemos everything works. I suspect that for some reason something is wrong with the interrupt pin, but what?

This is my error message:

User exception (panic/abort/assert)
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Abort called

stack>>>

ctx: cont
sp: 3ffffef0 end: 3fffffc0 offset: 0000
3ffffef0: feefeffe feefeffe feefeffe 00000100
3fffff00: 000000fe 00000000 00000000 00000000
3fffff10: 00000000 00000000 00000000 00ff0000
3fffff20: 5ffffe00 5ffffe00 3ffef31c 00000000
3fffff30: 00000002 0000000d 3ffee514 4020251a
3fffff40: 40100686 2bde5da7 ffffff00 4020252c
3fffff50: 40101a49 0004ea65 3ffee514 40203185
3fffff60: 00000000 3ffee65c 000003e8 3ffee554
3fffff70: 3fffdad0 3ffee65c 000003e8 3ffee554
3fffff80: 3fffdad0 3ffee4ec 3ffee514 40203234
3fffff90: 3fffdad0 3ffee4ec 3ffee514 40201075
3fffffa0: 3fffdad0 00000000 3ffee514 40202128
3fffffb0: feefeffe feefeffe 3ffe84e8 40100f85
<<<stack<<<

After I found a post with a different interrupt problem, I adjusted my code accordingly.
My change in the void keyPressedOnPCF8574() function

`/*

  • PCF8574 GPIO Port Expand
  • http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
  • PCF8574 ----- WeMos
  • A0 ----- GRD
  • A1 ----- GRD
  • A2 ----- GRD
  • VSS ----- GRD
  • VDD ----- 5V/3.3V
  • SDA ----- GPIO_4
  • SCL ----- GPIO_5
  • INT ----- GPIO_13
  • P0 ----------------- BUTTON0
  • P1 ----------------- BUTTON1
  • P2 ----------------- BUTTON2
  • P3 ----------------- BUTTON3
  • P4 ----------------- BUTTON4
  • P5 ----------------- BUTTON5
  • P6 ----------------- BUTTON6
  • P7 ----------------- BUTTON7

*/

#include "Arduino.h"
#include "PCF8574.h" // https://github.com/xreef/PCF8574_library

#define ESP8266_INTERRUPTED_PIN 13

// Set i2c address
PCF8574 pcf8574(0x20);

// Function interrupt
bool keyPressed = false;

void ICACHE_RAM_ATTR keyPressedOnPCF8574(){
// Serial.println("keyPressedOnPCF8574");
keyPressed = true;
}

void setup()
{
Serial.begin(9600);
delay(1000);

pinMode(ESP8266_INTERRUPTED_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ESP8266_INTERRUPTED_PIN), keyPressedOnPCF8574, RISING);

for(int i=0;i<8;i++) {
pcf8574.pinMode(i, INPUT);
}
Serial.print("Init pcf8574...");
if (pcf8574.begin()){
Serial.println("OK");
}else{
Serial.println("KO");
}
}

void loop()
{
if (keyPressed){
PCF8574::DigitalInput val = pcf8574.digitalReadAll();
if (val.p0==HIGH) Serial.println("KEY0 PRESSED");
if (val.p1==HIGH) Serial.println("KEY1 PRESSED");
if (val.p2==HIGH) Serial.println("KEY2 PRESSED");
if (val.p3==HIGH) Serial.println("KEY3 PRESSED");
if (val.p4==HIGH) Serial.println("KEY4 PRESSED");
if (val.p5==HIGH) Serial.println("KEY5 PRESSED");
if (val.p6==HIGH) Serial.println("KEY6 PRESSED");
if (val.p7==HIGH) Serial.println("KEY7 PRESSED");
keyPressed= false;
}
}`

now I get no more error message, but understood why I have not and I'm not sure if it the Promgam now still works properly

xreef commented

Hi Tommamgo,
now the sketch works correctly?
Bye Renzo

I'm not quite sure about that....
When I upload the sketch, I get this output.

...
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
Init pcf8574...OK
...

First when I press a button it changes.

KEY0 PRESSED
KEY2 PRESSED
KEY3 PRESSED
KEY4 PRESSED
KEY5 PRESSED
KEY6 PRESSED
KEY7 PRESSED

I have connected a button to pin 01.
(Pin01 -> button -> Resistor 4.7k -> Ground)

It seems that the output is inverted?

in my opinion with esp family is always better put some delay in every loop or the watchdog will reset.