0

I am building a rather complicated model railroad crossing signal and have moved to using the Mega since I need more pins than the Uno. Upon reading the specs of the Mega on the Arduino.cc website I noticed a potential pin conflict, or not, maybe they serve a dual purpose?

External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2).

I2C: 20 (SDA) and 21 (SCL).

SDA and Interrupt 3 both function on pin 20? Likewise with Interrupt 2 and SCL?

I assume this is true, how/why do they share the same pin?

1

Lots of things share pins. It's normal. The "how" is that those pins are connected, internally, to multiple bits of the circuitry.

The "why" is simply because if you had a discrete pin for each possible function you would end up with a chip the size of your desk.

Pretty much every single pin on the chip has multiple functions on it.

|improve this answer|||||
  • Then can you define two things with the same pin? #define INTERRUPT_3 20 and then #define I2C_SDA 20? – dinotom May 2 '16 at 23:21
  • You can define anything to anything. You can only use one function at a time though. After all - how would you wire the pin to both the I2C device and the interrupt source and differentiate between them? – Majenko May 2 '16 at 23:22
  • 1
    So if I plan on using interrupts AND I2C, then effectively I can't use interrupt3? – dinotom May 2 '16 at 23:25
  • And interrupt 2. Still, you have pin-change interrupts on every single other pin on the board... – Majenko May 2 '16 at 23:32
  • Not on the Mega you don't. – Nick Gammon Oct 30 '16 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.