2560 PCINT pins

I hope I have done my home work.

My plan uses pins 18&19 for Modbus communication with a Solar Charge Controller. Pins 20&21 for I2C communication with a PFC8574, ADS1115 and INA2228. Pins 50,51&52 for SPI communication with an RTC3234 (CS pin 48) and a SDcard (CS pin 49).

I have avoided using Pins 0 &1 (RX TX) due to a prior statement

I will be continually using if (Serial.available(). I presume that might cause a conflict.

I need two interrupts for the RTC3234 & the INA228. It appears that I have run out of hardware interrupts. Based on the following statement:

The schematic appears to expand on the number of PCINT pins:

If this is true , I could use D14 (PCINT0) for the INA228 interrupt and A15 (PCINT2) for the RTC3234,

Yes, acording to my Atmel ATmega2560 documentation it is true :slight_smile:

(And Atmel made those chips, while Arduino just use them in some simplification)

Conflict with what? Serial.available() checks if data is available on UART0 (USB or TX0/RX0).
The only reason why you would use Serial.available() is to check for data so from your description to check if there is data from a terminal program (e.g. serial monitor).
If you're afraid that interrupts might be interfering with each other, there is a always a chance but that is not because of Serial.available(). If an interrupt is handled all other interrupts are blocked; so your interrupt service routines should be very short (time wise). Once the interrupt service routine is finished another interrupt can be handled.

If you don't use TX1/RX1 you can also use those pins; they are INT2 and INT3 (not to be confused with PCINT2 and PCINT3).
In that case you don't have to determine the source of the interrupt (rtc or ina) in the ISR, the interrupt identifies the source.

I thought source identification applied to only to those pins within the PCINT group. As I would only be using 1pin from the PCINT0 group and 1 pin from the PCINT2 group, I would think that would be unnecessary. Am I correct?

You are correct. What put me on the wrong foot is that you circled TX3/RX3 which are in the same PCINT group and I did forget that you mentioned A15.

but you don't have anything conneced to RX/TX, so no problem

You cannot specify rising or falling for the pin change interrupts and that make the code a little tricky to get working.

DS3232 RTC is an I2C device and NOT SPI device.

If it is Official Hardware (as category suggest), then on RX,TX is connected USB convertor.

That is correct but why are you pointing that out?

This is the picture (obtained from the official schematic of Arduino MEGA) of the external hardware interrupts of the MCU:

DPin-21        INT0/SCL
DPin-20        INT1/SDA

DPin-19        INT2/RXD1
DPin-18        INT3/TXD1

DPin-2         INT4
DPin-3         INT5

------         INT6
-----          INT7

You can safely use INT4 and INT5.

@GolamMostafa explanation of the mapping is not what the Arduino software uses.

As you can see INT4 and 5 are used by pins 19 and 18 so they are not available since you use then for modbus

As per schematic (Fig-1), the physical interrupt pins of the 2650 MCU for INT4 and INT5 are physically connected throug copper tracks of the PCB to DPin-2 and DPin-3 of the edge connector. I don't understand how software can chnage these permanent connections.


Figure-1:

At suitable time, I will do physical test verify the connection. I will be using the following method to attach DPin-2 with INT4.

attachInterrupt(digitalPinToInterrupt(2), ISRINT4, FALLING);

It doesn't but it can give any name it wants to any pin so the software int4 does not have to correspond to the hardware INT4

This explains:
https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/#interrupt-numbers

Except for uploads; OP referred to another post of yours :wink:

???

Apologies. OP stated that he stayed away from Tx/Rx because it interferes with the upload as you pointed out.

From the following line of the above link, I undrstand that the argument of digitalPinToInterrupt(pin) is asking for the DPin-# at which the INT4-pin of the MCU is connected.

"Normally you should use

digitalPinToInterrupt(pin)

, rather than place an interrupt number directly into your sketch."

And NOT

attachInterrupt(4, ISRINT4, FALLING);  //4 for INT4

No you understand that wrong
You are overcomplicating things, it very simple.
You just give it one of the available 6 pin numbers that you want to use as an interrupt.

Let me verify physically what I have understood.