1
\$\begingroup\$

I was working on a project in which microcontroller is communicating serially with computer.

Initially it works properly but after some duration (i.e 2-3 hours) microcontroller get hanged.

I think it hangs due to serial communication with computer. To verify it I have written a program to for microcontroller as well as for computer to transmit and receive data serially.

In my program I am first transmitting string of five characters serially from computer. Microcontroller will receive the string and re-transmit the same string to computer. Computer will receive the string transmitted by microcontroller.

Now I have transmitted string and a received string at computer, I am comparing both the strings and if they are same I am writing '1' in a file and '0' if they are different.

I want to know that my process to verify serial port communication is correct or not?

\$\endgroup\$
  • 1
    \$\begingroup\$ Code or it did not happen. \$\endgroup\$ – abdullah kahraman Mar 9 '13 at 12:35
  • \$\begingroup\$ How is it powered? It might be picking up noise from the power supply. \$\endgroup\$ – Leon Heller Mar 9 '13 at 14:43
1
\$\begingroup\$

Long'ish serial wiring may incidentally suffer from bit errors. How about adding a checksum to every message (data frame) you send, so the receiving end can check that checksum and if it is wrong discard the whole data frame, probably asking for a retransmit.

A simple checksum mechanism can be achieved by EOR'ing all bytes in the frame and sending the resulting byte as checksum. The receiving end should be able to calculate the same checksum.

\$\endgroup\$
1
\$\begingroup\$

What you suggest will test that the hardware and basic low level software are working. However, you already knew that since you say it runs for over 2 hours before something stops.

This means you have a bug in something that only happens rarely, like a bit error, overrun, or framing error. What happens under each of these conditions in the micro? The hardware may need to be reset on a framing error or overrun. Are you doing this?

You also have to consider that noise can get into the line. How does your protocol recover when one side receives something a little different than the other side sent? You have to think about these things. You could send data in packets with checksums, ACKs, and retries. You could do some kind of keepalive scheme with automatic reset on inactivity after a timeout. There are lots of ways. These reasons are why its a lot harder to design a good serial protocol than most people seem to think at first glance.

\$\endgroup\$
  • 1
    \$\begingroup\$ If it always is 2hrs, a memory buffer overflow could be a cause too. \$\endgroup\$ – jippie Mar 9 '13 at 17:31
0
\$\begingroup\$

Are you running other stuff on the microprocessor at the same time? If so, try to disable them. If possible, try to use another chip and see if you get the same behavior.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.