I2C communication (Wire) receiveing all messages two time

Strange proble, I've a master and a slave that communicate using Wire.requestFrom to ask for a message depending to a message sent from master to slave, slave auto responding with a specific message.

The problem is that when I send a message, slave answer ok, if I send another message (different from first) I receive from slave the previous message another time.

Who can help me?


Post the code for both the I2C master and the I2C slave, if possible reduced to the minimum necessary to demonstrate the problem.

Most probably a problem with the interrupt context. The I2C answer is sent inside an interrupt handler. All variables used there and in the main routine must be declared volatile. You must not call any routine that depends on interrupts there (as for example Serial.print()).

SOLVED seems the pèroblem was the use of Wire.readBytes function, using instead a cicle with Wire.read until data are available now all is perfect!