Linux: serial port, Arduino reset, avrdude
please: article howto , needs revision , improvements. thanks.
references:
(1) man page termios(3),
(2) http://www.gnu.org/software/libc/manual/html_node/low_002dlevel-terminal-interface.html#low_002dlevel-terminal-interface
(3) arduino forum articles.
** dtr line , reset arduino **
linux "lower modem control lines" when hangup. hangup implies dtr goes low.
linux hangup serial line when speed set b0 or line closed , hupcl set.
** programming serial port **
serial interface recognize , trasform many special character , events in input , output.
i use following termios flags in order communicate in "raw mode", serial port
does not apply transformations ("non canonical mode").
ignbrk, brkint , parmrk set 0
a break condition in input read linux sequence 0xff 0x0 0x0
istrip set 0
does not strip eighth bit. need whole byte long character.
inlcr, igncr , icrnl set 0
does not translate nl (new line) cr (carriage return) or viceversa.
does not drop cr
ixon set 0
does not software flow control on output, , pass corresponding input characters (xon , xoff) unaltered.
ixoff set 0
does not software flow control on input. not send xon/xoff stop arduino sending data.
opost set 0
does not process (alter, transform) output stream
csize (multibit) set 0 , cs8 set 1
set character size 8 bit.
parenb set 0
disable parity generation on output , checking on input
hupcl set 0
does not lower modem control lines (and dtr) when closing port.
echo, echonl set 0
no echo of character received
icanon set 0
non canonical mode. see reference (1) , (2)
isig set 0
does not raise system signal (see signal(7)) when receiving special character intr, quit etc
iexten set 0
does not implementation specific input processing
vin , vtime set 0 (and icanon set 0)
read function not block , return immediately
permitting asyncronous elaboration.
see ref (2) , man page: select(2).
speed set b9600. if sometime set b0 dtr goes low , arduino reset.
this python snippet, easy translate in c (see examples in reference doc (2)).
import termios
speed = termios.b9600
serial = file(name, 'r+', 0)
ts = termios.tcgetattr(serial)
ts[0] &= ~(termios.ignbrk | termios.brkint | termios.parmrk | termios.istrip | termios.inlcr | termios.igncr | termios.icrnl | termios.ixon | termios.ixoff)
ts[1] &= ~termios.opost
ts[2] &= ~(termios.csize | termios.parenb | termios.hupcl)
ts[2] |= termios.cs8
ts[3] &= ~(termios.echo | termios.echonl | termios.icanon | termios.isig | termios.iexten)
ts[4] = speed
ts[5] = speed
ts[6][termios.vmin] = 0
ts[6][termios.vtime] = 0
termios.tcsetattr(self.serial, termios.tcsanow, ts)
it similar
stty raw ospeed 9600 ispeed 9600 < /dev/ttyusb2
**avrdude**
set serial hangup on close, when avrdude open , close port dtr toggle (arduino reset, bootloader start).
use current avrdude.conf packaged in arduino software (hardware/tools/avrdude.conf)
stty hupcl < /dev/ttyusb2 ; avrdude -v -c avrdude.conf -p m328p -p /dev/ttyusb2 -cstk500v1 -b 57600
about -b 57600: refer .upload.speed in file hardware/boards.txt
marco vaccari
references:
(1) man page termios(3),
(2) http://www.gnu.org/software/libc/manual/html_node/low_002dlevel-terminal-interface.html#low_002dlevel-terminal-interface
(3) arduino forum articles.
** dtr line , reset arduino **
linux "lower modem control lines" when hangup. hangup implies dtr goes low.
linux hangup serial line when speed set b0 or line closed , hupcl set.
** programming serial port **
serial interface recognize , trasform many special character , events in input , output.
i use following termios flags in order communicate in "raw mode", serial port
does not apply transformations ("non canonical mode").
ignbrk, brkint , parmrk set 0
a break condition in input read linux sequence 0xff 0x0 0x0
istrip set 0
does not strip eighth bit. need whole byte long character.
inlcr, igncr , icrnl set 0
does not translate nl (new line) cr (carriage return) or viceversa.
does not drop cr
ixon set 0
does not software flow control on output, , pass corresponding input characters (xon , xoff) unaltered.
ixoff set 0
does not software flow control on input. not send xon/xoff stop arduino sending data.
opost set 0
does not process (alter, transform) output stream
csize (multibit) set 0 , cs8 set 1
set character size 8 bit.
parenb set 0
disable parity generation on output , checking on input
hupcl set 0
does not lower modem control lines (and dtr) when closing port.
echo, echonl set 0
no echo of character received
icanon set 0
non canonical mode. see reference (1) , (2)
isig set 0
does not raise system signal (see signal(7)) when receiving special character intr, quit etc
iexten set 0
does not implementation specific input processing
vin , vtime set 0 (and icanon set 0)
read function not block , return immediately
permitting asyncronous elaboration.
see ref (2) , man page: select(2).
speed set b9600. if sometime set b0 dtr goes low , arduino reset.
this python snippet, easy translate in c (see examples in reference doc (2)).
import termios
speed = termios.b9600
serial = file(name, 'r+', 0)
ts = termios.tcgetattr(serial)
ts[0] &= ~(termios.ignbrk | termios.brkint | termios.parmrk | termios.istrip | termios.inlcr | termios.igncr | termios.icrnl | termios.ixon | termios.ixoff)
ts[1] &= ~termios.opost
ts[2] &= ~(termios.csize | termios.parenb | termios.hupcl)
ts[2] |= termios.cs8
ts[3] &= ~(termios.echo | termios.echonl | termios.icanon | termios.isig | termios.iexten)
ts[4] = speed
ts[5] = speed
ts[6][termios.vmin] = 0
ts[6][termios.vtime] = 0
termios.tcsetattr(self.serial, termios.tcsanow, ts)
it similar
stty raw ospeed 9600 ispeed 9600 < /dev/ttyusb2
**avrdude**
set serial hangup on close, when avrdude open , close port dtr toggle (arduino reset, bootloader start).
use current avrdude.conf packaged in arduino software (hardware/tools/avrdude.conf)
stty hupcl < /dev/ttyusb2 ; avrdude -v -c avrdude.conf -p m328p -p /dev/ttyusb2 -cstk500v1 -b 57600
about -b 57600: refer .upload.speed in file hardware/boards.txt
marco vaccari
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Linux: serial port, Arduino reset, avrdude
arduino
Comments
Post a Comment