Using interrupts and wire library?

hi, I am trying to use an interrupt to call a function which uses the wire library, but it seems to crash at this point. Is it not possible? Eg i try this:

function i try to call:

void gettime() { // Below required to reset the register address to 0. Wire.beginTransmission(104); Wire.send(0x00); Wire.endTransmission();

Wire.requestFrom(104, 7); second = Wire.receive(); minute = Wire.receive(); hour = Wire.receive(); day_of_week=Wire.receive(); day = Wire.receive(); month = Wire.receive(); year = Wire.receive(); }

and where i attach interrupt:

attachInterrupt(0, gettime, CHANGE); //red wire

i can use interrupts for simple things like in the example, and my function gettime() works when not called from an interrupt. Is it because wire lib uses intterupts? any ideas would be welcome.

thanks gazzy

Wire does use interrupts.

Best thing to do is to set a flag in your interrupt service routine, and then call that function from your main loop depending on the value of the flag. This way your ISR runs quick, and you have a better chance of not missing any other interrupts if you’re using them.

thanks will give that a try, took me ages to realise that might be why it wasn’t working! at least now I know :slight_smile: