I am an absolute beginner of programming AVR microcontrollers. My programming equipment is based on Atmel Studio IDE combined with the ATMEL-ICE programmer. I am writing to you, not just to start being part of this community, but because I am trying to make some more complex and useful experiments.
Problems I'm facing are related to the communication of an ATMEGA328P-PU with a WI-FI module ESP8266-01 via UART .I post some pictures, very simplified, which represent the circuit and the connections between ESP8266-01 and the micro Atmega328P. In the diagram, I have eliminated all that is necessary to allow the ATMEL-ICE programmer to load the executable into the micro. The ESP8266 module is equipped with the following pinout: TXD, RXD, VCC, CH_PD, GPIO_0, GPIO_2, RSTn. The module must be powered with 3.3V and also the RXD channel must receive a voltage of 3.3V. To allow the RXD to receive a voltage of 3.3V from the TXD pin of the Atmega328p, a small voltage divider has been realized with two resistors: one with 10KOhm and one with 20KOhm. The TXD channel of the WIFI module is connected directly to the PD0 (RXD) of the ATMel328P.In the images, you see the power represented by conventional batteries, but in reality, I use a 9V power supply that is transformed by a breadboard power supply module capable of delivering voltages of 5V and 3.3V. The WIFI module turns on, but the problem occurs during serial communication through UART port.
In addition I set the microcontroller to work with the internal clock at 8Mhz.
In your opinion, are the connections wrong? I publish the code, which for honesty is taken from useful publications on the internet, and only adapted since it was conceived for the Atmega16. I changed the reference to some registers and bits. I realize that I pose a vast and challenging question at a distance. The main problem is why the begin () method remains hanging indefinitely. In response to the answer, assuming that it is a real answer, not knowing if and what was received by the WIFI module that never finds correspondence with the string that represents the answer of "OK". Lacking of skill and experience, I have tried to make some debugging attempts, but in fact the values that come back are fundamentally improper. I ask you, with utmost gratitude, support, advice on how to solve these problems, or how to approach the integration of a WIFI module in a circuit that mounts a standalone ATMEL microcontroller.
Thank you very much