Go Down

Topic: Interrupts (Read 1 time) previous topic - next topic

oigres

Hi all,

in ARDUINO documentation they say that interrupt 0 (INT0) is attached to pin 2 in the ARDUINNO MEGA*:
http://arduino.cc/en/Reference/AttachInterrupt

BUT, in the following page, they say show INT0 as being attached to pin 21:
http://arduino.cc/en/uploads/Main/arduino-mega2560-schematic.pdf

I know that INT0 is not related to pin 21 because I have tested and concluuded that, in reality, pin 21 it is related to INT2.

I ask if this difference is "by design", or if is some documentation flaw.

Please advise.

Thanks.

-SR

retrolefty

#1
Jul 04, 2011, 04:07 am Last Edit: Jul 04, 2011, 04:09 am by retrolefty Reason: 1

Hi all,

in ARDUINO documentation they say that interrupt 0 (INT0) is attached to pin 2 in the ARDUINNO MEGA*:
http://arduino.cc/en/Reference/AttachInterrupt

BUT, in the following page, they say show INT0 as being attached to pin 21:
http://arduino.cc/en/uploads/Main/arduino-mega2560-schematic.pdf

I know that INT0 is not related to pin 21 because I have tested and concluuded that, in reality, pin 21 it is related to INT2.

I ask if this difference is "by design", or if is some documentation flaw.

Please advise.

Thanks.

-SR


There are mistakes and misunderstanding in various docs, sometimes because of inconsistent terms used by arduino Vs Atmel. The only 'bible' to go by, in my opinion, is the pin mapping source files in the core libraries. It can get confusing for sure. My method, like yours was, is to actual perform simple hardware/software testing before committing to larger projects using features I haven't used before.

Lefty

CrossRoads

"The only 'bible' to go by, in my opinion, is the pin mapping source files in the core libraries. It can get confusing for sure. "
Reviewing the schematic is also helpful.

INT0 is pin 2 on an ATMega328.  So I would go with simple documentation error.

INT0,1,2,3 are physical pins 43,44,45,46 on the ATMega2560.  D21,20,19,18 on the Mega2560 schematic.
INT4,5,6,7 are physical pins 6,7,8,9. D2, D3 and not connected, not connected on the Mega2560 schematic.  Loss of 2 interrupts there.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

retrolefty

#3
Jul 04, 2011, 07:11 am Last Edit: Jul 04, 2011, 07:13 am by retrolefty Reason: 1
Quote
INT0,1,2,3 are physical pins 43,44,45,46 on the ATMega2560.  D21,20,19,18 on the Mega2560 schematic.


But reference says:

Quote
Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).


So leaving physical pin numbers out of it and leaving Atmel pin names out of it also to void confusion, and just using arduino shield connector pin numbers and the proper user interrupt name used in sketches,  The Arduino reference above says for a mega board, six total user interrupts supported on the following arduino pins:

Quote
sketch interrupt number                    arduino pin number
           0                                                 2
           1                                                 3
           2                                                21
           3                                                20
           4                                                19
           5                                                18


I've only used interrupts on arduion pins 2 and 3 on my mega board, but I assumed the pin numbers in the arduino reference to be accurate, that there are a total of 6 available user interrupt pins on a mega and they are at pins 2,3, and 18-21?

Lefty

CrossRoads



Arduino software is redefining the ATMega2560 INTs into its own numbering it seems:

Phsyical INT4 -> Arduino INT0
Physical INT5 -> Arduino INT1
Physical INT0 -> Arduino INT2
Physical INT1 -> Arduino INT3
Physical INT2 -> Arduino INT4
Physical INT3 -> Arduino INT5
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

retrolefty

Quote
Arduino software is redefining the ATMega2560 INTs into its own numbering it seems:

Phsyical INT4 -> Arduino INT0
Physical INT5 -> Arduino INT1
Physical INT0 -> Arduino INT2
Physical INT1 -> Arduino INT3
Physical INT2 -> Arduino INT4
Physical INT3 -> Arduino INT5


Yes, and arduino doesn't use name INTx in sketches, just 0-5 as used in the

Code: [Select]
attachInterrupt(0, blink, CHANGE);

So regardless of what any schmatic drawing or atmel datasheet calls things, when writting sketches and wiring up interrupts people should just stick to user interrupt names 0-5 in their sketches and the arduino pin numbers 2,3,21,20,19,18 for the wiring. Anything else just adds confusion and gives me a headache. Of course for people laying out PCB, there is no avoiding it I guess.

CrossRoads

"pin mapping source files in the core libraries"
That's what is missing - an easier way to see what these are.

Oh - I guess this page sort of says that, doesn't it:

http://arduino.cc/en/Main/ArduinoBoardMega2560

Quote

Input and Output
Each of the 54 digital pins on the Mega can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX); Serial 1: 19 (RX) and 18 (TX); Serial 2: 17 (RX) and 16 (TX); Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and transmit (TX) TTL serial data. Pins 0 and 1 are also connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip.

External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up