You are not logged in.

#1 2014-05-26 18:33:08

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

How to install and use the CP2102 USART to USB Converter?

First off, I did a quick search and found that some people had had success in that the cp210x driver was already installed on their machines. I did a modprobe and it returned nothing (not an error).

I searched around on the net a bit and found a very useful USART to USB converter bridge (http://www.nexuscyber.com/cp2102-usb-to … Mgod5UQAdQ). The CP2102 is a programmable device with many settings insofar as the data framing is concerned. As such, a driver for the device must be used to interface and modify these parameters.

On the Silabs website I found this driver (http://www.silabs.com/products/mcu/page … ivers.aspx) for linux (kernel > 3.x.x). The problem is that this driver is just a single C program with zero documentation. An include make file is about as useful considering it has a single line in it that fails (for me) at run-time.

    obj-m = cp210x.o
    KVERSION = $(shell uname -r)
    all:
    	make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
    clean:
    	make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

The driver source can be found here (http://pastie.org/private/kulx2zqdyvkafoxekwjq)
Where my make error is

    
make -C /lib/modules/3.14.4-1-ARCH/build M= modules
make[1]: Entering directory '/usr/lib/modules/3.14.4-1-ARCH/build'
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
In file included from scripts/kconfig/zconf.tab.c:2537:0:
scripts/kconfig/menu.c: In function 'get_symbol_str':
scripts/kconfig/menu.c:587:18: warning: 'jump' may be used uninitialized in this function [-Wmaybe-uninitialized]
     jump->offset = strlen(r->s);
                  ^
scripts/kconfig/menu.c:548:19: note: 'jump' was declared here
  struct jump_key *jump;
                   ^
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
scripts/Makefile.build:44: /usr/lib/modules/3.14.4-1-ARCH/build/arch/x86/syscalls/Makefile: No such file or directory
make[2]: *** No rule to make target '/usr/lib/modules/3.14.4-1-ARCH/build/arch/x86/syscalls/Makefile'.  Stop.
/usr/lib/modules/3.14.4-1-ARCH/build/arch/x86/Makefile:185: recipe for target 'archheaders' failed
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory '/usr/lib/modules/3.14.4-1-ARCH/build'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

If I do not sudo make I just get this:

  .probe  = usb_serial_probe,
            ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:165:16: error: 'usb_serial_disconnect' undeclared here (not in a function)
  .disconnect = usb_serial_disconnect,
                ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_get_config':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:321:3: error: implicit declaration of function 'dbg' [-Werror=implicit-function-declaration]
   dbg("%s - Unable to send config request, "
   ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_open':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:430:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_close':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:451:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_get_termios':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:534:17: error: invalid type argument of '->' (have 'struct ktermios')
    &tty->termios->c_cflag, &baud);
                 ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_get_termios_port':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:556:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_change_speed':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:706:21: error: invalid type argument of '->' (have 'struct ktermios')
  baud = tty->termios->c_ospeed;
                     ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_set_termios':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:735:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:740:22: error: invalid type argument of '->' (have 'struct ktermios')
  cflag = tty->termios->c_cflag;
                      ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_tiocmset_port':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:871:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_tiocmget':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:910:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_break_ctl':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:932:36: error: 'struct usb_serial_port' has no member named 'number'
  dbg("%s - port %d", __func__, port->number);
                                    ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c: In function 'cp210x_init':
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:989:2: error: implicit declaration of function 'usb_serial_register' [-Werror=implicit-function-declaration]
  retval = usb_serial_register(&cp210x_device);
  ^
/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.c:996:3: error: implicit declaration of function 'usb_serial_deregister' [-Werror=implicit-function-declaration]
   usb_serial_deregister(&cp210x_device);
   ^
cc1: some warnings being treated as errors
scripts/Makefile.build:314: recipe for target '/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.o' failed
make[2]: *** [/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source/cp210x.o] Error 1
Makefile:1274: recipe for target '_module_/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source' failed
make[1]: *** [_module_/home/branden/Desktop/Linux_3.x.x_VCP_Driver_Source] Error 2
make[1]: Leaving directory '/usr/lib/modules/3.14.4-1-ARCH/build'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

There is no documentation aside from:

  • make ( your cp210x driver )
    cp cp210x.ko to /lib/modules/<kernel-version>/kernel/drivers/usb/serial
    insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko
    insmod cp210x.ko

Can anyone provide some guidance on the steps to install this driver (or at least where to look) and why there is such a lack of documentation? Are there assumptions here that I am not aware of? How is anyone suppose to use this? If you look in the source there are structures being used as arguments to functions that are never defined as far as I can tell. Perhaps they are part of the header files included at the top, but I could not find some of those on my machine either.

Has anyone had success using this device?

Offline

#2 2014-05-26 18:40:44

loqs
Member
Registered: 2014-03-06
Posts: 2,765

Re: How to install and use the CP2102 USART to USB Converter?

if you did

modprobe cp210x

and there was no error then you loaded the driver successfully (there is such a driver in the kernel package)
it should then be listed if you do

lsmod

edit:
should add modprobe would also exit without error if the module was already loaded ( due to auto detection and it did not need to do anything )

Last edited by loqs (2014-05-26 18:46:20)

Offline

#3 2014-05-26 18:47:31

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

lsmod has:

cp210x                 15558  1 

So the driver must be installed? Sorry for my ignorance. There is still virtually no information on how to use the device. I plugged the usb device (containing the cp210x IC) and found it to create /dev/ttyUSB0, but that is about as far as I have gotten.

I also successfully accessed the device's descriptor information using a libusb program I wrote:

*** USB Descriptor ***
Silicon Labs
Number configurations: 1
Device class: 0
VendorID: 4292
ProductID: 60000
Max power: 50
Number interfaces: 1
	Number alternate settings: 1
		Interface number: 0
		Number endpoints: 2
			Descriptor type: 5
			Endpoint address: 129
			Descriptor type: 5
			Endpoint address: 1

Last edited by sherrellbc (2014-05-26 18:48:58)

Offline

#4 2014-05-26 18:49:04

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

There is a driver for the cp210 compiled as a module in the default Arch Linux package.

From make menuconfig:

  ┌──────────────────────────── Search Results ─────────────────────────────┐
  │ Symbol: USB_SERIAL_CP210X [=m]                                          │  
  │ Type  : tristate                                                        │  
  │ Prompt: USB CP210x family of UART Bridge Controllers                    │  
  │   Location:                                                             │  
  │     -> Device Drivers                                                   │  
  │       -> USB support (USB_SUPPORT [=y])                                 │  
  │ (1)     -> USB Serial Converter support (USB_SERIAL [=m])               │  
  │   Defined at drivers/usb/serial/Kconfig:132                             │  
  │   Depends on: USB_SUPPORT [=y] && USB [=m] && USB_SERIAL [=m]           │  
  │                                                                         │  
  │                                                                         │  
  │                                                               

Does that module not load?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#5 2014-05-26 18:51:35

Trilby
Forum Fellow
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 17,245
Website

Re: How to install and use the CP2102 USART to USB Converter?

You likely don't even need to modprobe it.  I have one of these converters and I have not installed or built any additional drivers.  When I plug it in it shows up as /dev/ttyUSB0 which also has symbolic links in /dev/serial/

EDIT: oops - this was rather slow - all this has been covered.

What is it you need to know about how to use it?  You read and write to the /dev/ttyUSB0.  You can use something like picocom/minicom if that helps.

Last edited by Trilby (2014-05-26 18:53:48)

Offline

#6 2014-05-26 18:53:40

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Trilby wrote:

You likely don't even need to modprobe it.  I have one of these converters and I have not installed or built any additional drivers.  When I plug it in it shows up as /dev/ttyUSB0 which also has symbolic links in /dev/serial/

EDIT: oops - this was rather slow - all this has been covered.


Indeed I do have /dev/ttyUSB0 creater upon inserting the device, but I cannot find any documentation on how to use it (i.e. data frame settings and passing through/receiving data).

ewaller wrote:

There is a driver for the cp210 compiled as a module in the default Arch Linux package.

From make menuconfig:

Does that module not load?

I am not sure what you mean by this. Where must you navigate before running make menuconfig?

Last edited by sherrellbc (2014-05-26 18:55:49)

Offline

#7 2014-05-26 19:06:51

Trilby
Forum Fellow
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 17,245
Website

Re: How to install and use the CP2102 USART to USB Converter?

sherrellbc wrote:

I was looking on the net how to open and talk to ttyUSB0, but have had little success. I was looking to create a custom program if that is possible. Any direction on how to open and "talk" to tty devices?

I haven't done much coding for "pure" serial devices, but AFAIK, these act just the same.  Basically you'd use `open` to open the ttyUSB0, and `fcntl` + `tcsetattr` to set the attributes to the file descriptor, then `read` or `write` as needed.  Each of these functions have man pages.  I had some example code for working with one of these to take input from switches and control some LED's (and motors in one set up), but I haven't worked with it in a while and I'm not sure where it's gone.  It's buried on my backup disk somewhere.

EDIT: these are all the C functions - I'd bet python has some good libs for working with these if that's more your flavor, but I don't know much python.

Last edited by Trilby (2014-05-26 19:11:07)

Offline

#8 2014-05-26 19:08:05

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

Forgive me, I don't really have a good feeling for your experience, so I do not know if I am not understanding something profound, or if you may be missing some fundamental concepts of Linux.  Bear with me smile

On Linux, use stty to control the port characteristics.  Baud, Parity, Word Size, Stop Bits, etc...    Other than that, reading and writing are just streaming files.  From the console, you can redirect output to /dev/ttyUSB0 and it will send data out the port.  eg:  ls -l / > /ttyUSB0

You might also fire up a serial terminal emulator like gtkterm for an interactive session with whatever is attached to the port.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#9 2014-05-26 19:13:10

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

sherrellbc wrote:

[I am not sure what you mean by this. Where must you navigate before running make menuconfig?

I really did not mean anything.  That is a make of the kernel itself.  I run custom kernels, so I always have the latest kernel source handy.  I was just checking that we provide the module you need.  The point is, when you plug the device in, I would expect the kernel I found to be loaded automatically.  Does the module appear in the output of lsmod after you attach the device?  I think it does, because the device node is instantiated.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#10 2014-05-26 19:24:06

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Trilby wrote:

Basically you'd use `open` to open the ttyUSB0, and `fcntl` + `tcsetattr` to set the attributes to the file descriptor, then `read` or `write` as needed.

I will look into this. In the mean time I installed picocom and am trying to get that to work. My only concern is getting the default framing configuration for the device and changing these parameters. How are these parameters accessed and modified?

ewaller wrote:

Does the module appear in the output of lsmod after you attach the device?  I think it does, because the device node is instantiated.

A quick look into the output of lsmod has:

cp210x                 15558  1

And when the device is plugged in I have a new file, ttyUSB0, created in /dev.

Do you have a good resource for learning how to open tty devices and communicating bidirectionally?

Last edited by sherrellbc (2014-05-26 19:29:56)

Offline

#11 2014-05-26 19:35:58

Trilby
Forum Fellow
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 17,245
Website

Re: How to install and use the CP2102 USART to USB Converter?

I just found python has the library "serial" which would make a lot of the steps I described much simpler.

But this does not get into framing - that is an entirely different level of the code, and it has nothing to do with the hardware (well, the need for it may have to do with the hardware, but there is nothing hardware specific in it).  Any means of framing you'd use with code for other serial devices would apply here.

There are undoubtedly many libraries to implement various protocols - but this all depends on what you are hooking up to on the serial end of this adaptor.  For all of my tinkering with these things, I just wrote my own - but these were very simple applications.  Both the "read" and "write" functions read/write blocks of a specified size.  You can set things up also to block until data of a certain size is available.  Further, you could come up with your own protocol for verifying data integrity and implement it as you wish.  But from the sounds of your questions, there is an existing protocol that you wish to interact with.  In that case, any existing protocols should have libraries available to implement them.

So the documentation you are looking for has nothing to do with this UART - you just need to check out the communications protocol documentation.

EDIT: You may find this blog, and the author's previous posts linked within it, useful.

Last edited by Trilby (2014-05-26 19:39:32)

Offline

#12 2014-05-26 20:09:24

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Really as of right now all I am trying to do is communicate via UART from an AVR microcontroller to my PC. I purchased this cp210x UART to USB converter bridge to facilitate this goal. I may move on to move complex things like dumping eeprom or what have you, but currently I am just trying to get some simply character strings sent between PC and AVR.

It is proving to me non-trivial, at least for someone not very experienced much very much linux. I have a program running right now on the AVR that is simply waiting for a single character to come through UART. I then have it interfaced with an LCD screen to display this character. In this way I will know that I at least have simplex communication working.

The problem I have right now is that I do not know the default framing parameters for the cp210x device (i.e. baud rate, # stop bits, character size, parity) in order to get this working. Ideally of course I would like to configure this device to work as requested (i.e. various baud rates), but I am trying to get the simplest program working right now.

I installed picocom as you suggested but was not very pleased considering it was all via terminal and there was no gui to work with - this makes it much easier right now before I get acquainted with the communication steps. I may move back to picocom once I get this working. I then installed gtkterm as suggested by ewaller, but still I have not been able to successfully send anything across to the controller. The assumption is right now that using these serial terminals (picocom/gtkterm) will automatically configure the device when such parameters are set within the program itself. If that is true, I have precisely matched the parameters of the serial programs with the UART setup I have on the controller but nothing has worked just yet.

Baud: 9600
Parity: none
Stop bit: 1
Char size: 8

Last edited by sherrellbc (2014-05-26 20:10:26)

Offline

#13 2014-05-26 20:12:34

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

I suggest you install and run Gtkterm.  Select the port and set  the communication parameters using the GUI.  Characters you type in the terminal will be sent to the AVR.  Characters sent by it will be displayed in the window.  Get this working, then lets explore CLI stuff

If you really need to to do this from the CLI, read man setserial

Last edited by ewaller (2014-05-26 20:13:54)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#14 2014-05-26 20:26:06

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

ewaller wrote:

I suggest you install and run Gtkterm.  Select the port and set  the communication parameters using the GUI.  Characters you type in the terminal will be sent to the AVR.  Characters sent by it will be displayed in the window.  Get this working, then lets explore CLI stuff

If you really need to to do this from the CLI, read man setserial

I absolutely agree. I have been working on this very thing the past 30 minutes or so. I have downloaded and successfully installed gtkterm, but am having issues with it. In order to open usb devices (and presumably tty devices) I must run the programs as root. When I do that I get:

[branden@localhost ~]$ sudo gtkterm
Control signals read: Input/output error

And the gui opens. I then configure to the frame parameters I mentioned a few posts up (being the exact same parameters I have setup the AVR to use). The AVR is currently programmed to only accept characters and display them on an LCD screen. I also have an LED that should toggle whenever I receive a byte of information via UART; this LED is never toggled and consequentially nothing is written to the LCD screen.

The terminal of gtk periodically displays "?" characters. Unless the converter is doing something funny, I am not sure where any communication is coming from because the AVR is passive.
yaeFR4u.png

I wrote the uart library the AVR is using, so I know it works properly; testing was successful between two AVR devices.

Last edited by sherrellbc (2014-05-26 20:32:00)

Offline

#15 2014-05-26 20:31:36

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

We will work on the permissions for /dev/ttyUSB0 later.   Let's isolate the problem.  Unplug the AVR from the adapter, then, on the adapter, shunt pin 2 to pin 3 with a jumper.  That attaches Tx to Rx.  Then type in Gtkterm and see if you get a loop back of what you type.  Also, is it possible that you have Tx and Rx going to your AVR swapped? You might need a null modem.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#16 2014-05-26 20:34:03

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Indeed, the loop-back test is working fine. What do you mean by a null-modem?

Offline

#17 2014-05-26 20:39:00

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

https://en.wikipedia.org/wiki/Null_modem

There are two flavors of serial devices Data Sets (Modem, Mainframe Computers) and Data Terminal (Serial Terminals, Printers, "IBM PC" serial ports).  You can plug a Data Terminal straight into a Data Set.   If you try to plug a data terminal into a data terminal, then the Tx signals are hooked together and the Rx signals are hooked together.  To make things work, you need a cable that swapts Tx and Rx so that one Tx talks to the other Rx, and vise-verse.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#18 2014-05-26 20:47:08

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Actually, as an EDIT I must same something has been tricking me into thinking it was now working.

The loopback test without the AVR works as expected. With echo on and the TX/RX not shorted together I get a single character. In contrast, if the pins are shorted together I get double characters printed to the screen. Therefore, it appears to me as if it was working. I reprogramming the AVR to take a byte via UART, send it back and also write to the LCD screen (each time a character comes through).

The loopback test with the AVR appears to be working strangely. Basically, send a character over from gtkterm and send back a capital A every time. However, I get a double character print to the screen as expected (same as before), but not what I send. Actually, I just the exactly character send to the AVR returned (when it was actually hard-coded as 'A'). If I unplug the AVR and send characters nothing is returned to gtkterm, so no second character is printed.


---------------------------------------------
Not sure what is going on at all.
In summary, I have echo on within gtkterm (which means the character I type and the character I receive gets printed - therefore double characters are printed on success).

No AVR connected:
- Loopback prints two characters to the screen with converter's RX/TX shorted together
- Loopback prints only character to screen when RX/TX not shorted together
Loopback test appears to be working fine.

AVR Connected (converter TX -> AVR RX, AVR TX -> converter RX). AVR is programmed to send back character it receives
- Loopback test prints two characters when connected
- Loopback prints only a single character when AVR disconnected

At this point it seems as if everything is lined up correctly and worked as expected. So, as a test, I hard-code the AVR to send back a letter 'A' when it receieves a character over UART.
- Loopback test prints same character that is being sent to AVR (i.e. if 'x' is sent, 'xx' gets printed to terminal).
- Loopback test prints only one character is AVR is not connected (i.e. not return path so only the character sent out gets printed).

This does not make any sense. Loopback test appears to work when there is a 'loop' to speak of, but a hardcoded value is not being send back. Somehow the returned character is exactly what is being sent.

EDIT: The same character is being looped back regardless of baud setting. So something is wrong here.

Last edited by sherrellbc (2014-05-26 21:52:50)

Offline

#19 2014-05-27 23:41:01

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Going to give this another try now..

Offline

#20 2014-05-28 00:23:11

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

I really do not know what I could be doing wrong here ..

I have code on one MCU, call it A, that only sends characters and on another I have code that only reads, call it B, characters (and is also hooked to an LCD screen). So, basically what I do is send a character from A to B and have B display it on the LCD screen.

I have this working just fine. The LCD screen is writing a a new character each time one is send from MCU A.

Now, I remove the connection with MCU A (the sending) and replace the RX pin on MCU B with the TX lead from the converter bridge and nothing happens.. I have the exact same settings configuring into GTKterm.

Offline

#21 2014-05-28 00:26:36

Trilby
Forum Fellow
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 17,245
Website

Re: How to install and use the CP2102 USART to USB Converter?

Do you have a voltmeter?

Offline

#22 2014-05-28 00:50:01

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

Trilby wrote:

Do you have a voltmeter?

Of course. The supply use provides approximately 4.5V or so. The controller I use is fine at the operating voltage and presumably since USART is TTL I imagine it to be fine as well. Just to be sure, I used the 5V regulated supply from the converter bridge to drive both MCUs and it still did not work (but the MCUs were communicating just fine between one another as before).

And grounds are connected as they should between my circuit and the converter.

Frankly, the only thing I can begin to thing to do right now is use internal times and determine approximately how long the transfer is taking and compare that to the setup of 9600 baud.

Last edited by sherrellbc (2014-05-28 00:57:38)

Offline

#23 2014-05-28 02:36:02

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,057

Re: How to install and use the CP2102 USART to USB Converter?

<hopeful>Do you have an oscilloscope? </hopeful>
I think there are two things going on here.  First, I think you have a mismatched Baud.  Check your settings in GtkTerm.  It could also be the uController.  I know you said you have it set for 9600 Baud, but are you sure?  The divisor settings are dependent on your clock frequency.  Are you sure you are using the correct divisors for the frequency of your crystal?  And are you using a crystal, ceramic oscillator, or external oscillator for your time base?  The internal RC oscillator of the Atmel parts are not accurate enough for asynchronous communications without playing some tricks (in firmware, the uController measures the apparent period of a signal whose period is known and 'calibrates' itself by calculating the appropriate divisor du jour).  If you have a scope, you could measure the bit period of the data coming from the Atmel.  That the two devices can communicate tells me they both might be using the same wrong Baud.

The other problem is that I think you have "Local Echo" turned on in GtkTerm.  This places the system in "Half Duplex" mode in which data are not expected to be echoed from the Atmel.  That you are getting two characters when the pins are shorted tells me you get the local echo and the loopback.  Then the loopback is missing, you still get the local echo.   Also, make sure you have parity turned off.

Last edited by ewaller (2014-05-28 02:36:59)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
----
How to Ask Questions the Smart Way

Online

#24 2014-05-28 02:40:48

Trilby
Forum Fellow
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 17,245
Website

Re: How to install and use the CP2102 USART to USB Converter?

ewaller wrote:

Do you have an oscilloscope?

This is really what I was getting at with the voltmeter - not checking that devices are being supplied the proper volatage, but checking that signals are being sent when/where you expect them to be.

I don't have the fancy stuff - but I have used a cheap radio-shack multimeter to do such checks.  If you do have an oscilloscope that's a much better idea ... I'm just "too ghetto" to think of the right ideas first - I think of the dumpster-electronics approaches first.

Last edited by Trilby (2014-05-28 02:41:15)

Offline

#25 2014-05-28 03:10:58

sherrellbc
Member
Registered: 2014-05-26
Posts: 109

Re: How to install and use the CP2102 USART to USB Converter?

ewaller wrote:

<hopeful>Do you have an oscilloscope? </hopeful>
First, I think you have a mismatched Baud.  Check your settings in GtkTerm.  It could also be the uController.  I know you said you have it set for 9600 Baud, but are you sure?  The divisor settings are dependent on your clock frequency.  Are you sure you are using the correct divisors for the frequency of your crystal?  And are you using a crystal, ceramic oscillator, or external oscillator for your time base?

I did not think the internal RC oscillators were that bad off, so I was using the internal 8MHz (DIV8 = 0 fuse bit). Taking your advice I just refused the AVR and set it to use a 20MHz clock (external crystal oscillator) to no avail. The setting in GTKterm is certainly 9600 baud.Referencing the datasheet for the Atmega328P we have:

6UfsT3a.png

Which gives a a UBRR register value of 129 corresponding to normal speed (U2Xn = 0). This is all computed for me at compile-time via this formula:

RaHdD1e.png

20,000,000/(16*9600) - 1 = 129.2 ~ 129 truncated.

That the two devices can communicate tells me they both might be using the same wrong Baud.

I was also suspicious of this .. I do not have a trivial way to test this though. Perhaps some workaround using timers is about the best I can do; no oscilloscope here. Doing a quick high-level test I did find something rather interesting though. Both devices are set to run at 9600 baud. One device is operating at 8MHz (internal oscillator) and the other is using an external 20MHz crystal. I am getting UART communication between the devices, but certainly not the characters I'm sending..

The other problem is that I think you have "Local Echo" turned on in GtkTerm.  This places the system in "Half Duplex" mode in which data are not expected to be echoed from the Atmel.  That you are getting two characters when the pins are shorted tells me you get the local echo and the loopback.  Then the loopback is missing, you still get the local echo.   Also, make sure you have parity turned off.

GTKterm does not actually show you what you are typing into the terminal. That is, when you type a character then nothing is displayed to the screen. Presumably this character is sent out as you type it. I was under the impression that local echo would just echo what I type to the screen as well as send it out. Thank you for the clarification.

Last edited by sherrellbc (2014-05-28 03:16:48)

Offline

Board footer

Powered by FluxBB