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
2
votes
1 answer

Micropython: [Errno 19] ENODEV but i2c.scan() returns proper address

I am currently using an SRF-10 sensor connected to an esp32. It's being powered by 5V and I am using a level converter to bring down the voltage to 3.3V to be able to use it on the esp32. Both the SCL and SDA have a 1.8K pull up resistor as…
2
votes
1 answer

I2C slave does not answer periodically unless a new script is called

I have programmed an ATtiny1627 as I2C slave to answer to the read_i2c_block_data() function. Basically it receives the command indicating which variable to return and answers with 4 bytes representing a float. A Raspberry Pi 4 is the I2C master and…
Octavian
  • 21
  • 2
2
votes
0 answers

How to checkif an EEPROM exists at I²C?

I'm trying to detect if a removable EEPROM exists in a given system, but I ran into some problems. With configuration STM_enableRCCAPB1PeriphClock( RCC_APB1Periph_I2C1, ENABLE ); STM_resetRCCAPB1PeriphCmd( RCC_APB1Periph_I2C1, DISABLE ); I2C_Cmd(…
Knut S.
  • 21
  • 1
2
votes
0 answers

I2C LCD Library for PCF8574 through ft232h on Raspberry Pi

I'm completely lost on how to even get this to work. I have a usb ft232h breakout board that is suppose to support i2c as well as gpio. I can get basic gpio devices to work just fine however I'm having a ton of issues regarding the I2C LCD that's …
nullmage
  • 145
  • 1
  • 3
  • 8
2
votes
0 answers

Reading temperture from LM75 I2C

I'm trying to read and write bytes in an i2c bus using LM75 and a Master (USB ITS). Using a library from Github (AsyncPro for VCL 1.7) and Delphi . The problem I always get, that i receive 253 or 255 when I compile to project and try to read the…
2
votes
1 answer

trying to read and write to a specific register of ethernet switch using uboot

I am a new to linux/u-boot and just generally reading and writing to specific registers. I have a KSZ9897 Ethernet switch, and my goal is to use u-boot i2c commands to set bits [15:13] to 001 to put the switch in the proper test mode. The following…
nomar123
  • 21
  • 2
2
votes
1 answer

How to configure ACPI *.asl for a virtual mdio-gpio device connected to a I2C gpio expander

I'm working with a Q7 Module (x86) and try to configure our peripherals with ACPI SSDT Overlay on Linux. But I strugle with it. I think I missunderstand some of the core concept of ACPI. Problem CPU -> I2C -> PCA9575 GPIO Expander ->…
2
votes
1 answer

WeMos D1 Mini (ESP8266) I2C Slave Mode does not receive any incoming data

I have spent hours trying to figure out how I can get the "WeMos D1 Mini" to be in slave mode. For some reason it does not acknowledge any incoming data. From all the forums I read, everyone needs to make their own "special interrupt based I2C" code…
S To
  • 73
  • 6
2
votes
1 answer

Raspberry Pi AMG8833 Thermal Camera, How to print highest detected temperature?

I have been following this tutorial - https://www.instructables.com/Thermal-Camera-AMG833-Raspberry-Pi/ It's working well, as shown. I can see graphical temperature reference in window. The CODE: from Adafruit_AMG88xx import Adafruit_AMG88xx import…
Pavol Bujna
  • 169
  • 2
  • 14
2
votes
3 answers

I2C ISR and Interrupts

Platform - ARM9 I have a third party device connected via I2C to the ARM9. My problem is the I2C read/write is getting in a twist. It appears the IRQ line is asserted but never de-asserted when there is data to read. The read fails as the…
dubnde
  • 4,359
  • 9
  • 43
  • 63
2
votes
2 answers

ESP32 SPI/i2c/xTask interference/instability

I am currently making a high bandwidth transmitter spreading ADS1115 data over both a LoRa and NRF24 module, however, I am running into lots of issues with the task scheduler and unstable behaviour of i2c (being used for the ADC, both transmitters…
2
votes
1 answer

I2C interface using python over MacOS to Accelerometer

I plan to use StandardFirmata (already flashed to the Arduino board) protocol and be able to read/write to MMA7660FC 3-Axis Orientation/Motion Detection Sensor, which is already mounted on a Grove Beginner Kit pcb. Using Arduino code…
2
votes
2 answers

Getting notified when an I2C-Value changes in C++

I recently started experimenting with I2C-Hardware on my raspberry pi. Following this tutorial Using the I2C interface I already know how to read and set values. However, the program I want to realize needs the current value on a specific address…
user2762996
  • 566
  • 1
  • 5
  • 16
2
votes
1 answer

Accessing the i²c bus with Node-Red in Docker on a RaspberryPi 4

I am currently setting up Home Assistant with Docker on a RaspberryPi 4. I used this tutorial : https://www.reddit.com/r/homeassistant/comments/cm4tzp/guide_for_installing_on_a_raspberry_pi4_using/ as a reference - so far so good. Thing is I would…
artth
  • 31
  • 6
2
votes
1 answer

Android i2c permission denied

I’ve developed an NDK application to access an i2c device via the i2c-dev interface. This application is running on an Android development kit, on which we have connected an MPU6050 device via i2c. I’ve setup the DT binding for the device, as shown…
Ringo001
  • 163
  • 1
  • 9