Electronic – Interrupt Service Routines and I2c together

i2cinterruptspic

I would like to ask a question that has been on my head for a while

I have done coding small ISR's for pic and AVR controllers and i have successfully tested them on board.And i have just learned some days ago that you need to keep ISR short.

So I have this ISR that runs each 2 ms from timer.

Well the doubt I have is If I have an I2c communication running parallel and then the interrupt occurs, What will happen to the I2C communication.

Will the data transmission gets damaged?.

If The ISR takes 2ms to execute, what will happen to the I2C communication meanwhile.

Can it cope with such delays? Or is it my lack of understanding.

Best Answer

The processor won't execute any foreground code during the interrupt. If the IIC is strictly handled in hardware, then that won't matter. If this processor is the IIC master, then it won't matter either since you own the clock and can go as slow as you want (most slaves allow this).

However, a interrupt routine taking 2 ms with other things going on, like IIC communication, at the same time sounds like bad overall architecture. The right answer is to step back and understand what all the processor needs to accomplish, what limited set of things really are low-latency that it must react to, and re-architect the firmware from there. Propagating a bad design by working around previous mistakes just makes things even worse.