2 mega168 with uart hot plug problem

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

I have finish a project who use 2 mega168 at 16mhz the one board is the main circuit and work continues and the other board is the <<commander board >> who user can program various values and is portable so user can program many main boards.
The microcontroller communicate with hardware uart so the tx from one mc go to rx and the rx to tx from the other.
In main board the uart work with urxc interrupt routine.
The problem is when I hot plug the commander with dsub9 connector the main program go to uart interrupt routine and crash.
The only way to work is to power off main board connect the commander and then power on again.
If I do this everything work great but if I disconnect the commander, when it is work, again the main program go to urxc interrupt routine and ofcourse crash.
For the commander I use button when to send data to main board so when i disconnected or connected there is no data from tx to rx.
Also the dsub connector have and the power for commander.Total 4 wires rx,tx + , -
How I can solve this?

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

Patient: Oh, Doctor, it hurts when I do this.

Doctor: Don't do that!

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Hot Swapable USART is doable.

Both should have a Pull-up or pull down resistor on the RxData line, so that when nothing is connected the RxData line won't randomly switch up high and low. Some RS-232 chips include this, some don't.

If you are doing logic level connections then you must provide the pull up or down resistors yourself.

You also need a small series resistor and cap, (RC Filter), on the input for ESD supression, or another method of doing this. Note that this will limit the maximum baud rate, based upon the filter's cutoff frequency.

You then need an intelligent Rx Data routine that can recognize framing/parity/etc. errors and ignore those bytes.

You also, generally, want to packetize your data and include a checksum or CRC with the packets to verify that were received correctly. The data routines should include a software handshake, i.e. and Acknowledge signal is sent back to the data packet sender to verify that the packet was correctly received, or a NAK is sent to say it wasn't received, so please sent it again. Likewise the sender should listen for the ACK signal, and resend the data if it doesn't receive one in a timely manner.

From a hardware perspective one would like the V+ and Gnd leads to connect BEFORE the data signals are connected. One doesn't want the micro being plugged in to have power on the signal lines without having valid V+ and Ground, or it can partially power itself through the signal lines and lock up the micro. Using the WatchDog Timer might be a partial solution to this situation.

JC

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

thank you for your fast answer
My baudrate is 38400 i will try first with pull up for rx pin and pull down for tx.
1kohm is good ?
If I don't hot plug the second mc and power on all at the same time the communication is perfect didnt miss anything.

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

1 k is good.
10 k is better.

Quote:
If I don't hot plug the second mc and power on all at the same time the communication is perfect didnt miss anything.

Thats the point. If the system is hard wired, and always powered, there will be very few noise glitches on the signal lines to interfere with normal communications.

It is when you connect and disconnect the communications link that there will be unexpected glitches on the lines, and the hardware must handle these safely, and the software must be smart enough to recognize them as error states, and ignore them.

JC

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

Ok problem solved with 10k pull up resistor on rx pin.
Thank you