Questions tagged [i2c]

I2C is a two-wire serial bus. It is used to interface with low-speed peripherals in embedded systems and computer motherboards.

Use this tag when asking questions concerning the I2C bus or SMBus, which is a more strictly defined subset of I2C.

Devices you can communicate with using I2C might include the temperature and voltage sensors on your motherboard. In embedded systems, a vast amount of devices ranging from memory chips to camera modules use I2C for control and data transfer.

I2C bus consists of two signals: SCL and SDA. SCL is the clock signal, and SDA is the data signal.

I2C connection schematics

The clock signal is always generated by the current bus master; some slave devices may force the clock low at times to delay the master sending more data (or to require more time to prepare data before the master attempts to clock it out). The common clock frequency of I2C bus is 100KHz (100Kbps) and 400KHz (400 Kbps). There are high speed versions with clock frequency at or greater than 1MHz (1Mbps) available which is product specific by the semiconductor manufacturers.

The bus is a multi-master bus, which means that any number of master nodes can be present. Additionally, master and slave roles may be changed between messages (after a STOP is sent).

At any given time only the master will be able to initiate the communication. Since there is more than one slave in the bus, the master has to refer to each slave using a different address. When addressed only the slave with that particular address will reply back with the information while the others keep quit. This way we can use the same bus to communicate with multiple devices.

The voltage levels of I2C are not predefined. I2C communication is flexible, means the device which is powered by 5v volt, can use 5v for I2C and the 3.3v devices can use 3v for I2C communication. A 5V I2C bus can’t be connected with 3.3V device. In this case voltage shifters are used to match the voltage levels between two I2C buses.

There are some set of conditions which frame a transaction. Initialization of transmission begins with a falling edge of SDA, which is defined as ‘START’ condition in below diagram where master leaves SCL high while setting SDA low. After this all devices on the same bus go into listening mode.

In the same manner, rising edge of SDA stops the transmission which is shown as ‘STOP’ condition in above diagram, where the master leaves SCL high and also releases SDA to go HIGH. So rising edge of SDA stops the transmission.

I2C conditions

With I2C, data is transferred in messages. Messages are broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits, and ACK/NACK bits between each data frame:

I2C message format

Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the slave when the master wants to talk to it.

Read/Write Bit: A single bit specifying whether the master is sending data to the slave (low voltage level) or requesting data from it (high voltage level).

ACK/NACK Bit: Each frame in a message is followed by an acknowledge/no-acknowledge bit. If an address frame or data frame was successfully received, an ACK bit is returned to the sender from the receiving device.

More information:

I2C Standards Doc

I2C primer

1748 questions
4
votes
1 answer

What does ENXIO mean for an i2c ioctl?

I have an i2c adapter exposed to userspace as /dev/i2c-0. When I use i2cdetect from the i2c-tools package on that adapter, I see my device listed on this adapter and I am able to perform get, set, and dump operations on it from the command line. I…
Woodrow Barlow
  • 8,477
  • 3
  • 48
  • 86
4
votes
0 answers

Specifying GPIO Numbers for IO Expander in Linux Device Tree

I'm trying to add a PCA9557 I/O expander to an arm-based system on an I2C bus. The system already has another I/O expander on a different I2C bus. I am trying to figure out how to specify which GPIO numbers the pins on the new expander get, and how…
Jeremy
  • 1,083
  • 3
  • 13
  • 25
4
votes
5 answers

I can't get DS3231 RTC to work

I have a DS3231 RTC module and I am trying to read time off of it using my Arduino UNO through I2C. I'm using the sample code provided with the library but it doesn't seem to work. The only thing I get out of the serial monitor is this: 20165-85-165…
Ege F
  • 107
  • 1
  • 1
  • 9
4
votes
1 answer

i2c protocol NACK ambiguity

I have a question about I2C protocol. I found this on the wikipedia page. "If the transmitter sees a 1 bit (NACK), it learns that: 1) The slave is unable to accept the data. 2) No such slave 3) Command not understood 4) Unable to accept any more…
dennis menace
  • 83
  • 2
  • 7
4
votes
1 answer

I2C duty cycle significance

What is the significance of changing the duty cycle in i2c protocol? the feature is available in most of the advanced microcontrollers.
dennis menace
  • 83
  • 2
  • 7
4
votes
0 answers

Invensense mpu 9250: dmp

I'm trying to use the dmp to calculate quaternions. I can't understand how to get the dmp data output. I think that they are stored in some registers reachable using i2c but i don't know their address or in general how to get them. Help please
Enrico Gizzi
  • 51
  • 1
  • 2
4
votes
1 answer

I2C user-space read/write issues

I'm writing a user-space program to read and write to/from an EEPROM using open(), ioctl(), read(), and write(), but it doesn't seem to be working the way I expect. I guess first of all I have to ask, is the entire I2C protocol for read and write…
srau
  • 73
  • 1
  • 7
4
votes
3 answers

STM32 I2C1 Start bit not set on SR1 register

I am trying to program the stm32 to talk to my i2c EEprom, but it seems like everytime I say: I2C_GenerateSTART(I2C1, ENABLE); while( !(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) ); the code hangs here I went through with the debugger and…
jramirez
  • 8,537
  • 7
  • 33
  • 46
4
votes
2 answers

pic32 start bit does not clear -- Basic I2C setup

I am new to embedded programming and am trying to get my first I2C project working. I am using the PIC32MX795F512L. I am pretty much following the microchip datasheet for I2C on PIC32. The problem I'm having is the S bit is never cleared from the…
user36927
  • 41
  • 1
  • 3
4
votes
2 answers

I2C slave - clock stretching

Do you guys know how to enable the clock stretching for I2C slave? Is it enough to just put this function I2C_StretchClockCmd(I2C2, ENABLE) in the initialization of I2C? How does clock stretching work exactly?
kai
  • 61
  • 1
  • 1
  • 2
4
votes
2 answers

How to read data from i2c using i2cget?

I'm new to embedded devices and am trying to understand how to use i2cget (or the entire I2C protocol really). I'm using an accelerometer MMA8452, and the datasheet says the Slave Address is 0x1D (if my SAO=1, which I believe is referring to the…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
4
votes
1 answer

Python i2c write_bus_data usage

8I have a number of 4 digit seven segment displays that I am trying to control using Beaglebone Black (running Ubuntu) and i2c. The SSD's are Byvac BV4614's and the full datasheet is available here. I have wired up the circuit correctly using pins…
Hugo Rune
  • 121
  • 1
  • 7
4
votes
1 answer

Different I2C addresses on Arduino?

I've written a class for Arduino that reads the compass data of the HiTechnic LEGO Mindstorms compass sensor. Using the Wire-library, I can very well fetch the data from the respective registers. In my library for Arduino I address the sensor by…
1' OR 1 --
  • 1,694
  • 1
  • 16
  • 32
4
votes
2 answers

cross compiling python native C extensions with distutilscross, setup.py won't accept '-x' argument

I have a working cross compile of Python, however I've tried cross compiling the py-smbus extension from i2c-tools using distutilscross and can't get past the command line. The documentation (https://pypi.python.org/pypi/distutilscross) suggests…
Sparky
  • 2,694
  • 3
  • 21
  • 31
4
votes
4 answers

I2c that support 16 bits address

Initially, I used a eBus SDK which supports 8 bits registers for the I2C. This SDK does not support 16 bits register address for I2C. Is there any alternative to this sdk that support 16 bit register address for the I2C? Best wishes and thank you…
ras red2004
  • 169
  • 1
  • 1
  • 10