Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Arduino gets freezed if an Interrupt is attached #47

Open
swimm3r opened this issue Oct 18, 2024 · 1 comment
Open

Question: Arduino gets freezed if an Interrupt is attached #47

swimm3r opened this issue Oct 18, 2024 · 1 comment

Comments

@swimm3r
Copy link

swimm3r commented Oct 18, 2024

Hello,

Does anyone have problem with attachInterrupt while using hd44780ioClass/hd44780_I2Cexp.h?
The Arduino Uno gets freeze while running the folowing code (it's only a part of it).

#include <Wire.h>
#include <hd44780.h>                 
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <util/parity.h> //comment out if you don't use an AVR MCU

int interruptPin = 3;
int ledPin = 13;

//hd44780_I2Cexp lcd(0x3f, I2Cexp_BOARD_SUNROM);
hd44780_I2Cexp lcd;

volatile unsigned long lastInt = 0;
volatile unsigned long long currentBuf = 0;
volatile byte bufCounter;

void setup(){
  Serial.begin(115200);
  Wire.begin();
  lcd.begin(16, 2);
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin), DCF77_ISR, CHANGE);
  lcd.setCursor(0, 0);
  lcd.print("up:");
  lcd.setCursor(0, 1);
  lcd.print("down:");
  lcd.setCursor(0, 0);
}

Thank you. Any suggestion is welcomed.

@bperrybap
Copy link
Contributor

You have not shown any of the main code but
I'm guessing this issue is caused by something that is being done in the ISR that was attached.
The Wire library uses interrupts, if interrupts are blocked or masked when calling a Wire library function, the Wire code can get stuck in an infinite look looking for an event (that is set by the Wire ISR) that will never happen because the Wire library ISR isn't getting to run.

So for example, if your attached ISR runs and attempts to use the Wire interface by using the hd44780 library, that will cause the Wire library to hang (because at that point interrupts are masked) and your ISR will never complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants