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
3
votes
2 answers

MPU6050 output yaw pitch and roll with Arduino

I'm trying to read yaw, pitch and roll with MPU6050 and Arduino, but I always get overflow, if I use the function yprx() in the loop without waiting for any input I get the correct values, the problem in this solution is that I need the three values…
Mitro
  • 1,230
  • 8
  • 32
  • 61
3
votes
0 answers

Python code for a 16x2 LCD via I2C gives alternate results

I'm trying to use some Python code to write text on a 16x2 LCD display ("compatible" with classics Hitachi HD44780) connected to a RaspberryPi model B+ via an I2C "back-pack". This I2C board has a PCF8574 IC. This is the library (credits to the…
dentex
  • 3,223
  • 4
  • 28
  • 47
3
votes
0 answers

Linux I2C device driver probe function is not called

I am trying to connect Analog Devices` ADV7182 video encoder chip which has I2C communication to config the chip and control MIPI video data over CSI-2. The issue is that the probe function of the driver is not called unless I create a new I2C…
oxod
  • 166
  • 1
  • 7
3
votes
3 answers

platform device/driver vs i2c device/driver

As i am new to embedded field i am facing difficulties in understanding the clear difference between i2c device/driver and platform device/driver. i have read this link: What is the difference between Platform driver and normal device…
3
votes
1 answer

Properly call external dll in Delphi?

I know few basics of Delphi (In fact I've been using it for few years)... I'm hitting a wall with DLL's (never really play with this). Consider this example: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics,…
ELCouz
  • 572
  • 2
  • 6
  • 17
3
votes
1 answer

Why am I getting an IOError when running this i2c example code on my Beaglebone Black?

Below is the image.py example in the Adafruit SSD1306 Library, for driving OLED display through i2c on a BeagleBone Black. It is giving me an IOError, but I am confused as to what it means. Is the IOError likely a problem with the code itself, or…
user391339
  • 8,355
  • 13
  • 58
  • 71
3
votes
5 answers

How to initialize I2C on STM32F0?

Recently I've been trying to get the I2C bus working on the STM32F030F4P6 MCU, but with little luck. I'm using an STM32F0 module and have found plenty of resources for the STM32F1 module I2C initialization, but nothing specific about the STM32F0…
Stroodlemuffin
  • 31
  • 1
  • 1
  • 5
3
votes
1 answer

When to best implement a I2C driver module in Linux

I am currently dealing with two devices connected to the I2C bus within an embedded system running Linux. I am using an exisiting driver for the first device, a camera. For the second device, I have successfully implemented a userspace program with…
stefangachter
  • 845
  • 2
  • 10
  • 16
3
votes
3 answers

How to convert the value get from Temperature Sensor?

I am working on ST Temperature sensor( hts221 ) , I use I2C command communication with sensor. I see from the document like the following text. enter code here Temperature data are expressed as TEMP_OUT_H & TEMP_OUT_L as 2’s complement numbers. And…
Martin
  • 2,813
  • 11
  • 43
  • 66
3
votes
1 answer

Reading multiple bytes using I2C in U-Boot

I am having a problem with the I2C driver for a Freescale p1022tw board. There is a command on U-Boot's console to read from an I2C device: i2c md chip address[.0, .1, .2] [# of objects] When I read 4 bytes from a device with id 0x60, at address…
Nildo
  • 43
  • 1
  • 5
3
votes
4 answers

I2c bit banging Programming using C

I am trying to write a c code for I2c Using bit banging. I have revised the Code of wiki(http://en.wikipedia.org/wiki/I%C2%B2C). But i am unable to get a result. As per my understanding the code in the wiki is not correct. Many changes i made, but…
user3844884
  • 41
  • 1
  • 2
  • 6
3
votes
1 answer

C I2C code to read sensor data from MPU9150 not working

I am trying to read the MPU9150 sensor data over I2C using an LPC1343 microcontroller. I have developed the following C code, however, I receive zero when reading the value of say accelerometer X low bits. Here is my code: /////////////// MPU9150…
JDS
  • 16,388
  • 47
  • 161
  • 224
3
votes
0 answers

i2c registering macro not found?

I ame working on I2C driver on a raspPi: /* register I2C device static */ static const struct i2c_board_info rasp_i2c_devices[] = { { "mbed", mbedID }, }; /* in the init function of my module…
zilleplus
  • 479
  • 1
  • 3
  • 12
3
votes
2 answers

Is I2C master to Master communication possible?

Is it possible for an I2C master device to communicate with another I2C master device ? Thanks
3
votes
1 answer

How to use I2C on a TM4C123GXL (TivaC) Launchpad

I am attempting to connect my Launchpad device to the Pololu MinIMU9v2 9DoF sensor via the I2C bus. I am working in a Linux environment, compiling with arm-none-eabi-gcc, and I have downloaded the sw-ek-tm4c123gxl zip file from the Texas…
Bobby
  • 1,439
  • 2
  • 16
  • 30