Saturday, May 30, 2015

i2c memo




This is a tiny memo on "how does i2c work"


There will be no complex explanations, just basic stuff.
Most of this information can be found in the web.


i2c

History and origin


Basically we don't care, but for sake of clarity I have to mention, that i2c really is IIC which means Inter-Integrated circuit. Why do we care? Because this brings in length and line quality limitations. Sometimes we can extend this limits, but most of the time it's better to obey official reference documentation.


Circuit was developed by Philips (these guys made really lot of cool stuff) and uses four wires to work.
Yes, they say it uses three or two wires, but in fact let's count:

  • Vdd (power and reference voltage line, typically 3.3V or 5V),
  • SDA (Serial Data Line),
  • SCL (Serial Clock Line),
  • Ground (yes! You have to have common ground, inter-integrated circuit, remember? ;) )
Important to know, that SDA and SCL lines use "pullups" to Vdd. Playing with resistance line length can be adjusted. Typically you'll need 10kOhm resistors.
Here's picture from wikipedia:

Hierarchy and addressing


Hierarchy in i2c is very simple: "One host to rule them all" One master, up to  112 slaves.
Why number is so strange? 
Because i2c uses 7-bit addressing which leaves us 128 unique addresses, 16 of them are reserved. 
Yes, that leaves 112 slave device addresses for us.

Pros


  • i2c is hotpluggable;
  • One host controller (master) is needed;
  • Only two wires needed (it depends, but in some cases it's true);
  • It is possible to have more than one master on bus

Cons

  • Line capacity should not exceed 400pF (it depends too, but mostly true);
  • Bus has no error control, so programming over i2c could be very unpleasant;
  • Hard to debug if one of devices sets false "stop" status.



Tips and tricks

Due to lack of error correction in bus architecture and absence of physical signal line, it is not impossible to get in situation, when bus interference bring i2c slave device into "locked" position.
Such situation will happen if accidentally bus interference matches "start" signal. In this case when controller will send true "start" signal, slave device will already be expecting "data". Which will result locking of slave device.

To reset slave receiver, we should send 9 SCL impulses keeping SDA high at the same time. 

No comments:

VIM cheat sheet

Basic basics :) i - start editing, current symbol a - start editing, next symbol Esc - stop editing :w - write to disk :w <filename> -...