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

Changing slave address of mlx90614 with bcm2835 via SMBus / I2C

How do I change slave address of mlx90614 with bcm2835 library? I've tried following code... int main() { // Buffer, where I store data which I'll send unsigned char buf[6]; // bcm2835 i2c module intialisation code bcm2835_init(); …
TukeV
  • 641
  • 2
  • 6
  • 13
3
votes
1 answer

STM32F207 I2C test failing

I am learning embedded development on the STM3220G-EVAL board with the STM32F207 microcontroller. I have tried to test the I2C interface by interfacing the two I2C2 and I2C3 modules on the same chip and sending/receiving a character. Here is the…
hl2gordon
  • 71
  • 1
  • 7
3
votes
1 answer

What is the use of 'i2c_get_clientdata" and "i2c_set_clientdata"

I have been studying I2C driver (client) code for a while. I have seen this function "i2c_get_clientdata" and "i2c_set_clientdata" every where. I have seen the this question here . Use of pointer to structure instead of creating static local…
Virendra Kumar
  • 947
  • 2
  • 13
  • 31
3
votes
1 answer

Using operators for I2c operations

I have a STM32F2 controller and a FRAM device FM24V10-G connected to it via I2C. Usually, in order to communicate with I2C devices I use a library, based on libopencm3. However, using FRAM requires a slightly different order of I2C actions(like…
Egor
  • 401
  • 1
  • 7
  • 14
3
votes
1 answer

Linux C Programming: Concurrent reads/writes to same file descriptor

I am writing a program that interfaces with a particular serial device. The serial device has two channels, and a hardware rx and tx buffer for each channel. Basically, at any given time , you can read/write to either channel on the device. I am…
It'sPete
  • 5,083
  • 8
  • 39
  • 72
3
votes
1 answer

Set Up I2C Address Without Device Attached

I've been trying to learn about I2C today, it's taken me some time to set up but I've now got a Raspberry Pi configured with i2c-tools installed and I can see /dev/i2c-0. However when I run i2cdetect -y 0 I get an empty address table. This makes…
James
  • 3,957
  • 4
  • 37
  • 82
3
votes
1 answer

How to retrieve data from an i2c device over usb in linux

I have a temperature sensor, which is connected using an USB-I2C adapter (http://www.robot-electronics.co.uk/htm/usb_i2c_tech.htm) I attached this device to my linux computer (suse10). I typed dmesg and saw usb 3-3: new full speed USB device using…
stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94
3
votes
1 answer

I2C Bitbanging in Raspberry pi

We are using raspberry pi in one of our projects; in the same we want to use the i2c to interface touch screen. As i2c in pi shall not support clock stretching planning to use the i2c bit banging. I am following the procedure as given in the…
Suman
  • 109
  • 2
  • 7
3
votes
2 answers

Need help handling multiple shared I2C MAX3107 chips on shared ARM9 GPIO interrupt (linux)

Our group is working with an embedded processor (Phytec LPC3180, ARM9). We have designed a board that includes four MAX3107 uart chips on one of the LPC3180's I2C busses. In case it matters, we are running kernel 2.6.10, the latest version…
Jim Luby
  • 105
  • 1
  • 9
3
votes
1 answer

Soft I²C ping function

I am using a soft I²C implementation to read a set of Sensirion SHT21 sensors. I am trying to figure out a way of having the sensors answer to see if they are actually connected to the device. I am using the Arduino which means all my code is…
Jonny Flowers
  • 631
  • 1
  • 9
  • 20
2
votes
2 answers

PIC I2C slave ack on data

I am looking into the I2C protocol for PIC16F88X. What I would like to do, is to enable an I2C slave to either ACK or NACK depending on the data received on the I2C. The PIC can ACK or NACK on the I2C address sent on the line, but from what I've…
Gauthier
  • 40,309
  • 11
  • 63
  • 97
2
votes
0 answers

Unable to send data with I2C using STM8s in C [Solved]

I'm an engineering student and for my bachelor thesis I use a 16 channel IO expander which communicates with I2C with a STM8S microcontroller. IDE: STVD (I set the correct ARF6 byte) IO-ex: PCA8575 -> datasheet:…
Joerie
  • 77
  • 8
2
votes
0 answers

ACPI: Linux I2C Driver not binding with the device

I'm trying to modify an hwmon driver from being Device Tree specific to use the generic property APIs (for compatibility with ACPI). For the purposes of testing I'm trying to bind with the device through _HID instead of PRP0001 at the moment. I'm…
2
votes
1 answer

I2C to FPGA to PCIe to HID

We have a hardware design in progress that is taking touch screen inputs and passing them along via I2C to an FPGA. The FPGA translates the I2C data to PCIe. The PCIe passes the touchscreen data to the processor. I am wondering how to get Windows to…
Roger
  • 21
  • 1
2
votes
1 answer

I2C not working on the Raspberry Pi Pico W with MicroPython

Trying to use the Raspberry Pi Pico W and some i2c devices with micropython but running into issues. When I try to scan one device, it seems fine, but as soon as any more come onto the I2C bus, it never seems consistent with the result, most of the…