LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-17-2013, 03:33 PM   #1
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Rep: Reputation: Disabled
What is UART


What is UART and how can I use it to detect the transmission of bytes of data (sending / receiving) in c?
 
Old 12-17-2013, 03:39 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,610

Rep: Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703
Serial ports used to be popular on PCs to connect to modems, printers or other PCs. These days they have disappeared in favor of the more flexible USB port. A UART is the device used to implement a serial port, see here:
http://en.wikipedia.org/wiki/Univers...er/transmitter

In linux, the first serial port device is typically /dev/ttyS0 and the procedure for using it would be found in the Howto:
http://www.tldp.org/HOWTO/Serial-HOWTO.html
 
1 members found this post helpful.
Old 12-17-2013, 03:43 PM   #3
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
Serial ports used to be popular on PCs to connect to modems, printers or other PCs. These days they have disappeared in favor of the more flexible USB port. A UART is the device used to implement a serial port, see here:
http://en.wikipedia.org/wiki/Univers...er/transmitter

In linux, the first serial port device is typically /dev/ttyS0 and the procedure for using it would be found in the Howto:
http://www.tldp.org/HOWTO/Serial-HOWTO.html
That would be correct and that is what I am using now. I am using a PPP modem to dial out to a 3G connection and I'd like to monitor the sending and receiving of data via UART.

Also, the link for: http://www.tldp.org/HOWTO/Serial-HOWTO.html does not seem to be working...
 
Old 12-17-2013, 04:13 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,610

Rep: Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703
If you just want to capture the PPP traffic, you can use wireshark.
 
Old 12-17-2013, 04:26 PM   #5
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
If you just want to capture the PPP traffic, you can use wireshark.
Which I have done. However, the point of this is to create a program that monitors the traffic and lights up an LED when either sending or receiving traffic using the GPIO in linux (its an embedded device with an ARM processor and a linux kernel, kind of like a Raspberry Pi...)
 
Old 12-17-2013, 04:32 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
We would need a bit more information, such as how exactly the PPP modem is connected to the system. UART is a generic term for the asynchronous serial protocol, but there are several subsets with different voltage levels. There's 1.8v UART, 3.3v UART, 5v UART, RS-232 (which works on 12v negative logic), etc. Is the PPP modem currently connected to the UART? Is it RS-232 or one of the more "embedded-friendly" 1.8-5v styles? Or is the PPP modem connected through another means and you just want to sniff for activity using a UART?

If all you want to do is light up an LED then there's no need to get more complicated than hooking up a couple of LEDs with current limiting resistors to the TX and RX lines directly (possibly through a couple of FETs if the LEDs draw too much current for the device outputs to handle directly).

Last edited by suicidaleggroll; 12-17-2013 at 04:36 PM.
 
Old 12-17-2013, 04:38 PM   #7
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
We would need a bit more information, such as how exactly the PPP modem is connected to the system. UART is a generic term for the asynchronous serial protocol, but there are several subsets with different voltage levels. There's 1.8v UART, 3.3v UART, 5v UART, RS-232 (which works on 12v negative logic), etc. Is the PPP modem currently connected to the UART? Is it RS-232 or one of the more "embedded-friendly" 1.8-5v styles? Or is the PPP modem connected through another means and you just want to sniff for activity using a UART?

Sure, let me give you as much as I know (as of now)
the PPP modem is connected using a mini-PCIe interface.

I did a dmesg | grep tty and the output reads:
GSM modem (1-port) converter now attached to ttyUSB0
GSM modem (1-port) converter now attached to ttyUSB1
GSM modem (1-port) converter now attached to ttyUSB3
GSM modem (1-port) converter now attached to ttyUSB4
GSM modem (1-port) converter now attached to ttyUSB5

it uses picocom to dial out and connect, so it's serialized in that manner. As for the voltage, it must be 1.8-5v... although don't count me on that

And yes, I just want to sniff for activity using UART, just to see if the device is sending data or receiving data, and then put some logic together to tell which GPIO to turn on to indicate via LED going high/low "Yes/no, the device is/is not sending data" or "Yes/no, the device is/is not receiving data"
 
Old 12-17-2013, 05:03 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
I was under the impression the PPP modem was connected via a UART on your board, or at least had a serial interface that you could tap into with one of your available UART ports, but it doesn't look like that's the case. How do you connect to it with picocom?

If you can find a line on the board that cycles with Tx or Rx activity you could run it to FET to drive an LED directly, but you'd need to watch out which line you're grabbing so the FET's capacitance doesn't degrade the signal.

Last edited by suicidaleggroll; 12-17-2013 at 05:04 PM.
 
1 members found this post helpful.
Old 12-17-2013, 05:11 PM   #9
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
I was under the impression the PPP modem was connected via a UART on your board, or at least had a serial interface that you could tap into with one of your available UART ports, but it doesn't look like that's the case. How do you connect to it with picocom?

If you can find a line on the board that cycles with Tx or Rx activity you could run it to FET to drive an LED directly, but you'd need to watch out which line you're grabbing so the FET's capacitance doesn't degrade the signal.

Actually, my mistake, it's calling pppd and dialing out with that, not picocom.
from pppd, I see that it's trying to open ttyUSB0 with a specific baud rate and then slips in the username, password, APN and number.
 
Old 12-17-2013, 05:18 PM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You might be able to write a middleman program or kernel module that sits between pppd and ttyUSB0. Any writes from pppd to your program get forwarded on to ttyUSB0 as well as triggering a Tx GPIO, and any reads from pppd read from ttyUSB0 as well as triggering an Rx GPIO.

I don't have a good idea where to start with that though.

There's also the usbmon utility discussed here, which may or may not let you get what you're after:
https://mail.netsweng.com/pipermail/...st/001663.html
http://tjworld.net/wiki/Linux/Ubuntu/USBmonitoring
 
1 members found this post helpful.
Old 12-17-2013, 05:24 PM   #11
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
You might be able to write a middleman program or kernel module that sits between pppd and ttyUSB0. Any writes from pppd to your program get forwarded on to ttyUSB0 as well as triggering a Tx GPIO, and any reads from pppd read from ttyUSB0 as well as triggering an Rx GPIO.

I don't have a good idea where to start with that though.

There's also the usbmon utility discussed here, which may or may not let you get what you're after:
https://mail.netsweng.com/pipermail/...st/001663.html
http://tjworld.net/wiki/Linux/Ubuntu/USBmonitoring
Thanks SuicidalEggRoll, that's kind of what I have right now, but it's more abstract, I going 'brute force' and calling ifconfig with the interface of ppp0 and extracting the RX and TX data as integers and comparing it to see if they increased, and if so, write to the GPIO. And this is done every second, but this is extremely inefficient...

and as for not having a good idea where to start, I'm in the same boat. It's proven very difficult to see where exactly I could start with this. I tried going down to the driver level, but that just proved to be a total nightmare.
 
Old 12-17-2013, 05:32 PM   #12
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
The fact that you get a ttyUSB0 when you plug it in tells me two things that might be useful:

1) While it has a PCIe physical interface, it's using the USB connection over that interface (pins 36 and 38, described here http://electronics.stackexchange.com...what-does-this).

2) That the modem is likely communicating through a USB->UART bridge. USB on the PCIe side, UART on the internal side.

If you can find the bridge (find pins 36 and 38 on the connector, see where they go, look for a chip labeled "FTDI"), you should be able to look up the data sheet and get the pinout. I bet you'll find a regular UART interface on the other side that you can tap into to directly drive the LEDs or run to a pair of available UARTs on your board (one to monitor the Rx line and one to monitor the Tx line).
 
1 members found this post helpful.
Old 12-17-2013, 05:49 PM   #13
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
The fact that you get a ttyUSB0 when you plug it in tells me two things that might be useful:

1) While it has a PCIe physical interface, it's using the USB connection over that interface (pins 36 and 38, described here http://electronics.stackexchange.com...what-does-this).

2) That the modem is likely communicating through a USB->UART bridge. USB on the PCIe side, UART on the internal side.

If you can find the bridge (find pins 36 and 38 on the connector, see where they go, look for a chip labeled "FTDI"), you should be able to look up the data sheet and get the pinout. I bet you'll find a regular UART interface on the other side that you can tap into to directly drive the LEDs or run to a pair of available UARTs on your board (one to monitor the Rx line and one to monitor the Tx line).
In regards to #1, thanks! that will help point me in the right direction. So I would just need to probe those pins?

as for #2 I'm not exactly too sure about bridges or where/how they would exist in the linux OS

and regarding the FTDI chip, I'm looking at the board closely, and I don't seem to see anything labeled FTDI or anything close to that, however I am still looking.

EDIT: Confirmed, there is no FTDI chip on this board. It's probably integrated in another chip somewhere else...

Last edited by RET80; 12-17-2013 at 06:01 PM.
 
Old 12-17-2013, 06:32 PM   #14
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
That's unfortunate, like you said the USB-UART interface must be handled internally on another device. FWIW, this is the type of device I was referring to:
http://www.mouser.com/ProductDetail/...b85Lsxog%3d%3d

There could be an interface IC from another brand, but FTDI is the big dog in that realm.
 
1 members found this post helpful.
  


Reply

Tags
data, serial, uart


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where does uart console get its value of uart port membase? unifoxz Linux - Kernel 1 12-20-2011 03:28 PM
LPC47M10x UART Niraj Kulkarni Linux - Hardware 0 02-07-2011 05:08 AM
LPC47M10x for UART Niraj Kulkarni Linux - Newbie 0 02-02-2011 04:12 AM
UART : Unknown iceman911 Linux - Hardware 1 06-23-2005 11:14 PM
uart pantera Programming 5 05-21-2005 07:50 PM


All times are GMT -5. The time now is 06:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration