Good afternoon, I am trying to communicate my UNO with an atmega328p microcontroller. The project I am trying to do is a led that is working according to data that I am sending from the UNO to the microcontroller which is controlling the LED. I cannot find out how to "tell" the microcontroller that data are going to be imported. The atmega328p is running every time the void ReceiveEvent, I want to run only the void loop and when I press a button that is controlled from the UNO, the UNO to send data to the microcontroller, microcontroller inserts the new data(brightness, blink mode) and blink according to the new data. Thank you a lot in advanced. Sorry for my bad english.
Are you using 2 UNOs? Or, one UNO as Master and one ATmega328P chip as Slave?
How many buttons are you using at the Master side to input your data/command? In which digital pins are they connected?
In Arduino I2C Management, the rceiver section is interrupt drive. So, whenever a data byte arrives at the receiver (TWDR Register) due to the execution of Wire.write() command at the Master, the Wire.onReceive() message is triggered which in turn calls upon the user-defined ReceiveEvent() routine. So, in the setup of the Slave codes, you must initialize the Wire.onReceive() function with the subroutine name as its argument.
There is also Wire.onRequest() message which is triggered in the same way as the Wire.onReceive(); but, this time it is triggered due to the execution of the Wire.requestFrom() command at the Master side.
If you are learning the I2C communication protocol, use two UNOs and keep practicing some simple data communication examples.