Practical
Embedded Java

Using I²C


A practical engineering approach to using embedded Java in real-world applications.


...



I²C is a trademarked acronym for Inter-Integrated Circuit. It is written 'I²C' instead of 'IIC', or 'I2C' when a superscript is not available. I²C is pronounced "Eye-squared-C", or "Eye-Two-See".

.I²C is a two-wire party-line bus intended for short-range communication between ICs on a circuit board or across boards in a system. Philips has been the main promoter of I²C but there are now dozens of other vendors. Millions of I²C devices are in use in consumer and industrial products. SMBus (System Management Bus) is a version very similar to I²C but with some differences.


I²C References and Specifications
I²C Specification from the creator: Philips Download the I²C specification (PDF) at the Philips website.
SMBus specification You can download the System Management Bus specification at the SMBus.org website. SMBus is very similar but with some timing and voltage differences. It was originally used for system and power management on PC motherboards, such as between a notebook's smart battery, charger, and system controller.
I²CChip website http://www.i2cchip.com/i2c_connector.html has information on special connectors and cables for I2C systems
Educypedia I²C site http://www.educypedia.be/electronics/I2C.htm has a wealth of information on I2C including the specification in Dutch
Mixing I²C and SPI signals? This page: http://www.i2cchip.com/mix_spi_i2c.html claims it can be done. It's an interesting idea and might be useful in special cases where pins are limited.

I²C Basics
When should I use I²C vs SPI? I²C devices are generally slower and lower cost than SPI. Multiple I²C device systems require fewer signals to implement. Some "exotic" functions are only available in I²C - car stereo tuners, amps, and tone controls, for example.
I²C Signals - just SCL and SDA I²C has only two signals - clock (SCL) and data (SDA). There are no chip selects. These are the only signals (OK, you also need power and ground) needed for an I²C system of arbitrary complexity. Old I²C chips are limited to 100 KHz max SCL. Newer parts can operate up to 400 KHz or faster.
I²C Slave Addressing Each I²C slave device has a 'base address' assigned by the manufacturer. Some devices have up to three address inputs which are typically wired to a fixed value by circuit board traces or jumpers. This enables up to eight instances of that slave device on a single I²C net. For example, the PCA9554 has a base address of 0x20, but the address bits extend that to 0x20..0x27.
Party line SCL and SDA

Multiple I²C slaves share the same SCL and SDA lines. To avoid clashes, each slave must have a unique address.

Slaves always ACK, so check for this Slaves always drive a bit cell active/low to ACKnowledge each I²C transmission. Your code should check to see that an ACK is present, otherwise the rest of the I²C data cycle is suspect.
Read the slave device data sheets This sounds simple but it's a recurring support issue. Read the data sheets! They are there for a reason (that is: they contain important information you need to use the part successfully), and most vendors do a good job of documenting their parts (they don't want support headaches).
Consider CMOS vs TTL voltage levels I²C devices can have CMOS or TTL voltage levels, and many can operate from 5 volts or considerably less. Read the data sheets to see what your device needs for proper input and output interfacing. Here's an overview of JStamp CMOS and TTL voltage level interfacing (also applies to JStik and SaJe) and a page on TStik interfacing and voltage levels. The same CMOS/TTL rules apply to any standard devices. For example, the PCF8574/A are not TTL-level compatible when powered by 5 volts but are usable with TTL inputs when powered by 3.3 or 3.0 volts. A better device is the PCA9554/A which has TTL level inputs when powered by 2.7 to 5 volts.
Start simple Start talking to to a slave device in the simplest possible fashion to get things working. Then add complexity. Some slaves can be quite complex (eeproms and multi-mode DACs come to mind). Don't try to write and test the whole slave driver at once - get a simple test case working first. Start with I2C.ping() which just looks for an ACK from a slave at that address, and returns boolean true if successful.
Master/slave Typically I²C systems have one master and one or more slaves, but there's nothing preventing a multi-master system. Slaves are typically polled by the master, but a slave can also emit an interrupt on a separate signal, to tell the master when it needs servicing. There's nothing in the I²C (at least that's my memory) specification to arbitrate between multiple masters, so you would need to figure this out yourself.
I²C can have a native hardware and/or a firmware implementation Since all an I²C master needs to do is emit data synchronized with a clock, this is simple hardware to design. It is much like a simplified UART transmit section. I²C is also easily implemented in firmware.
I²C clock is not critical in terms of speed or duty cycle, only the edges matter This makes I²C an easy protocol to implement, and somewhat noise tolerant. As long as the data is stable around the time of the appropriate clock edge(s), and there are no spurious clock edges, you should obtain a very reliable connection.
I²C is open-collector, needs pullups I²C signals are party-line and therefore open-collector or open-drain, meaning they are only actively pulled low. Pullup resistors are needed to create a valid inactive/high level. Some I²C slave devices have pullups built-in, but many do not. On a party line you don't want every device to have its own pullups, or the load will be too high. So check your device data sheets and make sure that you have appropriate pullups. Depending on your system, the pullup could be to 5V, 3.3V or something close to that. Start with 10 KOhms on both the clock and data lines.

I²C Signals
SCL - the I²C clock SCL clocks in data on its rising edges. Standard mode I²C has a clock of 100 KHz max. Fast mode I²C has a clock of 400 KHz max.
SDA - I²C data

SDA is a bidirectional signal - data is written from the master to the slave, and also from the slave to the master. Special Start and Stop conditions are specified by the relationship of SDA and SCL.


I²C in Systronix Products

I²C on TStik and TILT boards TStik uses the Dallas 80C400 controller, and TILT are the socket boards for TStik. I²C is supported on these products, and TILT400.Pro has a special, rugged, I²C repeater to greatly increase the number if I²C devices you can drive, as well as their distance from the socket board. http://www.tstik.com/appnotes/I2C.html
I²C on JStamp and JStik These aJile-based devices support I²C - refer to the Javadocs for the com.ajile.drivers.i2c class.

I²C Chips and Hardware
Philips I²C catalog Philips website can be confusing to navigate. Here's a shortcut to all their I²C devices:
http://www.semiconductors.philips.com/markets/mms/protocols/i2c/products/index.html
DigiKey Stocks a variety of I²C chips, just search on I²C at http://www.digikey.com, enter 'I2C' in the Parts Search dialog on the home page and you should get several hundred matches.
Linear Technology Bus Buffers Supporting I²C and SMBus: http://www.linear.com/pc/viewCategory.do?navId=H0,C1,C1007,C1070
I²C and SMBus Bus Analyzers MCC Bus Analyzers for I²C and SMBus
I2CChip adapters and modules http://www.i2cchip.com/

 
Systronix® 939 Edison St, Salt Lake City, Utah, USA 84111
Tel +1-801-534-1017, Fax +1-801-534-1019
contact us     Time Zone: MDT (UTC-6)
 

Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Systronix is independent of Sun Microsystems, Inc.
TStik, JStik, JCX, JStamp, JSimm, JDroid, and JRealTime are trademarks of Systronix, Inc.
1-Wire, iButton and TINI are trademarks of Dallas Semiconductor
Simmstick is a trademark of Dontronics
LEGO® is a trademark of Lego A/S, Denmark