Some Important Terms and their explanation
You might be knowing these terms already but if you don’t, I welcome you to fork and commit your own edit with respect to explanation.
Table of Contents
I2C Communication protocol
- Also pronounced as “I squared C” or Two Wire interface
- It is responsible for establishing a communication between multiple master devices(in our case Arduino) and multiple slave devices.
- Only two wires are required for almost 128(112) devices when using 7-bit addressing and up to almost 1024(1008) devices when using 10 bit addressing. How is it possible?
- Each device has a preset ID or a unique device address so the master can choose with which device we will be communicating
- The two lines are SCL and SDA
SCL
or Serial Clock generates clock signal to synchronize data transfer between the devices on the I2C bus and its generated by the master device.SDA
or Serial Data is responsible for carrying the data.
The two lines are open drain which means pull up resistors needs to be attached to them so that the lines are high, because the devices on the I2C bus are active low. Resistors range from 2k for 400 kbps (higher speed) to 10k for 100 kbps (lower speed)
DATA PROTOCOL IN I2C BUS
Img courtesy: How to Mechatronics video on I2C
- Start condition occurs when data line drops low while the clock line is still high
- each data bit is transferred at each clock pulse
- 8th bit is used for indicating whether the master will write to the slave(logic low) or read from it(logic high)
- The next bit ‘acknowledge’ is used by the slave device to indicate whether it has successfully received the previous sequence of bits
- So this time the master device hands the control of the SDA line to slave device and if slave device has successfully received previous sequence it will pull the SDA line down to condition called Acknowledge. And if it doesn’t pull the SDA line down, the condition is called Not Acknowledge i.e., didn’t receive the previous sequence of bits.
- The reasons for Not Acknowledge could be
- Slave might be busy
- Might not understand the received data
- Can’t receive any more data
- The reasons for Not Acknowledge could be
- Internal registers are locations in the slave’s memory containing various information or data
- After the data is completely sent, the transfer will end with a stop condition which occurs when the SDA line goes from low to high while the SCL line is high.
I2C_scanner is a simple sketch which scans the I2C bus for devices. If a device is found, it is reported to the arduino serial monitor.
SERIAL COMMUNICATION | . |
---|---|
UART - Universal Asynchronous Receiver Transmitter | SPI - Serial Peripheral Interface |
UART | I2C | SPI |
---|---|---|
1 to 1 | Simplex | Duplex |
Asynchronous | Synchronous | Synchronous |
2 Wires | 2 wires | 4+ wires |
20 kbps | 1 mpbs | 25 mbps |
Acknowledge Pins | No Acknowledge | No Acknowledge |
Medium Power | Medium Power | Lower Power |
15m distance | 1m distance | 20cm distance |