Hi Guys
I have a HVAC control unit which is based on Atmega324p . This device is connected to other device (Room controller) . I used a serial communication between the devices and every thing ok, but when an electrical noises occur the devices freez.
I send and receive the info by using "Serial.write(buffer, count ); Serial.readBytes(buffer, count );"
I made a simulation in the office (by using a spark generator) and when looking to the communication bits (On the oscilloscope) I had these truths:
1- sometimes, The connection is interrupted but on the oscilloscope the bits have a normal flow .in this
status the loops works normally bus no communication.
2- sometimes,the connection is interrupted and the code freezes ,(I'm planning to use software reset by the
watchdog or something else).
I need to solve this issues by the software (without using any external hardware)
please help me to solve it and thank you very much.
It's not at all clear from your description if the problem is caused by incorrect data being received - incorrect because it has been garbled by interference, OR, if the problem is due to the interference causing the microprocessor to crash.
Serial.readBytes() is a blocking function and is probably not appropriate in a situation where the data flow might be interrupted.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
It makes debugging much easier if you send data in human readable form. I would only send binary data if it was the only way to achieve the required performance.
If you need more assistance please post your two programs.
Does your code properly process and handle bad data, are buffers limited to prevent overflow. Try different power supplies, they could be part of your problem. if the communication wires are more then 1 meter round trip you need buffers, they become great antennas. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil