GreyGnome / EnableInterrupt

New Arduino interrupt library, designed for Arduino Uno/Mega 2560/Leonardo/Due
329 stars 73 forks source link

How to make pins 20 and 21 of 328P work ? #60

Open kbssa opened 4 years ago

kbssa commented 4 years ago

Hi,

I need to include the pins 20 and 21 (Crystals pins) of atmega328P in your library.

I have tried by my own, but with no success.

Could you point me to right direction, so I can make it work ?

Thanks

GreyGnome commented 4 years ago

It can probably be done, I'm not sure how easily though. I'll take a look...

On Thu, Dec 19, 2019 at 12:11 PM kbssa notifications@github.com wrote:

Hi,

I need to include the pins 20 and 21 (Crystals pins) of atmega328P in your library.

I have tried by my own, but with no success.

Could you point me to right direction, so I can make it work ?

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/60?email_source=notifications&email_token=AA2KFGPMW2O6MZLCRTWYZGTQZO2LVA5CNFSM4J5MPWI2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IBW6OWA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2KFGIUYX7F53W75Z3C2D3QZO2LVANCNFSM4J5MPWIQ .

-- -Mike Schwager

kbssa commented 4 years ago

Good to hear that, I only need this to finish my project.

Thank you very much

GreyGnome commented 4 years ago

In order for me to properly do this, I'll probably need an atmega328p standalone. I've got some on order but they won't be here for 3 weeks. In the meantime, I may try to get the attiny2414 to work with this library, and there I'll be allowing the crystal oscillator pins to be used as GPIO. It should be similar.

On Fri, Dec 27, 2019 at 10:12 PM kbssa notifications@github.com wrote:

Good to hear that, I only need this to finish my project.

Thank you very much

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/60?email_source=notifications&email_token=AA2KFGMLWHUXVQFULH5NGWLQ23G4TA5CNFSM4J5MPWI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHYBTNQ#issuecomment-569383350, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2KFGP6JH5OFDDHD2ZCUHTQ23G4TANCNFSM4J5MPWIQ .

-- -Mike Schwager

GreyGnome commented 4 years ago

...Oops, I mean attiny84. Not attiny2414.

On Sun, Dec 29, 2019 at 12:19 PM Michael Schwager mschwage@gmail.com wrote:

In order for me to properly do this, I'll probably need an atmega328p standalone. I've got some on order but they won't be here for 3 weeks. In the meantime, I may try to get the attiny2414 to work with this library, and there I'll be allowing the crystal oscillator pins to be used as GPIO. It should be similar.

On Fri, Dec 27, 2019 at 10:12 PM kbssa notifications@github.com wrote:

Good to hear that, I only need this to finish my project.

Thank you very much

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/60?email_source=notifications&email_token=AA2KFGMLWHUXVQFULH5NGWLQ23G4TA5CNFSM4J5MPWI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHYBTNQ#issuecomment-569383350, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2KFGP6JH5OFDDHD2ZCUHTQ23G4TANCNFSM4J5MPWIQ .

-- -Mike Schwager

-- -Mike Schwager

kbssa commented 4 years ago

In order for me to properly do this, I'll probably need an atmega328p standalone. I've got some on order but they won't be here for 3 weeks. In the meantime, I may try to get the attiny2414 to work with this library, and there I'll be allowing the crystal oscillator pins to be used as GPIO. It should be similar.

Could you point me to what I need to change to make it work ? Or it's more than a few changes ?

Thanks

GreyGnome commented 4 years ago

OK, I'm doing some looking around. First, is this code (line numbers included):

1243     portMask=pgm_read_byte(&digital_pin_to_bit_mask_PGM[arduinoPin]);
1244     portNumber=pgm_read_byte(&digital_pin_to_port_PGM[arduinoPin]);

So there are 2 problems: arduinoPin for PB6 and PB7 (ATMEGA328 pins 9 and 10) is not defined. On the Arduino, it only goes to pin 19. So you would need to have an "if" statement in the above. If the pin was 20 or 21, return the proper portMask and portNumber.

Then, I think here:

1841 #if ! (defined ARDUINO_328) && ! (defined EI_ATTINY24) && ! (defined EI_ATTINY25)
1842   if (interruptMask & _BV(6)) { arduinoInterruptedPin=ARDUINO_PIN_B6; arduinoPinState=current & _BV(6); portBFunctions.pinSix(); }
1843   if (interruptMask & _BV(7)) { arduinoInterruptedPin=ARDUINO_PIN_B7; arduinoPinState=current & _BV(7); portBFunctions.pinSeven(); }

Specifically, line 1841, here's no reason for the ARDUINO_328 in there, because we DO want _BV(6) and _BV(7) to be valid.

Same with line 1854; remove the ! (defined ARDUINO_328):

1854 #if ! (defined ARDUINO_328) && ! (defined EI_ATTINY24) && ! (defined EI_ATTINY25)`

Between line 186 and 187, insert:

#define ARDUINO_PIN_B6 20 // A lie! Because the Arduino has an xtal here, but we want to use
#define ARDUINO_PIN_B7 21 // these pins on non-Arduino Atmega328's

Between lines 222 and 223:

6,
7

...and fix line 221 by appending a comma.

Between lines 237 and 238, insert:

interruptFunctionType pinSix;
interruptFunctionType pinSeven;

Change line 241 to include more NULL's:

functionPointersPortB portBFunctions = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };`

I think that's about it, but I'm not 100% sure without testing it. I have some 328p's on order.

kbssa commented 4 years ago

Ok, Thank's a lot !

When I do some tests I post the results here.

GreyGnome commented 4 years ago

No problem. Remember, for lines 1843 and 1844 you have to have an "if" statement and return what the port mask and bit number are verbatim... don't use the "digital_pin_to..." macros because they cannot handle the additional pins.