User Tools

Site Tools


en:usbi2c

Differences

This shows you the differences between two versions of the page.


Previous revision
en:usbi2c [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
 +====== Converter from USB to I²C or SMBus - USBI2C01A ======
 + 
 +[[en:i2c|I²C]] is widely used bus intended for connection of various sensors on short distances. But it is not usual to interface this bus at personal computers because it is not accessible as standard interface. (([[http://www.paintyourdragon.com/?p=43|One exception is DDC bus on HDMI/DVI interfaces.]]))
 +
 +{{ :cs:modules:usbi2c01a_top_big.jpg?direct&300 |USBI2C01A}}
 +
 +This module could solve such problem by using the [[http://www.silabs.com/products/interface/usbtouart/Pages/HID-USB-to-SMBus-Bridge.aspx|Silicon Labs CP2112 IO]], which is direct converter between USB and SMBus or I²C respectively. 
 +
 +===== Use of the module =====
 +
 +The module is enumerated as standard HID device by default. Such behavior allows use without special drivers on every operating system. But some operating systems contain special software for manipulating with I2C/SMBus. In such case is useful to change generic USB HID driver by special driver which connect the MLAB module as standard I2C or SMBus interface.
 +
 +==== HIDAPI connection method ====
 +
 +HIDAPI is software interface to access HID devices from Linux, Windows or MAC OS. The library works on all mayor computer platforms and architectures. The prerequisite to get HIDAPI work is libusb-1.0 library installed in the system. 
 +
 +=== Ubuntu 14.04 ===
 +
 +We should install [[https://github.com/signal11/hidapi|hidapi]] and some other packages by running. 
 +
 +  sudo apt-get install libudev-dev libusb-1.0-0-dev libhidapi-dev python-setuptools python-pip python-smbus cython 
 +
 +Then we only need package [[en:pymlab|Pymlab]]
 +  sudo pip install pymlab
 +  
 +Then a new I2C interface may be used in the system, as is mentioned in the page [[en:i2c]]. The module allows even direct access to its GPIO pins.
 +
 +  
 +== The example of Python LED blinking script on USBI2C01A IO ports ==
 +
 +  import hid
 +  import time
 +  
 +  try:
 +      print "Opening device"
 +      h = hid.device()
 +      h.open(0x10C4, 0xEA90)
 +  
 +      print "Manufacturer: %s" % h.get_manufacturer_string()
 +      print "Product: %s" % h.get_product_string()
 +      print "Serial No: %s" % h.get_serial_number_string()
 +  
 +      h.write([0x02, 0xFF, 0x00, 0x00, 0x00])  # sets output to open-drain
 +      time.sleep(0.1)
 +      for k in range(10):
 +          h.write([0x04, 0xFF, 0xFF])  # writes 1 to all  8 outputs pins.
 +          time.sleep(0.1)
 +          h.write([0x04, 0x00, 0xFF])  # writes 0 to all 8 outputs pins.
 +          time.sleep(0.1)
 +  
 +      print "Closing device"
 +      h.close()
 +  
 +  except IOError, ex:
 +      print ex
 +  
 +  print "Done"
 +
 +//This example should be executed as root in default configuration.//
 +
 +<WRAP info round>
 +The details of HIDAPIO acces to IO ports should be found in [[http://www.mlab.cz/WebSVN/filedetails.php?repname=MLAB&path=%2FModules%2FCommSerial%2FUSBI2C01A%2Fpdf%2FCP2112%2FAN495.pdf
 +|this document]]
 +</WRAP>
 +
 +== Correct setting of access right to USB ==
 +
 +If we need an access to USBI2C01B module without root privileges we need to create a file SiliconLabs.rules in **/etc/udev/rules.d** directory. The file should contains:
 +
 +  SUBSYSTEM=="usb", ATTRS{idVendor}=="10c4", MODE="0666"
 +  SUBSYSTEM=="usb_device", ATTRS{idVendor}=="10c4", MODE="0666"
 +  
 +==== Linux Kernel ====
 +
 +The Linux is a case of operating system in which system access to I2C or SMBus interfaces currently exists. In Linux is useful to change generic HID driver by new software module in the kernel. The CP2112 IO is directly supported in Linux kernel from 3.16. In that case a loading of //i2c-dev// Linux kernel module is only required operation.  We should do this by sudo modprobe i2c-dev. Then we should see a new I²C interface in system bus list.
 +
 +  kaklik@UST-vyvoj:~$ sudo i2cdetect -l
 +  i2c-0 i2c        i915 gmbus ssc                  I2C adapter
 +  i2c-1 i2c        i915 gmbus vga                  I2C adapter
 +  i2c-2 i2c        i915 gmbus panel                I2C adapter
 +  i2c-3 i2c        i915 gmbus dpc                  I2C adapter
 +  i2c-4 i2c        i915 gmbus dpb                  I2C adapter
 +  i2c-5 i2c        i915 gmbus dpd                  I2C adapter
 +  i2c-6 i2c        DPDDC-B                          I2C adapter
 +  i2c-7 smbus      CP2112 SMBus Bridge on hiddev0  SMBus adapter
 +  i2c-8 smbus      CP2112 SMBus Bridge on hiddev0  SMBus adapter
 +  kaklik@UST-vyvoj:~$
 +
 +If we the new interface we should use it exactly same as standard system I²C bus. But CP2112 does not support SMBus Quick Write function. Then we should avoid use of the Quick Write by //-r// parameter as is demonstrated in following example: 
 +
 +  kaklik@UST-vyvoj:~$ sudo i2cdetect -y -r 8 
 +        1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
 +  00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +  70: 70 -- -- -- -- -- -- --                         
 +  kaklik@UST-vyvoj:~$
 +
 +We see that device with address //0x70//, which is the [[en:i2chub|I²C Hub module]] in that case.
 +
 +==== Examples of connected I²C devices ====
 +
 +=== CLKGEN01B ===
 +
 +Connection of the clock generator. This case is used in [[en:rmds|Radio Meteor Detector Station design]].
 +
 +[[en:clkgen]]
 +
 +{{:cs:modules:clkgen01b_connection_big.jpg?300 |The example of use the CLKGEN01B module and USBI2C01A}}
 +
 +
 +
 +=== MAG01A ===
 +
 +Magnetometer connection. 
 +
 +[[en:mag]]
 +
 +{{:cs:modules:usbi2c01a_mag01a_top_big.jpg?direct&300 | USBI2C01A module connected to MAG01A magnetometer.}}
 +
 +
 +=== GPIO ===
 +
 +[[cs:i2cio]]
 +
 +{{youtube>5ZDLRfBRRL4?medium}}
 +
 +===== Related pages =====
 +
 +  * [[en:i2c_avr_usb|I²C AVR USB]]
 +  * [[en:i2c-pic-usb|I²C PIC USB]]
 +  * [[en:i2c|I²C bus in MLAB development system]]
 +
 +
 +===== References =====
 +
 +  * [[http://www.acmesystems.it/i2c|I2C bus interface]]
 +  * [[http://wiki.erazor-zone.de/wiki:linux:python:smbus:doc|Python SMBus and I²C library]]
 +  * [[http://www.i2cdevlib.com/| I2C Device Library]]
 +  * [[http://askubuntu.com/questions/163298/whats-a-simple-way-to-recompile-the-kernel|Ubuntu stock kernel build]]
 +  * [[http://unix.stackexchange.com/questions/12005/how-to-use-linux-kernel-driver-bind-unbind-interface-for-usb-hid-devices|How to use Linux kernel driver bind/unbind interface for USB-HID devices]]
  
en/usbi2c.txt · Last modified: 2014/12/27 21:34 (external edit)