OLED display (ssd1306) works fine with Arduino Uno, but it doesn't work with standalone ATmega328 extracted from the same Arduino Uno board. However blink sketch for LED D2 works with or without Arduino board connected, which I suppose means that power circuit and microcontroller are connected right. I can't understand what is wrong with I2C bus.
Here is my scheme. I also tried to remove R2, R3 pull up resistors, still no sign of OLED.
Thanks for your answer. Yes, everything is fine with code, some lines crossed where they should not in pcb layout, so I solved the problem. Everything works fine now
As you noticed, we did not see a big problem. Just a few details that needs to be fixed. You didn't show a photo or PCB layout, so I hope that the crystal with the two 22pF capacitors is close to the ATmega chip. The GND of the 22pF capacitors should be close to a GND pin of the ATmega chip.
The I2C bus was not designed to go through a cable. It can not deal with crosstalk between SDA and SCL. The worst possible situation is a flat ribbon cable with SDA next to SCL.
The I2C bus is a weak bus, the high level is created with pullup resistors.
Some see the word "bus" as assume that they can use the I2C bus to push data into a cable and that data comes out at the other end. The I2C is the opposite of that.