Help needed with Arduino Uno interrupt

Hi All,

Firstly I have to say, I am very new to the Arduino, but I'm loving it. I used to do some microcontroller developments some 12 years ago with the 8051, but this is just fantastic.

Anyway, I am trying to utilize one of the hardware interrupts (Pin 2, int0) and I'm finding strange behavior.

I have a 1Hz clock on Pin 2 and a simple serial.println("Test") in the interrupt function. This works fine and if I add more println's it also works fine up to the point where I add a 6th or 7th println in the function, then nothing prints to the serial port at all. I am also trying to query a RTC within the ISR and nothing is printing. The code is below:

void rtc_interrupt()
{
Wire.beginTransmission(0x68);//Send the address of DS1307
Wire.write(0);//Sending address
Wire.endTransmission();//The end of the IIC communication

Wire.requestFrom(0x68, 7);//IIC communication is started, you can continue to access another address (address auto increase) and the number of visits
seconds = bcd2bin(Wire.read());//read time
minutes = bcd2bin(Wire.read());
hours = bcd2bin(Wire.read());
week = Wire.read();
days = bcd2bin(Wire.read());
months = bcd2bin(Wire.read());
Year = bcd2bin(Wire.read()) + 2000;

Serial.print(Year, DEC);//Serial display time
Serial.print('/');
Serial.print(months, DEC);
Serial.print('/');
Serial.print(days, DEC);
Serial.print(' ');
Serial.print(hours, DEC);
Serial.print(':');
Serial.print(minutes, DEC);
Serial.print(':');
Serial.print(seconds, DEC);
Serial.println();
Serial.print(" week: ");
Serial.print(week, DEC);
Serial.println();
}

Am I trying to make this ISR do too much?

Note: all variables have been set as volatile according to tutorials I have read.

Any help to make me understand would be greatly appreciated.

Robbie...

Hi Again,

Sorry, I should have mentioned that this routine works fine in the main loop.

Robbie...

Maybe you should remove all lines from the interrupt routine, and just use a flag to tell your loop to print data when interrupt occurred?

Cheers,
Kari

I have a 1Hz clock on Pin 2 and a simple serial.println("Test") in the interrupt function.

With 1.0+, serial output is interrupt driven. Interrupts are disabled in your ISR, so, doing things that rely on interrupts being active is generally not a good idea.

Thanks everyone for your input, it was enlightening.

GaryP's suggestion worked perfectly, thank you.

Robbie...