Go Down

Topic: Update I2C reference page (Read 746 times) previous topic - next topic

Keshka

After a day of debugging and finally finding a post in the forum I discover that: "You can't use the I2C routines inside an interrupt service routine(ISR). This is because they use a timer that requires the interrupts to be running and inside an ISR interrupts are disabled."

This should be included on the page http://arduino.cc/en/Reference/Wire

Keshka

retrolefty


After a day of debugging and finally finding a post in the forum I discover that: "You can't use the I2C routines inside an interrupt service routine(ISR). This is because they use a timer that requires the interrupts to be running and inside an ISR interrupts are disabled."

This should be included on the page http://arduino.cc/en/Reference/Wire

Keshka


That's the same reason a simple delay(xxxx) command won't work inside a ISR routine unless you re-enable the global interrupt bit, which can then be a very complex situation where you have nested ISR working. So it's not a fault of the I2C library as such. Even trying to do serial.read inside a ISR will not function.

The general recommendation and practice is that user ISR routines should be as short and simple as possible, just set or reset global flag variables and let the main loop function deal with what that means and should be done. It's like living in a house with lots of people but a single bathroom, do your business and get out.  ;)

Go Up