Problem UART COMUNICATION ATMEGA328P-ESP8266-01

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

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

Attachment(s): 

Last Edited: Sun. Dec 16, 2018 - 10:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry but how is this an ARM related question? Maybe I'm missing it, otherwise we need to move the thread.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sorry, surely I wrong. I did not realize that section is specific for ARM MCU. Could you please indicate to me which is the more appropriate section. I am not sure that problem I am facing is strictly a hardware issue or software. Considering this doubt which section, for AVR MCU, do you suggest?
I'm sorry for the mistake.
Thank you so much

 

Bye

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll move it for you.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear,

thank you so much and sorry again!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No crystal or resonator for the mega328 - you'll most likely have communication problems. Look at the Arduino uno schematics.

 

No capacitors - the mega328 wont be happy and the EP8266 is even more demanding. You've eliminated too much!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The first thing to do is run the AVR at 3.3v to eliminate the level differences.

Than you will need a xtal or resonator to provide an accurate and stable clock source for the AVR needed for successful serial comms, I would suggest one of the baud rate friendly ones like 7.3728MHz.

Now it is much easier to work with only one unknown at a time, so use a USBSerial TTL cable and connect to the TXD/RXD/GND pins of the AVR and get it working first,

before you add in the ESP8266 module, let the PC act as the target first so you can troubleshoot your comm issues.

Once the AVR is working, then you can use the PC via the USB Serial cable to work out what the ESP8266 needs to do.

Than, connect the two micros together!!!

 

You will find using an Arduino module, like a nano or pro-micro will be easier to work with on a bread board, and cheaper than a bare M328 as it provides all the needed caps, xtals, and programming interface.

 

Good luck with your project.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

No crystal or resonator for the mega328 - you'll most likely have communication problems. Look at the Arduino uno schematics.

 

No capacitors - the mega328 wont be happy and the EP8266 is even more demanding. You've eliminated too much!

 

Hi Kartman,
I'm wronging, I realize. But, I had believed that internal oscillator to 8 Mhz it was enough. I have suspected that an external Crystal was needed. I will attempt mount an external crystal at 16Mhz. However, just now, it comes to mind how should I indicate to atmega328 that have to use external Crystal and not internal oscillator? I am reading the datasheet of atmega series, I believe I have to set CKSEL0 Fuse. However, I am still confused on how to set their values. I know that exist low, medium and high Crystal. Should I consider a 16Mhz Crystal  like low? Can I set it during  microcontroller programming in Atmel Studio? In the menu "Device Programming" on the fuse tab? What is the correct option that I must select? What do you mean when you say "No capacitors - the mega328 won't be happy, and the EP8266 is even more demanding."?which capacitor are you referring ? The ones of the oscillator or should I need additional one for ESP8266-01? 

I thank you, and I apologize for the many questions, but the reading of the datasheet is still long ...

Thank you very much.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

codabat wrote:
?which capacitor are you referring ? The ones of the oscillator or should I need additional one for ESP8266-01?

An Arduino Nano has all the caps you need for this project and is cheaper then a bare chip, and has all the correct fuse settings too....

Here is the schematic with the bare essentials you will need, note this uses a resonator that has built in caps, if you use a xtal you will need to add two 12-20pf caps to gnd a shown in the schematic.

 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Mon. Dec 17, 2018 - 09:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

The first thing to do is run the AVR at 3.3v to eliminate the level differences.

Than you will need a xtal or resonator to provide an accurate and stable clock source for the AVR needed for successful serial comms, I would suggest one of the baud rate friendly ones like 7.3728MHz.

Now it is much easier to work with only one unknown at a time, so use a USBSerial TTL cable and connect to the TXD/RXD/GND pins of the AVR and get it working first,

before you add in the ESP8266 module, let the PC act as the target first so you can troubleshoot your comm issues.

Once the AVR is working, then you can use the PC via the USB Serial cable to work out what the ESP8266 needs to do.

Than, connect the two micros together!!!

 

You will find using an Arduino module, like a nano or pro-micro will be easier to work with on a bread board, and cheaper than a bare M328 as it provides all the needed caps, xtals, and programming interface.

 

Good luck with your project.

 

Jim

 

 

Dear Jim,
thank you for your valuable advice.
I try to summarize my first experiments with UART communications.
I have started with FT232 USB, that simulates a serial port on my pc. In this case, at the beginning it was all ok, then trying to increase the baud rate and  I have realized that internal oscillator at 1 Mhz was not enough. Then I have to remove the clock divider to do run the microcontroller at 8Mhz and so the communication is back good. I have believed it was enough to attempt to use another UART device as ESP8622-01. However, I had wrong!

If I have not misunderstood, do you advise me to send the AT commands for the basic ESP8622-01 configurations first through the USB FT232 from the PC and then connect ESP8622 at the microcontroller? I apologize if I did not understand correctly. I understand your advice to use Arduino, but I would like to come to a deeper understanding of the architecture and operation of a microcontroller. Another reason why I do not want to use Arduino is the need to get to make some devices for sale and with custom PCBs and designed independently. Of course, I will have to add an external crystal, I currently have a crystal of 16Mhz, do you believe is it okay?
So, summarizing, you advise me to communicate correctly PC and ESP 8622-01 module before connecting atmega328P with the ESP8622-01 wifi module?
You are very kind, thank you so much,

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

codabat wrote:
I understand your advice to use Arduino, but I would like to come to a deeper understanding of the architecture

All I'm suggesting is examine the Arduino as a h/w design reference, note the use of bypass caps on VCC/AVCC and a filter for AREF.

And suggesting the breadboard friendly versions are preferred to bare chips.

 

For serial comm, the AVR needs an accurate and stable clock source, the internal R/C osc will work but drifts with temperature and VCC level.

A xtal works much better, and required for commercial products, you will need to set the fuses to use an external xtal and tell the toolchain what freq it is, i.e. F_CPU value for proper delays and timings.

 

You were successful with the internal r/c to your PC, due to the precise baud rate of the PC, but the baudrate tolerance of both the ESP8266 and AVR may be off more the can be tolerated.

See the tables of example baud rate settings and note the error % of your chosen xtal and baud rate and pick one with a low error rate for best operation with the ESP8266.

Note: some xtal frequencies have 0% error.

 

Good luck wth your project

Jim

 

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try running both the ATMEGA328P and ESP8266 from 3.3V. According to the specification sheets, a HIGH input to the ATMEGA328P is 0.6 * Vcc minimum. A HIGH output of the ESP8266 can be as low as 0.8 * Vcc. So The ATMEGA needs at least 3V as an input high when Vcc is 5V but the ESP8266 running at 3.3V may output less than 2.7V. If that happens, the ATMEGA328P will not hear the ESP8266. Run them at the same voltage, no problem.

 

If you have to run the ATMEGA328P at 5V, you can change levels with 2N7000 or similar. See This link This is a circuit I used between 5V PIC and 3.3V GPS. One of the inputs used the internal pull up resistor so no extra resistor required.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

codabat wrote:
I understand your advice to use Arduino, but I would like to come to a deeper understanding of the architecture

All I'm suggesting is examine the Arduino as a h/w design reference, note the use of bypass caps on VCC/AVCC and a filter for AREF.

And suggesting the breadboard friendly versions are preferred to bare chips.

 

For serial comm, the AVR needs an accurate and stable clock source, the internal R/C osc will work but drifts with temperature and VCC level.

A xtal works much better, and required for commercial products, you will need to set the fuses to use an external xtal and tell the toolchain what freq it is, i.e. F_CPU value for proper delays and timings.

 

You were successful with the internal r/c to your PC, due to the precise baud rate of the PC, but the baudrate tolerance of both the ESP8266 and AVR may be off more the can be tolerated.

See the tables of example baud rate settings and note the error % of your chosen xtal and baud rate and pick one with a low error rate for best operation with the ESP8266.

Note: some xtal frequencies have 0% error.

 

Good luck wth your project

Jim

 

 

Hi Jim, I'm sorry if I answer you so late. I've been a little busy. You were very clear; I immediately put to work following the suggestions that you are giving me. I keep you informed! But first of all, I thank you for the patience and kindness with which you wrote to me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Rookie,
thank you, also for your indication and for your in-depth analysis.
I'll apply just now all this information that all of you gave to me.
I will inform you.
Thank you so much!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear friends: js, Kartmanki0bkajcashin
I was a bit busy, and I could not update you. Your advice has been constructive, and now the problems I have exposed to you are solved, and everything works correctly.
I wish you a happy new year.

Thank you very much.
See you soon.