I have a weird issue with I2C (Master) generated code. Sometimes the generated function 'I2C_MasterSendStart' fails (even if the bus is free) with error code 'I2C_MSTR_NOT_READY'. I've found 'strange values' of the 'I2C_state' variable on such occasions. With 'strange values', I mean values (like, for instance, 0xD2) that, looking at the whole generated code, it cannot assume (memory corruption or am I missing something?).
Again, in such occasions, if I reset it to its default value (namely 'I2C_state = I2C_SM_IDLE;') then the I2C communication works again.