I'm in need of an extra interrupt on a project that's based on an arduino Mega.
I'm already using interrupts 0 and 1 (digital pins 2 and 3). My project uses the SDA/SCL pins (for reading and writing to an SD card), so that rules out interrupts 2 and 3 (pins 20 and 21).
The only other interrupt pins left to me are shared with serial ports, which leaves me a bit stuck (perhaps)
However, one of the serial ports is used for incoming data only, i.e. I only use RX (pin 19). Is it ok to 'split' the function of this pair of pins? Can I continue to receive serial data on port 1, whilst at the same time attaching an interrupt to pin 18 (interrupt 5)?
My guess is that as soon as I initialize port 1 with Serial1.begin() then both pins are reserved for communication, and any attempt to attach an interrupt to one of them would cause problems.
Can I continue to receive serial data on port 1, whilst at the same time attaching an interrupt to pin 18 (interrupt 5)?
I don't think so - but I could be wrong.
My guess is that as soon as I initialize port 1 with Serial1.begin() then both pins are reserved for communication, and any attempt to attach an interrupt to one of them would cause problems.
I think you're right, but can't you experiment and see what happens?
If you want to do anything strange with the Hardware serial ports you will have to modify the HardwareSerial library (because that's where the interrupt vectors are assigned) and if you study the code in the library you should be able to figure out if it is possible to separate the Rx and Tx activities.
If you don't feel competent to modify HardwareSerial then I think the answer to your question must be NO.