3

I'm trying to communicate with an old i2c device and I'm getting wrong read values, and possibly even some incorrect write values too.

My logic analyzer shows random highs in the middle of a low.

This happens mostly on software i2c but I get incorrect reads on the hardware i2c too.

What could cause these spikes?

Here's an illustration. Look at the end of the second byte (C0) enter image description here

Edit: This seems very related: https://www.raspberrypi.org/forums/viewtopic.php?t=223056

  • I don't know how to use Rpi software I2c, but hardware I2c has caused me enough headache these couple of years. So I gave up and wait for Rp4 and stretech10. I also don't use logic analyzer, because the logic analyzer hides way ugly glitches, which scope makes them transparent. Yes, I know there are dual mode analyzer/scope, and my cheap socpe can also analyze,a do realtime transofrms, report back even FFT figures, not to mention other trivial algebric calculations. Things are moving too fast to catch up. SuperTem that I have been using for UART for years can now even do I2C jobs, ... :) – tlfong01 May 2 at 1:16
  • I noticed that for a couple of I2C devices, the vendors usually do tricks to remove noisy, fluctuating read data, such as taking moving average, trim max min etc. Others use smart digital filters, ... – tlfong01 May 2 at 1:23
  • Damn bro you gonna answer all my questions? haha. For real though, I'm thiking of trying other ARM linux boards or something. I need a reliable i2c master. – vaid May 2 at 1:24
  • Or Rpi as a stupid and weak master, making greedy wishes to the mighty Aladdin Lamp slave, the STM32 Blue Pill, :) – tlfong01 May 2 at 1:48
  • But I need a Linux board – vaid May 2 at 2:06
3

The solution is to bridge the RPi GND and 3v using a cap.

I used a 1uF cap.

  • 3
    I suspect the root cause of most Pi I2C problems can be traced to an electrical fault, e.g. poor wiring, loose wiring, out of I2C spec wiring etc. – joan May 2 at 7:15
  • Standard bypass/decoupling caps are 10uF tantalum and 0.1 ceramic, near device, and much bigger bypass, 100uF or larger electrolyte at PSU. I use Guinness Record breaking value of 10,000 uF. :) – tlfong01 May 3 at 5:42
2

Question

I2C device reading writing errors problem. How to solve it?

Answer

There are many reasons causing reading and writing errors. To name a few:

  1. Wires too long (more than 30cm) and not twisted. A suggestion is to use twisted cable Cat 5 to reduce mains EMI noise picking up,

  2. I2C speed too high. A suggestion it to start testing a low speed, such as 100kHz,

  3. Pullup overloading Rpi which already has 1k8 pull up. A suggestion is to remove ALL pullups of the I2C devices,

  4. Rpi I2C circuit too noisy. A suggestion is to use logical level converters such as TXS010n, TXB010n to step up 3V3 signal to 5V (high level means low risk of noise etc problem)

  5. PSU dirty. A suggestion is to place standard bypass/decoupling cpas 10u tantalum and 0.1 ceramic near the device and also near the Rpi mciro USB connector.

rpi psu cap

ads1115 pullup removal

/ to continue, ...

References

I2C Manual - Application Note AN10216-01 - NXP

I2C Bus Pullup Resistor Calculation - Application Report SLVA689–February 2015 - TI

Clean Power for Every IC, Part 1: Understanding Bypass Capacitors - Robert Keim, AAC 2015sep21

Clean Power for Every IC, Part 2: Choosing and Using Your Bypass Capacitors - Robert Keim. AAC 2015sep27

Introduction

It is not inconceivable that a dedicated, successful engineering student would graduate from college knowing almost nothing about one of the most pervasive and important components found in real circuits: the bypass capacitor. Even experienced engineers may not fully understand why they include 0.1 µF ceramic capacitors next to every power pin of every IC in every circuit board they design. This article provides information that will help you to understand why bypass capacitors are necessary and how they improve circuit performance, and a follow-up article will focus on details related to choosing bypass capacitors and the PCB layout techniques that maximize their efficacy.

...

Solution

it is convenient that such a serious problem can be effectively resolved with a simple, widely available component. But why the capacitor? A straightforward explanation is the following: A capacitor stores charge that can be supplied to the IC with very low series resistance and very low series inductance. Thus, transient currents can be supplied from the bypass capacitor (through minimal resistance and inductance) instead of from the power line (through comparatively large resistance and inductance). To better understand this, we need to review some basic concepts related to how a capacitor affects a circuit.

First, though, a brief note about terminology: The components discussed in this article are regularly referred to as both “bypass capacitors” and “decoupling capacitors.” There is a subtle distinction here—“decoupling” refers to reducing the degree to which one part of a circuit influences another, and “bypass” refers to providing a low-impedance path that allows noise to “pass by” an IC on its way to the ground node. Both terms can be correctly used because a bypass/decoupling capacitor accomplishes both tasks. In this article, however, “bypass capacitor” is favored in order to avoid confusion with a series decoupling capacitor used to block the DC component of a signal.

A Standard Approach

The foregoing analysis helps us to understand a classic bypassing scheme:

a 10 µF capacitor within an inch or two of the IC, and

a 0.1 µF ceramic capacitor as close to the power pin as possible:

The larger capacitor smooths out lower-frequency variations in the supply voltage, and the smaller capacitor more effectively filters out high-frequency noise on the power line.

If we incorporate these bypass capacitors into the 8-inverter simulation discussed above, the ringing is eliminated and the magnitude of the voltage disturbance is reduced from 1 mV to 20 µV, ...

Update 2019may04hkt0846

Grounding is also a problem. See the ADXL346 Datasheet's suggestion below.

ADXL345 grounding

  • @tifong01 where were you eaaarlieeeeerrrrrr – vaid May 3 at 7:38
  • What do you mean? I have been around all the time. – tlfong01 May 3 at 7:57
  • with all this information. I needed it before haha – vaid May 3 at 7:59
  • Well, I usually suggest things to newbies only AFTER they have made stupid mistakes. This way they learn harder but remember important things longer. And otherwise they won't bother to listen to the old guy. :) I heard that you have a logic analyzer, so I guess you should have more advanced knowledge than a poor hobbyist like me - therefore no suggestions needed before or after. – tlfong01 May 3 at 8:10
  • Having a logic analyzer =/= Having electrical engineering knowledge Having a logic analyzer == Reading data protocol – vaid May 3 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.