ESP8266-01 sends error when trying to upload the code

I have connected an ESP8266 module to the Arduino Mega. When running the AT commands (board set to Mega) some of them work and the others not. When uploading the code to the ESP8266 I recieve this error:

esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

I have tried to update the firmware, but I recieve the same error. The pins are connected like this:
GND - GND
3V3 - 3.3V
TX - TX0 -> 1
RX - RX0 <- 0
EN - 3.3V
How can I solve the problem?

to put the esp8266 in flashing mode, io 0 must be wired to gnd at boot.
is it an esp-01S? because older esp-01 requires to wire the EN pin too and io 0 must be pulled-up over a resistor for normal run.
did you upload an empty sketch to Mega?

Juraj:
to put the esp8266 in flashing mode, io 0 must be wired to gnd at boot.
is it an esp-01S? because older esp-01 requires to wire the EN pin too and io 0 must be pulled-up over a resistor for normal run.
did you upload an empty sketch to Mega?

How can I find out what is my esp8266 version?
It is written just ESP8266EX on it.

andstef:
How can I find out what is my esp8266 version?
It is written just ESP8266EX on it.

version of the module, not the esp8266.

esp-01

esp-01S (there are additional resistors between the header and the chips)

Juraj:
version of the module, not the esp8266.

esp-01

esp-01S (there are additional resistors between the header and the chips)

It is the ESP-01

Ihave connected the IO 0 pin to GND, but nothing changed...

andstef:
It is the ESP-01

then the EN pin must be wired to 3.3 V too

Juraj:
then the EN pin must be wired to 3.3 V too

It is. And it is a mistake in the first post

has Mega an empty sketch uploaded?

Juraj:
has Mega an empty sketch uploaded?

Yes