MCUdude / MightyCore

Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535
Other
637 stars 181 forks source link

Question about PCINT on 644A #264

Closed fschimpf closed 1 year ago

fschimpf commented 1 year ago

Hi! I have trouble getting pin-change-interrupts to work. I made a minimal program which works when I use extint-pins (INT0), but doesn't work with the pin-change-interrupts. Could you tell me if I am missing something or if this is an issue?

I am using a Mega644A with the following settings: Clock: Internal 4 MHz, BOD: BOD 2.7 V, EEPROM retained, Compiler LTO disabled, Variant: 644/644A, Pinout: Standard pinout, Bootloader: No Bootloader

// working program with button attached to INT0-pin const int button_pin = 10; // PD2, INT0
const int led_pin = 15;
void setup() { pinMode(led_pin, OUTPUT); pinMode(button_pin, INPUT); attachInterrupt(digitalPinToInterrupt(button_pin), button_ISR, RISING); } void button_ISR(){ state = LOW; } void loop() { digitalWrite(led_pin, state); delay (50); }

// Non-working program with button attached to PD4 / PCINT28. The only change is pin-number. const int button_pin = 12; // PD4, PCINT28
const int led_pin = 15;
void setup() { pinMode(led_pin, OUTPUT); pinMode(button_pin, INPUT); attachInterrupt(digitalPinToInterrupt(button_pin), button_ISR, RISING); } void button_ISR(){ state = LOW; } void loop() { digitalWrite(led_pin, state); delay (50); }

Thanks for the great work and regards, Fritz

MCUdude commented 1 year ago

I'm sorry, but you won't be able to use PCINTs with attachInterrupt. You'll have to use INT0, INT1, or INT2. However, you can use an external Arduino PCINT library, given that the ATMega644A is supported.

This library may work: https://github.com/NicoHood/PinChangeInterrupt

fschimpf commented 1 year ago

OK, thank you!