Strange Interrupt behavior on IO

mirmit
Posts: 3
Joined: Sat Aug 26, 2017 8:56 am

Strange Interrupt behavior on IO

Postby mirmit » Sat Aug 26, 2017 9:11 am

I'm in the process of migrating dome ESP8266 code to ESP32 and face a strange Interrupt handler behavior.

The ESP32 is connected to an external system - hoverboard. The hall sensors, detecting wheel movements raise a square signal. I connect the 3 signal to 3 input pins on ESP32. I'm using a very simple sketch:

Code: Select all

int pin[] = {15, 4, 16};

void setup() {
  // put your setup code here, to run once:
  for (int i=0; i<3; i++) {
    pinMode(pin[i], INPUT);
  }
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  attachInterrupt(pin[0], pin0LChanged, RISING  );
  attachInterrupt(pin[1], pin1LChanged, RISING  );
  attachInterrupt(pin[2], pin2LChanged, RISING  );
}


void pin0LChanged() {
  Serial.print("0");
}
void pin1LChanged() {
  Serial.print("1");
}
void pin2LChanged() {
  Serial.print("2");
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  Serial.println("-- ");
}
I was expecting to see something like 012012012012012 for a movement in one way, 021021021021021 in the other side. I have this behavior on ESP8266.

But I'm seeing output like:

Code: Select all

-- 
122222222222211111111111-- 
00000000012222222222111111111120000000000222222222111111111-- 
000000000000111111111122222222220000000001111111111-- 
22222222221111111111120000000000222222222222-- 
111111111111000000000000-- 
-- 
It appears the riding interrupt is shouted several times.

The signal, seen with a logic analyser is clean:
Signal.PNG
Signal.PNG (2.88 KiB) Viewed 5186 times
I'm wondering if there is something needed in EPS32 different from ESP8266 to have a correct behavior, or what I have missed.

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: Strange Interrupt behavior on IO

Postby tele_player » Sun Aug 27, 2017 7:51 am

I wonder if using Serial.print() in the ISR is causing the problem?

mirmit
Posts: 3
Joined: Sat Aug 26, 2017 8:56 am

Re: Strange Interrupt behavior on IO

Postby mirmit » Sat Sep 02, 2017 10:33 am

I've tested by adding the interrupt info into a buffer and printf in the main look.

Code: Select all

void pin0LChanged() {
if (pos < 100)
  buf[pos++] = 0x30;
}
void pin1LChanged() {
if (pos < 100)
  buf[pos++] = 0x31;
}
void pin2LChanged() {
if (pos < 100)
  buf[pos++] = 0x32;
}
And in the loop, the output part is:

Code: Select all

  Serial.println("-- ");
  buf[pos++] = 0;
    Serial.println(buf);
  pos = 0;
I still have spurious interrupt handled.
--
1110101110101011111101111110111011011111011011111111010101101011111111101011011110111011110111111010
--
1101101111110110101111010111011101010111010101111110111010111011011011011010101110110101111111110101
--
Are the electrical inputs the same as on ESP8266?

When I connect the GPIO2 (led on the input pin), I do have a clean result (1 interrupt raised between the -- on the proper port)

Who is online

Users browsing this forum: No registered users and 58 guests