Thursday, October 30, 2014

I2C Protocol

I²C (Inter-Integrated Circuitis a multi-master, multi-slavesingle-ended(data flow in only one direction at a time)serial computer bus invented by Philips Semiconductor, known today as NXP Semiconductors, used for attaching low-speed peripherals to computer's motherboards and embedded systems.


The Physical I2C Bus


  • Physically I2C consits of just 2 buses.
  • One bus is SDA for data transfer and the other one is SCL for the clock.
  • All the devices on the I2C bus are connected on these two lines.






  • Both these lines are open drain lines, i.e the chip can drive these lines low but can't drive it high.
  • To make it high we need to connect a pull up register to both the lines connected to 5V supply.
  • We don't need separate pull up register for each device.



Masters and Slaves

  • The devices on I2C bus are either master or slave.
  • Characteristics of a master-

  1. Master is the one who drives the clock.
  2. Master is the one who initiates the transfer.
  3. Though both master and slave send data over the bus bus but the transferred is controlled by master.

I2C Device Addressing

  • I2C device addresses are either 7 bit or 10 bit.
  • Considering 7 bit addressing we can connect upto 128 devices to the I2C bus.


  • While sending we send the address as a 8 bit sequence with 8th bit telling the slave if master is reading(1) or writing(0) from /to the device.


The I2C Protocol

  • SDA is allowed to change only when SCL is low , but it is not followed in 2 cases.
1. Start Sequence

2. Stop Sequence


  • The start and stop sequence is sent by master and it marks the beginning and end of the transfer with the slave device.
  • Steps for writing to the slave-
1. Send a start sequence(all the I2C devices start to listen)
2. Send the I2C address of the slave with the R/W bit low (even address/writing)(all the slaves listen to it and matches it with their own address).
The slave sends the acknowledgement bit in return if the address matches.
3. Send the internal register number you want to write to
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.

  • Steps for reading from the slave-
1. Send a start sequence( all the I2C devices on the bus start to listen)
2. Send I2C address of the slave with the R/W bit low (even address/write)(all the slaves listen to it and matches it with their own address).
The slave sends the acknowledgement bit in return if the address matches.
3. Send Internal address of the register to which we need to write.
4. Send a start sequence again (repeated start)
5. Send I2C address of the slave with the R/W bit high (odd address)(slave knows it has to be read from)
6. Read data byte from slave
7. Send the stop sequence.

The peculiar thing in this operation is that even in read operation we do one write operation to know the register from which we need to read from.

3 comments:

  1. I read your blog.I thought it was great.. Hope you have a great day. God bless.

    Rica
    www.imarksweb.org

    ReplyDelete
  2. please suggest websites for practical knowledge

    ReplyDelete