What is I2C?
I2C
(Inter-Integrated circuit), invented by Philips semiconductor in 1982. I2C is
mainly use to connect system control devices such temperature sensors, voltage
monitors, this bus mainly take cares of the system health.
Why I2C? do we have any other bus for this purpose?
Yes, we have SPI
(serial peripheral bus), for this purpose, but compare to I2C, SPI has few draw
backs so i2c is the better option to choose.
What are the drawbacks with SPI compare to I2C?
·
I2C uses two pins to communicate (SDA,
SCL).
·
SPI needs four pins (MOSI, MISO, SS,
CLK) to communicate, if the slave devices are more then we need extra pins (SS)
·
I2C supports multi masters, SPI doesn’t
Does i2c synchronous or asynchronous?
I2C is synchronous
bus, since it uses clock line to communicate. Serial ports are asynchronous,
because it sends all the bits at a time without waiting.
What is the I2C speed?
·
100 Khz
·
400 Khz
·
3Mhz
We can configure the
i2c bus speed by configuring the FDR(Frequency divide register) from processor.
Basic I2C communication protocol?
When the master
(your controller) wishes to talk to a slave it begins by issuing a start
sequence on the I2C bus. A start sequence is one of two special sequences
defined for the I2C bus, the other being the stop sequence. The start sequence
and stop sequence are special in that these are the only places where the SDA
(data line) is allowed to change while the SCL (clock line) is high. When data
is being transferred, SDA must remain stable and not change whilst SCL is high.
The start and stop sequences mark the beginning and end of a transaction with
the slave device.
All I2C addresses are either 7 bits or 10 bits. The
use of 10 bit addresses is rare and is not covered here. All of our modules and
the common chips you will use will have 7 bit addresses. This means that you
can have up to 128 devices on the I2C bus, since a 7bit number can be from 0 to
127. When sending out the 7 bit address, we still always send 8 bits. The extra
bit is used to inform the slave if the master is writing to it or reading
from it. If the bit is zero the master is writing to the slave. If the bit is 1
the master is reading from the slave. The 7 bit address is placed in the upper
7 bits of the byte and the Read/Write (R/W) bit is in the LSB (Least
Significant Bit).
The placement of the 7 bit address in the upper 7
bits of the byte is a source of confusion for the newcomer. It means that to
write to address 21, you must actually send out 42 which is 21 moved over by 1
bit.
1.Send a start sequence
2.Send the I2C address of the slave with the R/W bit low (even address)
3.Send the internal register number you want to write to
4.Send the data byte
5.Send the stop sequence.
2.Send the I2C address of the slave with the R/W bit low (even address)
3.Send the internal register number you want to write to
4.Send the data byte
5.Send the stop sequence.
As an example, address of 0xE0. you
would write 0x51 to the command register at 0x00 like this:
1. Send a start sequence
2. Send 0xE0 ( I2C address of the SRF08 with the R/W bit low (even address)
3. Send 0x00 (Internal address of the command register)
4. Send 0x51 (The command to start the SRF08 ranging)
5. Send the stop sequence.
1. Send a start sequence
2. Send 0xE0 ( I2C address of the SRF08 with the R/W bit low (even address)
3. Send 0x00 (Internal address of the command register)
4. Send 0x51 (The command to start the SRF08 ranging)
5. Send the stop sequence.
Read from Device.
1. Send a start sequence
2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.
2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.
No comments:
Post a Comment