ATtiny841 core - attachInterrupt

I have been staring for some time at this basic attachInterrupt() example from the playground. It works on UNO but not on attiny841.

const byte ledPin = 4;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(0 /*digitalPinToInterrupt(interruptPin)*/, blink, CHANGE);
}

void loop() {
  digitalWrite(ledPin, state);
}

void blink() {
  state = !state;
}

The idea is that when pulling D2 (PB2) to ground and releasing it again, the led changes state.

I measure 4.9V on D2, so the pullup seems to be there. Yet I see no led changes. (the led works ok e.g. if I initialise state to HIGH)

The core has no digitalPinToInterrupt() so I replaced it with simply 0.

Am I missing something obvious? Or is it a problem in the core?

I use ide 1.6.6 and installed the 'attiny core modern from SpenceConde 1.0.6' using the board manager.(via DrAzzy's http://drazzy.com/package_drazzy.com_index.json)

Per datasheet, INT0 is on PB1 (pin 1 by the pinout numbering the core uses), not PB2. Which of course is exceptionally inconvenient, as that pin is unavailable if using a crystal...

I've created an issue for the lack of digitalPinToInterrupt() https://github.com/SpenceKonde/ATTinyCore/issues/61 (note that 1.0.6 of attiny841 is deprecated now - I combined the two attiny cores I maintain into one ultimate attiny core that works with every interesting attiny except the '13)

That's why I use PCINT's (and I don't use the PCINT libraries either - it's really not that hard to implement interrupts by hand, and I think awareness of how they're working under the covers results in better code).

Btw - my last name is spelled with a K - Konde. Is it written with a C somewhere that I should get fixed?

Edit: I think the github version should have digitalPinToInterrupt() working now.

Thanks, you rock!

I used PB2 because I trusted the ascii art doc inside pins_arduino.h which places INT0 near PB2 instead of PB1.

I used pin D1 (PB1), and now it works.

B.t.w, when using the 1.1.0 core I remarked two oddities: - the above sketch does not compile unless I places the blink() definition before the call to attachInterrupt(). If not, I get: 'blink' was not declared in this scope.

  • it does not find avrdude (I am on linux kubuntu 14.04): java.io.IOException: Cannot run program "REMOVE/bin/avrdude" (The 1.0.6 core did not produce these phenomena)

Btw - my last name is spelled with a K - Konde. Is it written with a C somewhere that I should get fixed?

No, I simply misspelled your name, sorry for that.

Peter.

What ide version are you using?

1.6.6. Some (board manager? myself?) operation removed my avrdude? Anyway installed 1.6.8, and everything works fine: compiling + uploading... Thanks again.