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

STM32 HAL_I2C_Master_Transmit - Why we need to shift address?

after stumbling upon very strange thing I would like to find out if anyone could provide reasonable explanation. I have SHT31 humidity sensor running on I2C and after trying to run it on STM32F2 it didn't work. uint8_t __data[5]={0}; __data[0] =…
user505160
  • 1,176
  • 8
  • 25
  • 44
2
votes
2 answers

MSP430 I2C reading a SDP610 differential pressure sensor issue

I am trying to read a SDP610 sensiron differential pressure sensor via a Texas Instruments msp430. I am having the issue of the sensor not acknowledging the command and thus, not communicating the pressure value itself. Note I have confirmed that…
Thomas Morris
  • 794
  • 5
  • 26
2
votes
2 answers

How to pass I2C addresses to Adafruit CircuitPython code? (Running ADS1115)

I'm trying to run two Adafruit ADS1115s off of one Raspberry Pi, using two I2C addresses (0x48, 0x49). The address for each device can be set by tying the ADDR pin high (0x49) or leaving it floating (default, 0x48). I've confirmed that each board…
2
votes
2 answers

Reading and Storing MSB first

I'm considered a beginner in programming, so sorry if this is a very simple question. I'm using STM32f411 uC to read from a pressure sensor MS5525DSO using I2C protocol. The programming is in c language through Eclipse. when I read a data from…
2
votes
2 answers

i2c stm32 nucleo unable to establish connection

I am new to the whole stm32 environment. I've always used arduino in the past and I wanted to try something new for this project. I am having a really hard time setting up an i2c connection between a nucleo board (MASTER) and an arduino(SLAVE). I…
Rollback
  • 2,203
  • 1
  • 11
  • 15
2
votes
0 answers

STM32 how to recover from lock up

I am trying to communicate with an SMBus battery. That has 2 sections so I am using 2 I2C modules. After the first I2C module makes a successful communication second module gets stuck. And it gets stuck in Busy. In that case I thought I need to…
2
votes
1 answer

STM32 I2C Slave Receiving Executed Only Once with DMA in HAL Library

Currently, I am implementing I2C transfer with DMA to get a fixed number of bytes. STM32 MCU: STM32L152RDT6 STM32 is slave and Arduino is master. I have implemented in Arduino which will send I2C command for 3 bytes each time. However, the callback…
黃銘賢
  • 73
  • 2
  • 9
2
votes
1 answer

ESP8266 I2C slave does not acknowledge data

I have a TM4C123 processor acting as a I2C master and a ESP8266 as a slave. For the ESP I am using the Arduino IDE with ESP8266 support installed at version 2.5.2, which should support the I2C slave mode. However, I can't get it to work. Even with…
David Wright
  • 464
  • 6
  • 18
2
votes
1 answer

Controlling the AOSP power-reporting functionality from new code

In the Android Open Source Project, where would I add/override the code which tells Android about the battery level and AC power? I need to poll a component on an i2c bus to get this information, on my board, and pass it to Android.
fadedbee
  • 42,671
  • 44
  • 178
  • 308
2
votes
1 answer

Reading BME680 from i2c 2 on Armbian

I'm trying to use BME680 sensor on BananaPI + Armbian 5.65 together with TSL 2651 on same i2c but no luck. (for reference, very same configuration is not working on RPi either) Sensor when connected alone, works, but connected together with TSL its…
fluffypuffy
  • 103
  • 1
  • 1
  • 6
2
votes
0 answers

STM32: I2C slave without enabled clock stretching feature

I have to implement on a STM32L053 an I2C slave to read/write some arbitrary bytes of memory on the slave uC and the requirement is, that it should also work for I2C masters, which are not support clock stretching (NOSTRETCH=1). I found a good…
user9564464
  • 173
  • 2
  • 16
2
votes
2 answers

Arduino as I2C slave talk to RPi

I use an Arduino as I2C slave to treat some Ultrasonic sensors and send revelant data to a Raspberry. The code running on Arduino : void setup() { // initialize i2c as slave Serial.begin(9600); Wire.begin(SLAVE_ADDRESS); // define callbacks…
2
votes
2 answers

No clock I2C STM32L0

Hi i am currently working on a project where i am using a murata cmwx1zzabz (The module is powered by an STM32L072CZ and an SX1276 transceiver). The goal eventually is to send data from my sensor(VL53L1X) using lorawan to the internet. So i started…
2
votes
2 answers

Variable sized i2c reads Raspberry

I am trying to interface A71CH with raspberry PI 3 over i2c, the device requires repeated starts and when a read request is made the first byte the device sends, is always the length of the whole message. When I am trying to make a read, instead of…
Dogus Ural
  • 583
  • 1
  • 9
  • 20
2
votes
1 answer

SPI interface 3-wire serial Si471X

I tried to find an answer to this question by searching SDIO which is related to my question based on Silicon Labs naming of data channels. However, I was flooded with topics related to the SDIO protocol for serial comms with an SD memory card - a…