Author Topic: digitalPinToInterrupt missing in pins_arduino.h file for MoteinoMEGA Core  (Read 852 times)

j54n1n

  • NewMember
  • *
  • Posts: 2
  • Country: it
Hello there,

I was using the board definition MoteinoMEGA from your MoteinoCore JSON (https://lowpowerlab.github.io/MoteinoCore/package_LowPowerLab_index.json) at its most recent version v1.5 and I got an error with this minimal sketch:
Code: [Select]
#define PIN_INT0 10

void setup() {
  pinMode(PIN_INT0, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(PIN_INT0), onInterrupt, FALLING);
}

void loop() { }

void onInterrupt() { }
The Arduino IDE spits out following error message:
Code: [Select]
C:\Files\Work\arduino\MinimalCoreError\MinimalCoreError.ino: In function 'void setup()':

MinimalCoreError:5:19: error: 'digitalPinToInterrupt' was not declared in this scope

   attachInterrupt(digitalPinToInterrupt(PIN_INT0), onInterrupt, FALLING);

                   ^~~~~~~~~~~~~~~~~~~~~
And in fact if I open the file pins_arduino.h in the variants folder for MoteinoMEGA I can not find a line with digitalPinToInterrupt.

If I compare it to the file for the Moteino in the pins_arduino.h I can find on line 84:
Code: [Select]
#define digitalPinToInterrupt(p)  ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
Could it be that the line with digitalPinToInterrupt was not copied over to the MoteinoMEGA file?

MightyCore is using following definition in its file for the ATmega1284:
Code: [Select]
#define digitalPinToInterrupt(p)    ((p) == 2 ? 2 : ((p) == 10 ? 0 : ((p) == 11 ? 1 : NOT_AN_INTERRUPT)))
https://github.com/MCUdude/MightyCore/blob/7ae2249138427e13d444fd5cd7961c541cfd9780/avr/variants/standard/pins_arduino.h#L120
Could this be fixed by making a new version of the core and could it be updated in the JSON?

Cheers

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6608
  • Country: us
    • LowPowerLab
Normally you would not need this function because there are only 3 interrupts on the MoteinoMEGA. One is used by the radio (2) and the other 2 are free (0,1).
So the function call is redundant if you don't know which pins have actual hardware interrupts.
On the MoteinoMEGA there are i0,i1,i2 markins on the silkscreen. You would just type 0,1,2 instead of digitalPinToInterrupt(2/10/11).

But for completeness sake you can add this locally in pins_arduino.h and I can add it in the next release:

Code: [Select]
#define digitalPinToInterrupt(p)    ((p) == 2 ? 2 : ((p) == 10 ? 0 : ((p) == 11 ? 1 : NOT_AN_INTERRUPT)))

j54n1n

  • NewMember
  • *
  • Posts: 2
  • Country: it
Thanks Felix, very much appreciated. Actually I am using an Arduino library that is depending on digitalPinToInterrupt(p). See also: https://github.com/mysensors/MySensors/issues/665

I patched already my local version but so can also other projects benefit from it.

Cheers