Can I use INT5 at the same time as Serial1 if I'm only using the RX on the serial port? I need to be able to use a transceiver's iRQ while listen for codes from an RFID sensor. And "yes" it is possible to run out of serial ports and external interrupts on a mega2560. 8)
I see no reason this won't work at the hardware level, the Serial library may get in the way though by setting the pin to an output. Note however that external interrupts still work when a pin is set to OP (IIRC) so this may not matter.
Another option is to use INT7 (PE7) or INT6 (PE6) , these are two external interrupts not implemented by the Arduino but there in the chip never the less. (Exactly what the interrupt vector table does with these two I don't know, they may be trapped and ignored by the library, or maybe not filled at all so you will go to the "bad int" vector).
Rob
Weird, according to the Eagle schematic PE6 and PE7 have no connection on the Arduino Mega board. I guess aesthetics was more important. I'll try INT5 first, if that doesn't work I can move a few things around and just disable the interrupt when i need the serial port. Would signal diodes be needed if neither device was on and the same time?
Yes so I see, well I did say they were "on the chip" ![]()
Why they would ignore two important features like more external interrupts is anyone's guess.
Would signal diodes be needed if neither device was on and the same time?
The only way I can see this working is by getting in and changing the direction of the Tx pin. If it stays an output there is no way to get the external interrupt.
Hopefully after the Serial1.begin you can do a pinMode(INPUT) then attachInterrupt() and pray that the serial code doesn't dick with it.
Do you have ANY other spare inputs? If so you can diode OR your remaining interrupt signal to one of the other INTs and read the spare pin to see who was the source of the interrupt.
Rob
I want to stay away from PCINT cause I already have things connected to all three ports and i don't want the chip checking which pin it was every microsecond. I could just move things around to make use of PCINT1 but stuff is already soldered in. I'll read over the core libraries to see what register changes are made for Serial.begin, Serial.end, attachInterrupt, and detachInterrup. I would assume it puts everything back the right way. It should work if only one device will be on at a time.
I'm not suggest using a PCINT, just a general IP. You can diode AND/OR two external interrupts and have one of them also go to a GPIO. Then the ISR tests the GPIO to see which one is was. A bit like PCINT I suppose but may work with what you have.
For that matter, if you only use a single PCINT in a group it's the same as an external interrupt in almost every respect, you don't have to test anything.
Rob
... it's the same as an external interrupt in almost every respect
It's only the same if you want to trigger on a change in the input level. You can't specify to trigger only on a low, a high to low, or a low to high. This is hardly the same.
Don
I did say "in almost every respect".
Interrupts are for detecting events and an event (probably by definition although I haven't looked it up) is a change of state. I don't think I've ever wanted to interrupt on a level, only the transition from one level to another. However I concede that there may be reasons to detect a level with interrupts.
Anyway this is all semantics, for all normal uses I see no real difference between an INT and a PCINT if you only use one pin in the group.
Rob