I tried connecting them via a level shifter, to be able to run the Atmega328p at 5V, since it drives a few relays. But, also, for the sake of testing, tried running it at 3.3v, to avoid using the level shifter, in case that was the cause of the issue.
The issue is, the ESP8266 will go crazy in an endless power cycling loop whenever I have the atmega328p connected to the I2C bus in the ESP8266. By the way, I have a OLED LCD in the same bus in the ESP8266.
I also observed the same behavior when connecting both via UART, but I can easily go around it by having the ESP8266 power the atmega up whenever it is ready. I can't do the same when using I2C, because the ESP8266 will go crazy as soon as I plug the SCL and SDA lines. So, it doesn't work if they are already plugged when starting up, or if connected after power on.
I have an option in the board I made to enable a pull-up resistor on SDA and SLC lines. Both, same results whether the pull-up is enabled, or not.
Does anyone have a suggestion on how to wire them via I2C?