Mega 2560 Rev3 DTR (solved)

Hey all,

I have a bit of C code that opens a serial port with the correct settings and everything, does some communication with firmata and then optionally close the port. Below I'll paste my arduino_close() function. I get the desired behavior on my UNO and my 3 Mega rev2's; that is, when the port is closed, DTR is raised and the board resets.

However, on the Mega rev3, with the exact same host code and the exact same sketch that works with my other arduinos above, on close, the board does not reset and the TX light is solid. I've been researching linux/windows serial and modem programming extensively for the last few months and I think I may be missing something that the rev3 expects. I am just not sure. My code though has been working for about 1.3 years without an issue on multiple arduinos without issues/this problem; it looks like it just effects Mega 2560 rev3.

Here is my close function:

void arduino_close(){
  tcflush(fd, TCIFLUSH);
  tcdrain(fd);
  usleep(1000000);
  tcsetattr(fd, TCSANOW, &settings_orig);
  close(fd);
  fd = 0;
}

Like I said above, this works perfectly on my UNOs and older Mega 2560s ; the port gets closed and the original TTY settings restored and the board gets reset.

Any help would be appreciated. Thanks.

This might be a side effect of the rev3 change to the auto-reset circuit. A diode was added from reset to +5vdc to deal with a very intermittent reset latch up condition that was discovered a year or so ago on 328p based boards. Without the diode the original auto-reset would happen on both the rising and falling of the DTR signal, where as after the diode the reset would only happen on the falling of the DTR signal. Being a active low control signal, closing a com port will result in DTR going false (high) on the arduino board and not cause a reset pulse like the older boards would. That's my theory anyway.

A quick test you could try to validate or disprove this theory is to temporarily install a diode in one of your older non rev3 boards. Just insert a diode into the reset and 5V pins on the shield connector with the cathode on the 5v pin. Then see if the older board doesn't then behave like your rev3 board does. This diode addition was also added to the Uno rev3 boards.

Lefty

This is exactly the info I was trying to find. Mind pointing me to the place where you got this info from (the change log from rev2 to rev3)? I would love to read through it and try and learn some stuff. When I get a diode over the next week I'll be sure to come back let you know if you're theory is correct. Thanks a ton!

So, my knowledge on this stuff is pretty capped right now. Any way you know of to force a DTR falling on a port? Seems like there is a standard model for opening the port and settings the comm settings. Not sure If at any point I can just effect a setting. I'll run some experiments in the mean time. Thanks.

ac_slater:
This is exactly the info I was trying to find. Mind pointing me to the place where you got this info from? I would love to read through it and try and learn some stuff. When I get a diode over the next week I'll be sure to come back let you know if you're theory is correct. Thanks a ton!

Well I participated in a long thread on the originally report of a repeatable reset latch up problem over a year or so ago, and several people participated in trying to recreate the symptom, one published scope pictures pointing out the possible cause and someone came up with the diode addition as a fix. The arduino folks took some time but did confirm the intermittent latch up possibility was real and then when they released their rev3 boards they included the diode addition. The only 'official' arduino mention of the fix I've ever seen was the rather terse description of the Rev3 changes on the Uno hardware page:

Revision 3 of the board has the following new features:
1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage provided from the board. In future, shields will be compatible both with the board that use the AVR, which operate with 5V and with the Arduino Due that operate with 3.3V. The second one is a not connected pin, that is reserved for future purposes.
Stronger RESET circuit.
Atmega 16U2 replace the 8U2.

Lefty

Thanks for everything. I found out that lowering DTR DOES fix the issue I was having.

void arduino_close(){
  tcflush(fd, TCIFLUSH);
  tcdrain(fd);

  int bits = 0;
  bits &= ~(TIOCM_DTR);

  if(ioctl(fd, TIOCMSET, &bits) < 0) {
    fprintf(stderr, "Failed to lower DTR on close.");
  }

  usleep(1000000);
  tcsetattr(fd, TCSANOW, &settings_orig);
  close(fd);
  fd = 0;
}

Thanks again man.