I have to test two independent systems using two Arduino boards (MEGA 2560). I was thinking to use one of them as master and the other as slave. I saw there exists codes for slave and master separately. Is it possible to control the slave board uniquely from a master code? Or the slave board should have uploaded a piece of code to receive the master commands?
With respect to the communication master-slave, the i2C identifier to communicate both boards is registered within the code? I mean, can I change the slave identifier as my wish (I know there is a limit of 120 ids)?
if you want a multi master I2C environment - all bus masters members have to be multi master. Otherwise the non Multi Master could interfere the communication.
If you google about "multi master I2C arduino" you will find only some examples. I didn't dig very deep on that topic, but to be honest - I would stick to a strict single master concept or would change the bus technology (i.e. SPI or CAN).
As far as I understood your use case, you can still achieve your requirement with a single master I2C concept: just pull information from the master from the slave asking "do you have new information for me" on regular basis or use an separate (interrupt) GPIO so the slave can give a signal, "hey master I have something new for you" and then let the master ask the slave.
Is it possible to control the slave board uniquely from a master code?
Yes, but not without uploading code on the slave too.
Or the slave board should have uploaded a piece of code to receive the master commands?
Yes, that's necessary, as without it the slave board doesn't know what to do with master commands, it wouldn't even listen to the master.
With respect to the communication master-slave, the i2C identifier to communicate both boards is registered within the code?
Yes, but the code can read it from anywhere. That can be the flash memory, the EEPROM memory, it may even get it over the serial interface but in that case it won't communicate with the other board until it received the ID.
I mean, can I change the slave identifier as my wish (I know there is a limit of 120 ids)?