Reply
Posts: 10
Registered: ‎02-09-2017
Accepted Solution

Access CP2108 GPIO8-15?!

Hello there!

 

I have a bit of trouble accessing the GPIO8-15 of the CP2108. I followed the example code and it works for the first 8 GPIOs but I have no idea how to access the other ones. It seems to me that the upper 8 ones are not supported at all. At least when I look at the prototype of the CP210xRT_WriteLatch function in AN721 (p42):

 

CP210x_STATUS CP210xRT_WriteLatch(HANDLE Handle, BYTE Mask, BYTE Latch)

 

And a byte holds IMHO only 8 bit, so there is no way of accessing 16 GPIOs... can somebody please give me a hint what to do?

 

Thanks in advance!

Posts: 2,326
Registered: ‎10-14-2014

Re: Access CP2108 GPIO8-15?!

if i remember it correctly, the library header file state this parameter length differently.
WeiguoLu
Posts: 10
Registered: ‎02-09-2017

Re: Access CP2108 GPIO8-15?!

Thanks for the answer but this does not help me very much. I tried it on Linux as well and there is no distinguishable way of flipping the upper 8 GPIOs. So I will just use some other GPIOs and redesign the PCB. Thanks anyway!

Posts: 230
Registered: ‎08-19-2015

Re: Access CP2108 GPIO8-15?!

Hi @ekoeck,

 

Please have a look at application note "AN978: CP210x USB-to-UART API Specification.":

 

https://www.silabs.com/documents/public/application-notes/AN978-cp210x-usb-to-uart-api-specification...

 

The API specification for the CP210xRT_WriteLatch() function is contained in section 1.2.2 (page 17), and is as follows:

 

CP210x_RT_WriteLatch_spec.png

Thus, the mask and latch parameters are WORD parameters, not BYTE parameters. 

 

Also, you can verify the functionality of using this function to change all of the GPIO states on the CP2108 using the AN223 software tool "CP210x Port Read/Write Example":

 

https://www.silabs.com/documents/public/example-code/AN223SW.zip

https://www.silabs.com/documents/public/application-notes/an223.pdf (This document is superseded by AN978).

 

I hope this helps.  Let me know if you have questions.

 

Regards,

Mitch

Posts: 10
Registered: ‎02-09-2017

Re: Access CP2108 GPIO8-15?!

Thanks for your reply, Mitch. I used AN721 as reference:

 

an721_42.png

 

The software from AN223 is sadly only for Windows, as far as I can see, but seems to work in my virtual machine. And the example code from the Linux VCP driver toggles only the lower 8 GPIOs. Since the final product should work in combination with a Linux system (I forgot to mention in my initial post) and it seems to work under Windows, how to make the magic happen on Linux?

 

Thanks!

Posts: 230
Registered: ‎08-19-2015

Re: Access CP2108 GPIO8-15?!

Hi @ekoeck,

 

The CP210x driver that is pre-built into the Linux kernel does not support GPIO functions, however, you can download and install the CP210x Linux driver from our website, which does support GPIO manipulation on the CP210x devices.  You can download the appropriate driver from the following site:

 

https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

 

Additionally, the following knowledge base may provide a bit more information about the differences in these linux CP210x drivers:

 

http://community.silabs.com/t5/Interface-Knowledge-Base/Differences-Between-the-CP210x-Linux-VCP-dri...

 

Finally, I have attached some example code (cp210x_gpio_example2_linux.c) that demonstrates GPIO use using the driver from our website.

 

I hope this helps!

 

Regards,

Mitch

Posts: 10
Registered: ‎02-09-2017

Re: Access CP2108 GPIO8-15?!

Hey Mitch,

 

this comment in your code did the trick:

 

// mask = 3: gpio #1 and #0; value = 2: set #1, clear #0
// Clearing GPIO turns LED on on SiLabs blue EK boards.
#ifdef CP2108
unsigned short gpioread = 0x3333;
unsigned long gpio = 0x00020003;
#else
unsigned char gpioread = 0;// 0x33;
unsigned short gpio = 0;
#endif

Would be nice to find this somewhere in the documentation. But thanks, it's working now fine Robot Happy