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 Answer 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.
-
Then can you define two things with the same pin? #define INTERRUPT_3 20 and then #define I2C_SDA 20?dinotom– dinotom2016年05月02日 23:21:12 +00:00Commented May 2, 2016 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– Majenko2016年05月02日 23:22:21 +00:00Commented May 2, 2016 at 23:22
-
1So if I plan on using interrupts AND I2C, then effectively I can't use interrupt3?dinotom– dinotom2016年05月02日 23:25:22 +00:00Commented May 2, 2016 at 23:25
-
And interrupt 2. Still, you have pin-change interrupts on every single other pin on the board...Majenko– Majenko2016年05月02日 23:32:48 +00:00Commented May 2, 2016 at 23:32
-
Not on the Mega you don't.2016年10月30日 06:41:17 +00:00Commented Oct 30, 2016 at 6:41