en:i2c
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:i2c [2013/11/27 12:35] – created kaklik | en:i2c [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== I2C in MLAB system ====== | ||
- | ===== Activating The I2C Port ===== | + | ====== I²C bus as an MLAB's component ====== |
+ | [[http:// | ||
+ | |||
+ | Thanks to an advancement in computer technologies [[en: | ||
- | The I2C port needs to be enabled in kernel before you can use it. This can be achieved by | + | ===== Linking of I²C devices ===== |
- | sudo modprobe i2c-dev | + | Although the I²C bus was originally designed to link devices on small scales (within the dimensions of PCB), using certain techniques it is possible to enlarge its range to tens of meters (( [[http:// |
- | + | ||
- | Then I²C bus interfaces | + | |
- | sudo i2cdetect -l | + | Linking of I²C devices within MLAB is implemented on several levels according to extent of a network. Locally (on scale of several meters), the modules are connected by MLAB cables and separated by [[en: |
- | ===== Checking For Connected Devices ===== | + | Over more extensive distances the bus is linked through shielded signal cables ending in female connectors and connected to [[en: |
- | At the command prompt type one of these depending on whether you are using the I2C-X port: | + | In the case of extensive networks I²C is replaced by other physical layer (CAN, Ethernet) that interconnects individual I²C network segments. |
- | sudo i2cdetect -y X | ||
- | The 7 bit I2C address of all found devices will be shown (ignoring the R/W bit, so I2C address 0000 0110 is displayed as hex 03). | ||
+ | ==== Pymlab package ==== | ||
+ | |||
+ | Pymlab represents a software package that enables a creation of network made of I²C devices and modules, which serve as routing points. It defines the structure of a network and addresses of individual nodes in a source file of a control program. Individual points in the network can than be accessed using simple python commands. | ||
- | ===== SMBus (System Management Bus) Functions ===== | + | The installation of the [[en: |
+ | |||
+ | sudo pip install pymlab | ||
+ | |||
+ | In case of having some older version of pymlab already installed, it is enough to run: | ||
+ | |||
+ | sudo pip install --upgrade pymlab | ||
+ | |||
+ | Both commands are equivalent and use the python package manager that contains [[https:// | ||
+ | This procedure should also download other packages used by pymlab such as cython-hidapi | ||
+ | |||
+ | sudo apt-get install libudev-dev libusb-1.0-0-dev libhidapi-dev python-setuptools python-smbus cython | ||
- | SMBus (System Management Bus) is a subset from the I2C protocol | + | ===== Convertors |
- | When writing a driver for an I2C device try to use the SMBus commands only (if it possible). It makes possible | + | |
- | Note address | + | Although I²C is quite popular bus suitable |
- | long write_quick(int addr) | + | ==== USB interface ==== |
- | Send only the read / write bit | + | Proprietary designs: |
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
- | long read_byte(int addr) | + | These share a common problem with a quality of drivers. Furthermore, |
- | Read a single byte from a device, without specifying a device register. | ||
+ | ==== USB HID ==== | ||
- | long write_byte(int addr,char val) | + | For connections without the need for drivers designed for specific hardware [[http:// |
- | Send a single byte to a device | ||
+ | ==== UART/RS232 to I²C ==== | ||
- | long read_byte_data(int addr,char cmd) | + | NXP manufactures [[http:// |
- | Read Byte Data transaction. | + | ==== Ethernet to I²C ==== |
+ | This type of convertor can be constructed using [[en: | ||
- | long write_byte_data(int addr,char cmd,char val) | + | ===== I²C implementation in Linux systems ===== |
- | Write Byte Data transaction. | + | There exists a package of tools for working with I²C bus for Ubuntu that can be installed through: |
+ | sudo apt-get install i2c-tools | ||
+ | Due to the usual absence of //i2c-dev// (([[https:// | ||
+ | sudo modprobe i2c-dev | ||
- | long read_word_data(int addr,char cmd) | + | <WRAP tip> |
+ | Modprobe command adds the module only to the kernel instance that is already running. Therefore, after reboot, the module will probably still be missing. If we do not want to use modprobe command on next computer start, we need to add following line to / | ||
+ | i2c-dev | ||
+ | </ | ||
- | Read Word Data transaction. | + | It is now possible to list available I²C buses: |
+ | $ sudo i2cdetect -l | ||
+ | i2c-0 i2c | ||
+ | i2c-1 i2c | ||
+ | i2c-2 i2c | ||
+ | i2c-3 i2c | ||
+ | i2c-4 i2c | ||
+ | i2c-5 i2c | ||
+ | i2c-6 i2c | ||
- | long write_word_data(int addr,char cmd,int val) | + | Using // |
- | Write Word Data transaction. | + | kaklik@radio-arm-0: |
+ | | ||
+ | 00: -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 10: UU -- -- -- -- -- -- -- -- -- -- -- -- -- 1e -- | ||
+ | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 70: 70 -- -- -- -- -- -- -- | ||
+ | kaklik@radio-arm-0: | ||
+ | The output above shows, that apart from system device with 0x10 address, there are to additional devices connected to the bus: 0x1e ([[en: | ||
- | long process_call(int addr,char cmd,int val) | + | ==== Communication with I²C devices ==== |
- | Process Call transaction. | + | The bus can be controlled either by using system kernel interface or a service utility that is a part of i2c-tools package: |
+ | $ apropos i2c | ||
+ | i2cdetect (8) - detect I2C chips | ||
+ | i2cdump (8) - examine I2C registers | ||
+ | i2cget (8) - read from I2C/SMBus chip registers | ||
+ | i2cset (8) - set I2C registers | ||
- | long[] read_block_data(int addr,char cmd) | + | === Writing === |
- | Read Block Data transaction. | + | Writing is executed by i2cset command. A following [[cs: |
+ | ~$ sudo i2cset -y -r 1 0x70 0xff | ||
+ | Value 0xff written, readback matched | ||
- | write_block_data(int addr,char cmd,long vals[]) | + | The command triggers all I²C channels on I²CHub |
- | Write up to 32 bytes to a device. | + | === Reading === |
+ | Reading from I²CHub is atypical as well, because the data registry is not addressed: | ||
- | long[] block_process_call(int addr,char cmd,long vals[]) | + | $ sudo i2cget -y 1 0x70 |
+ | 0xff | ||
- | Block Process Call transaction. | + | ==== Use of Linux kernel drivers ==== |
- | I2C Access Functions | + | |
+ | Some I²C devices have their drivers directly in the linux kernel allowing an access directly through file system. It applies to following MLAB modules: | ||
- | long[] read_i2c_block_data(int addr,char cmd) | + | * [[en: |
+ | * [[en: | ||
+ | * [[en: | ||
- | Block Read transaction. | + | Due to the fact that, in principle, I²C is not a [[http://en.wikipedia.org/ |
+ | echo driver' | ||
- | write_i2c_block_data(int addr,char cmd,long vals[]) | + | Linux kernel will take control of I²C device - such state can be seen in i2cdetect list labeled as UU. Details concerning the initialisation can be further found in [[http:// |
- | Block Write transaction. | + | ===== Other operating systems ===== |
+ | On other OS (like Windows or Mac OS), where we cannot or do not want to use kernel I²C interface support, we may use Python programming environment that is multi-platform. | ||
- | ===== References | + | ===== Related sites ===== |
- | * [[http:// | + | * [[en: |
- | * [[http:// | + | * [[en:i2c-pic-usb|I2C-PIC-USB]] - Konvertor I²C na USB s PIC |
+ | * [[en: | ||
+ | * [[en:arm|Procesory architektury ARM ve stavebnici MLAB]] | ||
+ | * [[en:odroid-x2]] | ||
+ | * [[en: | ||
+ | * [[en: | ||
+ | * [[en:pymlab]] |
en/i2c.1385555751.txt.gz · Last modified: 2013/11/27 12:35 (external edit)