Jun 16, 2013

Raspberry Pi serial communication

Since I was tinkering with Pi network settings, sometimes I was loosing SSH connectivity.
Annoying process of hooking Pi to display and keyboard forced me to look for a serial connection option. This way I will just have to switch between two terminal windows, instead of messing with the cables.
I've got a dongle named "USB 2.0 to TTL Uart 5-Pin CP2102 Module Serial Converter", based on reviews it should work in this configuration.



Description says TTL, which usually means 5V signal levels, but in fact Rx/Tx lines shows 3.3V.
Computer recognized the device as:
$system_profiler SPUSBDataType
...
            CP2102 USB to UART Bridge Controller:
              Product ID: 0xea60
              Vendor ID: 0x10c4  (Silicon Laboratories, Inc.)
              Version: 1.00
              Serial Number: 1
              Speed: Up to 12 Mb/sec
              Manufacturer: Silicon Labs
              Location ID: 0xfa130000 / 6
              Current Available (mA): 500
              Current Required (mA): 100
...
For this device to be detected as serial port on the PC side drivers needed. After installing the drivers, two new devices appear (on OSX):
$ ls /dev/*SLAB*
/dev/cu.SLAB_USBtoUART /dev/tty.SLAB_USBtoUART
Hooking up the Pi:

Only G(ground),R(rcv),T(trx) pins are needed.
Ground connects to ground, R connects to TXD, T connects to RXD.

To open serial terminal on OSX:
$screen /dev/tty.SLAB_USBtoUART 115200 8N1
Where 11520 is a bit-rate expected by Pi, and 8N1 - 8 bits, No parity, one stop bit.


To see the real signal levels I hooked this up to a scope:

And here how the space (0x20) looks on the wire

Yellow channel is PC transmit, and blue - receive. Since I'm in terminal, my input is echoed back. The bits are sent from low to high order, so 0010000 (0x20) actually becomes 00000100.

No comments: