OpenWrt Forum Archive

Topic: tplink mr3220: cannot read serial port from WITHIN openwrt

The content of this topic has been archived on 3 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi!

I installed trunk (ar71xx-generic-tl-mr3220-v1-squashfs) rebuild by myself with luci support on a fresh tplink mr3220 (20euro on amazon), everything went smooth. I've also put the router in client (station) mode to be a node of my local network (accessible via wireless as a client). No problems.

Then I've opened the router and soldered three wires to three pins of the serial port (TX, RX and ground) on the mainboard. With some care (voltage conversion is needed, see http://www.hackup.net/2011/09/serial-co … 20-router/ ) I have connected the wires to the TX-RX pins of an arduino board. On the arduino board there's a program running, sending strings to the serial line. Basically I want to receive those lines at the router serial port. But I don't know how. The guy at "hackup.net" suggests simply to use the command "screen" with something like

> screen /dev/ttyS0 9600

if I do that, I see only funny characters or - almost always - nothing at all.

I've also tried with "microcom" but it says that ttyS0 does not respond.

You could say "hey, you've done bad soldering and your serial is not connected!". But I have the proof that *something* is coming from arduino to the serial port. Just doing

>  cat /proc/tty/driver/serial

I get

0: uart:16550A mmio:0x18020000 irq:11 tx:10760 rx:184717 brk:184716 RTS|DTR|DSR|CD

and the numbers after "rx:..." and "brk:...."  constantly grow!!
And if I disconnect the wire going from arduino-tx to router-rx, those number stop to grow!

In summary, data are flowing but I am not able to read them.

Does anyone have any idea how to simply read ascii characters from /dev/ttyS0 ?

Thanks!

normally the console on serial port is already using that port. did you disable it? don't know how it behaves if two push and grab data at the same time on a serial line.

Thanks for your reply. Yes, I did already disable the console association with serial port, i.e. my /etc/inittab reads like this

::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
#ttyS0::askfirst:/bin/ash --login

Unfortunately this is not the problem.

I am missing some (perhaps trivial) piece of information about linux way of reading devices. Why can't I simply read /dev/ttyS0 by using "cat"? Is this because the file must be opened in some way? Let's say that a flow of bytes is coming down through it but the "terminal" emulators cannot interprete it, how can I just see them flowing without any interpretation, only for debugging purpose?

thanks for the hint!

I've installed "stty" (by getting packages coreutils and coreutils-stty)

the command as it is

> (stty raw; cat > received.txt) < /dev/ttyS0

fills "received.txt" with many copies of the same "unreadable" char, basically a black-on-white "@"

if I disconnect the wire coming to rx, the same command leaves "received.txt" empty

this is a great progress

still I cannot say to have learnt how to debug the serial port

I see that "stty" is full of options: does anyone have idea on how to get something more readable? tried iutf8 and cs8 and also ignbrk (this "brk" is something I do not understand: the /proc/tty/driver/serial message tells that - apart from rx bytes, also hundreds of "brk" per seconds come down... what are they??)

sorry for my ignorance, any help appreciated!

forgot that I can just scan the received.txt file with some program by myself (e.g. a c-code converting char in ascii codes and/or hex/binary), looking bit-by-bit the streaming and debugging it, i.e. understanding what is the format and how can be set the port to interprete it

will do next week...

andreo73 wrote:

forgot that I can just scan the received.txt file with some program by myself (e.g. a c-code converting char in ascii codes and/or hex/binary), looking bit-by-bit the streaming and debugging it, i.e. understanding what is the format and how can be set the port to interprete it

will do next week...

if you haven't solved yet, a hint for you:

To get the serial connection work reliably, you have to connect a 10k pullup resistor between the TX and the 3.3V pin. This is because the TX pin is connected to a voltage divider (2x5.6k) and a capacitor is put between the real pin and the TX connector.

next time, just read the wiki wink

you're right, I forgot that point, thanks! now I cant move on, no resistors and shops closed, have to wait for monday smile

anyway I did originally read that info on the wiki, but 1) havent understood it; 2) the webpage where I learnt the project ( http://www.hackup.net/2011/09/serial-co … 20-router/ ) did not mention it, so I assumed it was not important

indeed I would like to have it better explained: it is said that tx is connected to a voltage divider (2x5.6k) and also a capacitor is put between the pin and the real connector; my questions are

1) can you sketch such circuit? I'm not sure I've understood it: is that something like   "TX PIN" ----  CAP. ----  o -RESIST------  GND (or 3.3V??)
                                                                                                                                                                |
                                                                                                                                                               RESIST
                                                                                                                                                                |
                                                                                                                                                            "REAL TX CONNEC."
or something different (e.g. the second resist  directly in series with capacitor and pin)??

2) in such configuration, the capacitor should not simply act as cutting high frequencies (e.g. low pass)? is that a problem? what about the capacity value?

3) why putting a 10k resistance betw TX and 3.3V should help?

4) most importantly: why should I care for the "tx" line if I am just trying to use the "rx"? (I mean, for this 1st step I am just trying to read data coming down to the router and not the opposite)

infinite thanks for the help

ciao

a

I've also discovered a note on the wiki, end of the page:

<<With MR3220 v1.2 and CA-42 just connect TX, RX and GND, do not need any resistor>>

Yes, I am using the v1.2! But no, I'm not using any serial hack adapter. So: what is my situation? do I need the resistor?

hmmm.....

This message is just to say that - most likely - I will not insist in this task, it is perhaps too complicate with respect to my original purpose

I've just managed to read the serial port THROUGH THE USB connection: arduino pushes the serial data through an ftdi driver into the usb line and the router can read it; for openwrt: it is necessary to install usbserial package with ftdi support

then you can use "microcom" (other openwrt package) with option -D/dev/ttyUSB0  and works smooth

thanks for the help

ciao

I had a little different problem (solved):
- I bought an USB device with 28 I/O ports (some analogue, some digital, etc.)
- It simulates a serial over USB (more precisely it created /dev/ttyACM0 after some module installed)
- With microcom -D/dev/ttyACM0 I can read the result if
- I push out command with another terminal, like echo '~adc0~' >> /dev/ttyACM0
- BUT I got nothing if I would like to replace microcom, like: cat /dev/ttyACM0
BECAUSE these are buffered IO and waiting for enter (cr).

I use microcom for testing and
made perl script for automation.

have a nice day mike...

The discussion might have continued from here.