Hi,
I haven an issue with avrdude (program to talk to Atmel microcontrollers).
In 'ser_posix.c' there is code to set/clear the DTR line similar to this (minimal example):
Code:
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
main() {
int fd, serial;
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NONBLOCK );
usleep(1000000);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR) {
puts("TIOCM_DTR is not set");
} else {
puts("TIOCM_DTR is set");
}
usleep(50000);
serial |= (TIOCM_DTR); // set bit, set line LOW
//serial &= ~(TIOCM_DTR); // clear bit, set line HIGH
ioctl(fd, TIOCMSET, &serial);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR) {
puts("TIOCM_DTR is not set");
} else {
puts("TIOCM_DTR is set");
}
usleep(50000);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR) {
puts("TIOCM_DTR is not set");
} else {
puts("TIOCM_DTR is set");
}
while(1) {
// wait here
}
close(fd);
}
Now it is a verified fact (logic analyzer) that on my system I need to CLEAR the TIOCM_DTR bit to make the physical DTR line go HIGH and vice versa. This low-level code is later used in a function 'ser_set_dtr_rts()'. When this function is fed with '0' the DTR line should be LOW, when fed with a '1' it should set it to HIGH. On my machine this only works with above mentioned inversed register writes. But now there is a patch that inverses this and claims to be correct...
Currently I'm having a discussion on avrdude's site on savannah.nongnu.org about this.
Is the HIGH/LOW business maybe caused by the conversion from RS232 to 5V-TTL-serial?
I was going to ask about this on a suitable linux kernel mailing list, but couldn't find 'the one'.