[Solved] who else uses INT0 on MEGA2560 ?

Hello every body
It’s my first try on a forum so I hope i will do the things good

I have connected a PCF8523 Real Time Clock to an ARDUINO MEGA2560 like this :
!(http://C:\Documents and Settings\Administrateur\Mes documents\Mes images\RTC MEGA Diagram.JPG)
(OOps I didn’t succeed to upload the picture…)

But it is simple:
The SDA and SCL signals of the RTC are connected to A4 and A5 using I2C communication.
And the alarm signal of the RTC ‘INT’ connected to Digital pin 2, which is Interruptable, and according to the many docs and searches I did on the Web triggers an INT0.
The communication with the RTC works well, and I can read and ajust time with my interface

and when I disconnect the wire from the RTC INT to the MEGA pin2, I can see on a scope that the alarm signal stays HIGH and goes LOW after the 10s timer I programmed in the RTC.

But even though it is disconnected, I have a permanent call to my interruption routine… :fearful:

My question: What else in the Arduino background routines uses INT0?
Could the I2C routine interfere?

thanks for any suggestions

How to post an image

I don't know the answer to your question but from your description I don't think you need an interrupt. Poll the input every time around loop() and take action when it changes.

Do you need tutorials to help?

I have connected a PCF8523 Real Time Clock to an ARDUINO MEGA2560 like this :

The SDA and SCL signals of the RTC are connected to A4 and A5 using I2C communication.

The SDA and SCL pins are not A4 and A5 on a Mega. They are the SDA and SCL pins by the Aref and extra ground terminal (by pin 13) or pins 20 and 21.

How is the interrupt from the RTC configured? If it is open collector, do you have a pullup on the pin?

How is your interrupt configured? Post your code.

First thank you very much PerryBebbington : I am new to forums, and I didn't find this tutorial for uploading pictures, thank you for the link!

groundFungus : I am confused by your remark concerning SDA and SCL pins.
I started my project on an UNO and needed to upgrade to a MEGA due to a lack of memory and pins.
On the UNO A4 is shorted to SCL and A5 to SDA next to the Aref pin, as you say.
It is still working on the MEGA and according to you It should not!

So I studied more in detail the schematics of the RTC Shield I implemented on top of my MEGA, and bingo, you are right: the SDA and SCL reaches the RTC not via A4 and A5, but via SCL and SDA on pin 20 and 21!
Thank you for your remarck! this frees the A4 and A5 pins for other uses!

Concerning the Interruption: as you can see on the diagram (I succeded to insert it in my post thanks to PerryBebbington)

the interruption signal of the RTC is indeed open collector, and I pull-upped it with a 8.2K (out of stock of 10K).
I monitorred this signal on a scope and I see it going up after initialisation and going down after my 10s alarm request.
This leads me to think that electronicaly it seems to work normally.
My code is very long so I try some extraction of the meaningfull parts:
And I am French, so sorry for the French comments…

This is the include and var definition part

#include <RTClib.h>//C:\Documents and Settings\Administrateur\Mes documents\Arduino\libraries\RTClib-master
RTC_PCF8523 rtc;//pcf8523 sur Adafruit Datalogger shield rev B
//variable pour l'alarme
#define PIN_ALARM_RTC 2
volatile Pcf8523TimerState RTC_etat_TIMER;
volatile bool AlarmRTC = false;
DateTime DateDerniereAcquis;

this is the initialisation part:

  rtc.writeSqwPinMode(PCF8523_OFF);//pas de signaux carrés sur INT1_
  digitalWrite (PIN_ALARM_RTC, HIGH);//just to be sure it start at HIGH
  RTC_etat_TIMER.enabled = true;/** whether the timer is running */
  RTC_etat_TIMER.value = 10;/** the current value of the timer */
  RTC_etat_TIMER.freq = PCF8523_Freq_second;/** the clock divider used */
  RTC_etat_TIMER.irupt_state.irupt_flag = false;/** the timer's interrupt state */
  RTC_etat_TIMER.irupt_state.irupt_enabled = true;//on active l'IT donc on desactive CLKOUT
  rtc.write_timer(PCF8523_Timer_Countdown_A, &RTC_etat_TIMER);
  attachInterrupt(PIN_ALARM_RTC, onAlarmRTC, FALLING );//ne marche pas CHANGE

And this is my IT routine

void onAlarmRTC() {
  AlarmRTC = true;

In my main loop

void loop(void){
  if (AlarmRTC){
    Serial.println("Alarme RTC :");

if (AlarmRTC) triggers always …

Heuuuurgl! as I wrote this post, I discover that nowhere in my program the boolean ‘AlarmRTC’ is set back to False…
I think that was the problem!
… I feel so confused,

Formulating correctely the question, is halfway to answering to it

But my first question remains: which functions (delay, PWM , I2C, or other I don’t know) uses INT0 which might interfere with other ?

Thank you again for all your usefull remarks!
And really sory to use your time on my mistakes!

There is no need to disable interrupts in the ISR. Interrupts are automatically disabled in an ISR.

if (AlarmRTC){
    Serial.println("Alarme RTC :");

Where do you clear the AlarmRTC flag? Once it is set (true) in the ISR it will stay true until cleared (to LOW or 0).

It is OK to post snippets if you also include the whole code so we know how everything is tied together.

But my first question remains: which functions (delay, PWM , I2C, or other I don't know) uses INT0 which might interfere with other ?

None of those things effect INT0.

Thanks groundFungus for your quick reply!

Ok for the no need disable interrupts in the ISR, I will correct that.

Concerning INT0 I think I confused with PCINT0 : I don't understand what's the difference between them
I found some website that says that the INT0 is internal and PCINT0 is external:
But on a MEGA INT0 is on pin21 and PCINT0 on pin 53, both external ...?

Concerning the interferrence you say that "None of those things effect INT0 "
But for example this French site

says that the delay() function will not work and that the millis() function wil not increment.
Is it incorrect?
or something more wise I didn't understand?

Another thing I don't understand : PCINT3 and INT0/INT1 seems to be attached to pin 2 and 3 of the Arduino: when a signal will arrive on that pin, which INT will be triggered?
Which one should I use ?

I understood that if I use a delay() function, then I should not use INT0 but PCINT3 instead so that there should be no interference. Apparently it is wrong: can you explain what I don't understand?

Thank you again.

The Arduino reference page on external interrupts. The Mega has 6 hardware external interrupts (INT0 to INT5).

Pin change interrupts are also external interrupts. There are differences. The ISR for a PCI (Pin Change Interrupt) is called when any pin on the port changes. One then has to find which pin on that port caused the interrupt. Not all pins on a Mega are PCI capable. PCIs must be set up before use. This page explains PCI setup.

Your “PCI setup” link clarified me !

the table 12.6 is very clear:

I can see now why you told me no interference with other functions, since timer 0,1 and 2 are on different vectors:
I confused between interruptions, vectors, and pins…

now it is clear!

Thank you so much!

Have a nice day,

…and I hope the COVID-19 did not do any problem for you!

.and I hope the COVID-19 did not do any problem for you!

Nor you. I am an old retired guy who enjoys staying home anyway so, no, no problems.

Concerning the Interruption: as you can see on the diagram (I succeeded to insert it in my post thanks to PerryBebbington)

I cannot see any reason to use interrupts at all for what you are doing. I have not read your code in detail but for an alarm if the code is well written with no blocking code then polling the input will detect the alarm condition from the PCF8523 Real Time Clock just fine.