This is a fork of my subject "Can't get multiple SoftwareSerial to run on the Mega" but I've narrowed my current problems down to specifically interrupts. Tell me how I can simplify the problem description any more or help me with what I've gotten.
Basically what I'm designing is a simplified two-wire interface with a separate pair of wires from a Master Mega to each Slave UNO. I can't (won't) use TWI on a bus since I'm a stubborn old Finn. Specifically, I can't (won't) put a serial# in each slave UNO to make them unique as TWI seems to require. I can't put more than one TWI on the Mega so I decided to write my own. Since the messages between the UNO and Mega have, at most 2 bits, I haven't expanded the protocol beyond one bit at a time. Right now I'm trying to use the 6 Mega hardware interrupts to set up a separate communication to each slave.
I've read Nick Gammon's "Gammon Forum : Electronics : Microprocessors : Interrupts" and everything I can find in the forums under "interrupts and Mega"
I thought last weeks problems were solved once I learned that detachInterrupt() only delays an interrupt execution (which then executes with the next attachInterrupt). I read all the discussion on "clearing" interrupt bits, which is very hard for me to follow, especially since it is different on the UNO and the Mega. I'm now using EIFR = 0xFF; in my sendDataBit() routine. I'm very unsure how to clear individual interrupts, but as suggested clearing them all might work.
I've included my complete code for the Master Mega, below. In it I've stripped it down to only 2 comm lines. Physically, I've stripped it down further to have only pin 2 for interrupt0 and pin 4 for the data line. Interrupt1 on pin 3 (and pin 5 for a data line) are not even physically connected at the moment and are held HIGH with INPUT_PULLUP. I swapped out the Mega (purchased from Mouser) with a Mega ADK and have the same behavior. I also swapped out the UNOs.
The current strange behavior is that when I send an interrupt out from slave0 (UNO out on pin 2 and 3, into Mega pins 2 and 4) I get an interrupt1 (from non-connected pin 3??) as well as the expected interrupt0. The sendDataBit() routine is the only one that fusses with anything that could be related to interrupt1. Do I misunderstand how to clear interrupts?
I'll post the Mega master code in a separate post. Please look at the setup and the function sendDataBit().
Here is a sample of the Monitor output on the Windows monitor that is connected to the Master Mega. I just booted both devices, connected both monitors and sent an authorization request from the UNO to the Mega. The UNO and Master are connected with 5v to 5v, ground to ground, pin2 to pin2 and UNO pin3 to Mega pin4. Both devices are getting power through USB from separate computers. The "Holy Smokes, Batman" just after loop 4 is from interrupt1 (slave1ISR() ), followed by the expected interrupt0 (slave0ISR() ) conversation "slave 0 being authorized..." Serial.println("Holy Smokes, Batman"); is the only thing I put into slave1ISR() because I never expected it to be executed. I have no idea what is kicking it off since it was set up with "attachInterrupt(1, slave1ISR, FALLING);" and Mega pin 3 is not connected. If I send a second request from the UNO, I still also get Interrupt1, so I don't think it is just an uncleared interrupt from the booting process. The unacceptable (and temporary) Serial.print() inside the ISR isn't the problem since it hasn't been executed yet when the unexpected interrupt1 is kicked off. What am I missing?
71M11Master_2013aug28E
Note: from monitor 1 = denied, 0 = authorized, 5 = print AR list
Only testing slave 0, for now...
end of setup...
AR= 0 looping... 0
AR= 0 looping... 1
AR= 0 looping... 2
AR= 0 looping... 3
AR= 0 looping... 4
Holy smokes, Batman! slave1ISR...
Slave 0 being authorized Slave 0 sent data 1
slave 0 toys out 1 total toys out count now = 1 AR= 0
AR= 0 looping... 5
AR= 0 looping... 6
AR= 0 looping... 7
AR= 0 looping... 8
AR= 0 looping... 9
AR= 0 looping... 10
AR= 0 looping... 11