I got an issues from few days, got some code which reset millis time on successful i2c communication, if not it restart an relay after specified period of time. Here is part of the code:
if ((unsigned long)(i2c1Millis1 - i2cpreviousMillis1) >= i2cset1 ) // check if not restarted soon
i2c1Millis1 are updated every run of the loop and on successful i2c communication.
i2cpreviousMillis1 is updated on successful i2c request (coming from interrupt)
I manage to debug when false restart occur and looks like
i2c1Millis1 is lower than
So question is: can an interrupt occur while those two millis are compared when value of
i2c1Millis1 is taken for compare and then come interrupt where
i2cpreviousMillis1 is updated to current millis and it become greater and trigger the condition?
(I already modified my code
i2cpreviousMillis1 is updated with
i2c1Millis1 value on successful communication to prevent that, but it is not working, from time to time it made false restarts).