I'm having an issue with serial communication between an ATMega328 and an ESP8266.
I built a custom pcb board which is working ok, at least related to other aspects of operation.
The ATMega performs most of work, read sensor and an interrupt button, also display data in a screen.
ESP822 mostly deploy a web interface for configuration of the whole system and show system status through web.
Both ICs comunicate through serial at 9600 bauds.
My problem is, after some days of working ok (a week or more), ESP8266 stops being able to communicate through serial port. It doesn't react when data arrives to it (which trigger some actions at the ESP side) and it stops sending data to ATMega328 which happens every hour.
I can access the webpage served by ESP. And look into serial communication, using USB/Serial connected to my PC. I can see ATMega sending data to ESP, ESP ignores it.
When reseting, everything backs to normal.
Does any one have any suggestion about how to solve, investigate or anything that helps on getting serial communication to works as espected, I mean allways, forever ?
how have you interfaced the ESP to the ATMega328? give use a schematic of the wiring?
the ATMega328 uses 5V logic the ESP8266 3.3V logic - connecting an output directly from the ATMega328 to the ESP8266 can damage the latter
Sadly I cant share the code. Its too extense and sort of privative. Sort of, because its for a "product" I'm developing. But, most of it is just known parts of ESP8266 usual code.
For the connection and the voltage. I just connect them directly (crossed) and both of them are working 3.3v.
By now, hopefully this week. I'll re-start developing the code. I'll isolate strictly necessary parts and look how it behave.
x
Does this mean you have a bug on an confidential board with a confidential sketch?
If you can't share your board/sketch you might look to get help from a freelancer after he signed an NDA:
Thanks. I know its a naive position to ask for help here, not being able to share code and schematics. Please sorry me, it was a frustrating time to me last night.
But what you said is first clue to me. I understand nobody it's experiencing the same issue, and ESP serial comm works forever.
That might be, or not. The reason code sharing is suggested is because there's a reasonable likelihood that your receive code has one or more bugs that survive until a particular set of conditions arise, whereupon the code hangs, goes silent, or garbles the data, leading to your problem. But since we can't see it, we can't determine whether or not you've got bulletproof code. So I guess, you're on your own.
I'd like to say, as a background, that for ESP: Sketch uses 443804 bytes (42%) of program storage space.
Global variables use 38104 bytes (46%) of dynamic memory.
In my experience, reaching 60% or so on an ATMega328, results on some misbehaving.
So, I wonder if there's some experience on how much memory capacity is a limit for the ESP.
Bear in mind, a 5V level signal output into a 3.3 level signal input, with no level shifter, may not fail for a long period of time, but it is undoubtedly beyond the manufacturer's tolerances so is a very bad idea. In the meantime, it's quite possible that, as a result of random electrical noise impulses, the input will experience lockups that it may or may not recover from without a reset/power down. Also remember, it will probably only fail permanently when it causes you/your company/your customer the most embarrassment or grief; that's just a natural expression of Murphy's law. I'd listen carefully to people who have design experience; many of them reside on this forum. "It works today, it'll work forever" is not a design parameter, it's an expression of faith. Suit yourself.
As for memory use, it's so entirely dependent on program design and use of dynamic structures, that it's impossible to tell you "yes" or "no". I can write a program for my Nano that will consume 5% of memory at compile time, and fall to it's knees in the first iteration of loop() if I so choose. Or, write a program that consumes 80% at compile, and runs forever.
I've had serial running on 2 ESP8266s for weeks and months on end without issue. If you want specific advice the petered need to see code, schematics and photographs.