Translate

Saturday, June 15, 2024

Problems connecting I2C devices

 

Problems that arise when the I2C peripheral board is powered by 5 volts and the MCU to which it is connected is powered by 3.3 volts.

Giovanni Carrera, 15/06/2024

There are many device boards on the market with I2C (IIC: Inter-Integrated Circuit) bus such as sensors, displays, EEPROM, RTC clocks, etc. This bus is widely used because it requires only two signals: SDA and SCL.

SDA (Serial Data) is the data signal and SCL (Serial Clock) is the clock signal, both are bidirectional. Along with power, only four wires are needed to connect these boards, plus multiple I/O devices can be connected to the bus. Usually the MCU, for example Arduino, is the Master and starts and ends communication with a peripheral which is the Slave that receives commands and sends data to the Master. Communications take place at much higher speeds (typically 400 kbit/s) than the RS232 serial but are slower than the SPI bus.

Each peripheral is characterized by a 7-bit address in the standard version, so up to 128 peripherals can be addressed. There is also an extended version, with a 10-bit address.

Communication takes place with a standard I2C protocol.

The characteristic of the I2C bus is that both the clock signal (SCL) and the data signal (SDA) are driven open drain or open collector to avoid damaging the outputs of devices that could be connected at the same time. This means that the I2C controllers can only bring the output to zero level and that to return it to a high level it is necessary to use two pull-up resistors, almost always mounted on the peripherals. Their values ​​range from 2k to 10k ohm, the higher the bit rate the lower the resistance value must be, this is because there are parasitic capacitances that can create delays.

If there are multiple devices connected to the bus, you need to check that there are not too many pull-up resistors which would excessively load the outputs.

Things become problematic if we have to connect a peripheral device powered by 5V, such as an LCD display, compatible HD44780, with a MCU powered by 3.3V and not 5V tolerant, such as an ESP. If the I2C LCD board has two pull-up resistors mounted on the 5V, they must be removed and two external resistors connected to the 3.3V of the ESP mounted. It is true that the presence of the pull-up resistor limits the current on the ESP input, but the chip could be damaged after some time.

 

Example: LCD display with I2C interface

The classic two-line 16-character alphanumeric LCD display, with HD44780 type controller, has an 8 or 4 bit parallel interface plus some control pins and also backlighting. There are small interface cards that are soldered to the 14 or 16 pins and allow you to transform the parallel interface of the display into an I2C serial interface. They usually use the Philips PCF8574 chip as a 8 bit parallel to I2C converter. Figure 1 shows what one of these cards typically looks like.

Fig.1 

Before connecting it, you need to check whether the pull-up resistors are mounted, which is normally done. In the case of the PCF8574 (DW or N package) the bus pins are: 15 (SDA) and 14 (SCL).

The ESP8266/32 have power and levels at 3.3V and the GIPIO are not 5V tolerant, so the first thing I looked at was the level of the output signals.

The classic solution is to use a bidirectional level adapter, but there is also a simpler solution: the one I used.

Once you have ascertained that the pull-ups are present, they must be removed by desoldering them with a little caution because they are smd.

If we want to connect this module to ESPs or other microcontrollers powered by 3.3V, we must desolder the 4.7 kohm resistors with a little caution because they are smd. Since my intent is also to consume less current, I also removed the 1 kohm resistor of the useless red LED L and the one near the transistor. In figure 2 you can see the positions of the four resistors to be desoldered.

Fig.2

Obviously it is necessary to connect two 4.7 kohm resistors wired to +3.3V,  externally or mounted on ESP board, as in the example shown in figure 3.

Then we must set the I2C address using the three jumpers near the trimmer that regulates the contrast. If we do not solder the jumpers: A0=A1=A2 =1, so the address will be 0x27.

Fig.3