I2C (Inter-Integrated Circuit), pronounced I-squared-C, is a synchronous, multi-master, multi-slave, packet switched, single-ended, serial communication bus invented in 1982 by Philips Semiconductor (now NXP Semiconductors). It is widely used for attaching lower-speed peripheral ICs to processors and microcontrollers in short-distance, intra-board communication. Alternatively, I2C is spelled I2C (pronounced I-two-C) or IIC (pronounced I-I-C).
Hardware
- SDA : The Data line (Serial Data Line).
- SCL: The Clock line (Serial Clock Line).
- Rp : pull-up resistors.
- VD: 3.3v to 5V (for Arduino Uno 5V)
- Master : The architecture can accept more than one master.
- Slaves : 112 max slaves.
- Wires : no longer than 2 m.
I2C: Master as sender configuration
- Code of the Master :
// Wire Master Writer #include <Wire.h> void setup() { Wire.begin(); // join i2c bus (address optional for master) } byte x = 0; void loop() { Wire.beginTransmission(4); // transmit to device #4 Wire.write(x); // sends one byte Wire.endTransmission(); // stop transmitting x++; delay(500); }
- Code of the Slave :
// Wire Slave Receiver #include <Wire.h> void setup() { Wire.begin(4); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event Serial.begin(9600); } void loop(){ delay(100);} void receiveEvent(int howMany) { x = Wire.read(); // receive byte Serial.println(x); }