what i'm going to do is like this.
when i press button (with pull-up resistor) then the program will read the time from RTC print it to serial monitor... as simple as that... could it be able to do?
when i press button (with pull-up resistor) then the program will read the time from RTC print it to serial monitor... as simple as that... could it be able to do?
it's exactly for an example... i have more complex one and it uses I2C in interrupt too.. so i'm trying to use this example to see it's worked or not to have I2C in interrupt...
paulusalexander:
it's exactly for an example... i have more complex one and it uses I2C in interrupt too.. so i'm trying to use this example to see it's worked or not to have I2C in interrupt...
You are probably going to have to change your program flow:
Have the Interrupt Service Routine(ISR) set a flag (volatile bool triggered; )
In the main loop check the flag, clear the flag, service the request
the ISR should be short and sweet. Do not access external libraries, or complex functions. As the previous posters have intimated, interrupts are disabled while inside an ISR, therefore any routine that uses interrupts will hang. (Serial,Wire,delay,...).
Your Wire.requestFrom() is followed by a Wire.endTransmission(). Please remove that second Wire.endTransmission, since the Wire.requestFrom() is a I2C transmission on its own and the Wire.endTransmission() is only to transmit data after a Wire.write().
The Wire.endTransmission() waits until writing all the data to the I2C bus has finished.
The Wire.requestFrom() waits until all the data has been read from the I2C bus.
Therefor you should not use them in an interrupt handler, and don't use the Serial functions in an interrupt handler either.
Do as PaulS and chucktodd say, that is the only way.