Pages: [1]   Go Down
Author Topic: using any pin as an interrupt on a 2560 mega  (Read 1005 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a 2560 mega based custom board and need to use pin 36 as an interrupt so that I can set is as a Receive port (using SoftwareSerial) to talk to another Arduino board.

I know that the ATMEGA2560 (and other Arduino chips) support any pin being an Interrupt. I found this http://arduino.cc/playground/Main/PcInt but am at a loss for how to make pin 36 an interrupt.

Half of the analog pins have interrupts, if I configure one as a digital pin will that also work? Suggestions?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 115
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Those ints are per port so 8 digital IO's and you can mask off the others. Yea you can do it but there has to be a better way have you considered I2C, SPI or one of the 4 hardware uarts? rather than soft serial.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just realized that I do have D17 available on the custom board and its a hardware serial receive. I can use any digital pin as the TX for hardware serial, right?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like that's not going to work. So either I do SoftwareSerial or I use I2C on both Arduinos (the pins are open). Is there an advantage to I2C over Software serial?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I2C is done in hardware, SoftwareSerial is done in software. Anything implemented in software will consume more resources.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 115
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just realized that I do have D17 available on the custom board and its a hardware serial receive. I can use any digital pin as the TX for hardware serial, right?

Well you could technically use soft serial send on any port but D16 would be the hardware one that matches otherwise your receiving on one serial port and sending on another besides being ugly it should work.  Are you using the mega unmapped pins pe2,pe6,pe7,pg3,pg4,pd6,pd5,pd4,pj7.pj6,pj5,pj4,pj3,pj2,ph7,ph2 I think 7 or so of them are hardware ints as well.

I2C is a good deal faster than serial and it's implemented in hardware.  It's also multi drop so you can also connect sensors, eeprom, IO ex-panders, etc still using just those 2 pins.  Since you seem to be running low on IO pins those IO ex-panders might be useful.

You did not mention what you wanted to connect the two atmega's together I assume it's not for increased processing speed.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Mega2560 has quite a few hardware serial pins, you know.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pins 14, 15, 16, 18, 19 are taken by Motor drivers, it's hardwired on the board, the pins aren't even exposed. 

I'm connecting a second 2560 to drive a 3" LCD and touchpanel and it uses pins 22-53. I may also connect a 9DOF IMU to it because the custom board has its hands full with 5 analog pressure sensors, 5 LEDs and 3 motor drivers (which will likely increase to 5) and 3 rotary absolute position sensors. The main board is being connected to Ubuntu running ROS (Robot Operating System), it will be making all the decisions based on sensor data on when to turn on LEDs and motors.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

silasmoeckel, the only pin that has an interrupt that is free is D17, all the rest are hardwired to other things. I don't think I could do hardware serial for just RX and softwareserial for the TX?

Seems like I2C is probably my best bet. I'll play with it tonight and see if I can get it working.   - this is a tutorial I found but haven't watched yet.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/i2c
Logged

Pages: [1]   Go Up
Jump to: