I2C Noise and data corruption- USB battery v mains adapter(s) show diff behavior - Page 1
Forum section: electronics / beginners

author: USER_1234567890
author_rank: Newbie
timestamp: March 24, 2022, 07:54:33 am
content: Hi all,I've got a relatively simple device - a Wemos D1 Mini running a SD card module plus the following I2C devices: 1306 driven OLED, SHT85 humidity and temperature sensor plus a MS5837 pressure sensor. All of those are powered off of a 3.3v bus.I've got pullup resistors (started with none, then 10k then 2k with no difference in results) on the I2C lines (SDA and SCK) and and a 47 uf electrolytic cap on the 3.3v rail.I'm using it to sample process air in an industrial (i.e. fairly electrically noisy) environment.When I run it off of a USB battery, everything works fine, indefinitely.When I run it off of any of multiple USB adapters into the 5V in or via a mains to 3.3v adapter, the data recorded (and screen) become increasingly corrupted. I'm also writing a time string to the SD card, and that's recording without error, so I think the issue is entirely on the I2C bus. Worth noting that it works fine on mains power (USB or other adapter) in an office environment.Before I sit down and actually learn how to use my scope in anger, has anyone here run into a similar circumstance?Thanks in advance,Chris

author: tooki
author_rank: Super Contributor
timestamp: March 24, 2022, 03:09:31 pm
content: How long is the I2C bus? It’s not designed for anything but short distances. How’s it wired up? Does adding a ceramic cap (e.g. 100nF - 10μF) to the 3.3V rail help?NXP makes a chip, thePCA9615that turns I2C into a differential signal that can handle longer distances and reject noise. (I’d like to try it in a project I’m working on now, but nobody has any in stock. :/ )

author: USER_1234567890
author_rank: Newbie
timestamp: April 05, 2022, 07:32:13 am
content: Apologies - got sidelined and forgot to check back in. The bus is all of 30mm long. Should I expect different behavior from a ceramic cap vs an electrolytic one on the 3.3V rail?

author: tooki
author_rank: Super Contributor
timestamp: April 05, 2022, 05:23:38 pm
content: 30mm is nothing. You didn’t answer my question about how it’s wired: PCB traces? Cables? Something else?Ceramic and electrolytic capacitors have very different high frequency behavior. In particular, ceramics are much better at filtering high-frequency noise, which is often the kind of stuff one is dealing with.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 05, 2022, 05:31:18 pm
content: I've had similar problems with some other IC. Thought at first it was the chip's fault. Turned out the cause was the reflections in the transmission lines (caused by the wires that were forming a transmission line and the impedance miss-matching).Try to add a small series resistor with each wire, so to lower the ringing in the wires.

author: free_electron
author_rank: Super Contributor
timestamp: April 05, 2022, 06:45:17 pm
content: Quote from: tooki on March 24, 2022, 03:09:31 pmNot true. it was designed for noisy environments like TV chassis to reduce the number of communicating lines between chips. Old analog picture tube TV's were electrically VERY noisy.that's why the bus can detect level errors and has an abort - retry mechanism if a state change does not happen correctly. Problem is that almost none of the i2c driver code implements it !Get your pullups correct , route SCL and SDA correctly ( separated by a ground ) .I2c is even used in 19 inch compute racks as system management bus.I've ran i2c over long distance using current injectors instead of simple pull up resistors without issues.. twisted pair ethernet cable. SCL+gnd and SDA+gnd the other two were power pairs. works like a champ.Now there is indeed differential i2c. Maxim (linear tech) also makes transceivers for that.

author: tooki
author_rank: Super Contributor
timestamp: April 05, 2022, 07:26:19 pm
content: Quote from: free_electron on April 05, 2022, 06:45:17 pmI didn’t say anything about noise immunity. I said it’s not designed for long distances, and it’s not. This is widely documented, and the fact that transceivers to differential, different voltages, etc. exist only prove this. (The I2C spec only mentions length once — the order of the traces/conductors for lengths over 10cm — but the maximum bus capacitance is what forms the limiting factor.)Quote from: free_electron on April 05, 2022, 06:45:17 pmSo yeah… workarounds for it not actually being designed for long distances. (Not that I’m against workarounds if they work! Just saying that it was not originally designed for long distances.)

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 05, 2022, 09:49:13 pm
content: I2c is meant to be used on-board, if using wires and the AC adapter, you might be picking mains AC noise.Try twister pairs to provide some shielding, each being sda+gnd, SCL+gnd.Add 100nF+1uF between VCC and gnd in every device connected to the i2c bus.Try using 4k7 pullups at the start and also at the end of the bus, might work like some sort of termination.

author: free_electron
author_rank: Super Contributor
timestamp: April 06, 2022, 07:26:17 pm
content: Quote from: tooki on April 05, 2022, 07:26:19 pmThat is the only correct answer. Hence the usage of current mode injectors instead of pullups. Linear technologies has some of those. Many newer I2C devices have special active pull-up structures where they use two fets. They turn on a low impedance path to pull hard up and then switch that off after a few nanoseconds to a residual current. the PCA9xxx family has those i believe.Quotedepends what you mean by long.. on a single board tv chassis the bus length could be well over a meter , often going onto a wire bundle or connector to a second board or third board. Philips, Loewe, B&O , Salora, Finlux, Noka. They all did it. ( i worked at Salora as an intern in 1989). thos ewere the days. the ITT 2000 digivision chipset.. based on a 8048 core.

author: USER_1234567890
author_rank: Newbie
timestamp: April 07, 2022, 12:33:52 am
content: Sorry! Wired via cables. Will try the ceramic cap first, since that's the easiest one. Second easiest one will be ground twisted pairs for SCL and SDA. I've got pullup resistors on the recieving end. I'll check the sensor chip spec sheet; I thought they had internal pullups, but will re-check.Thanks!

author: USER_1234567890
author_rank: Newbie
timestamp: April 14, 2022, 09:09:33 am
content: Posting for posterity... 47uf ceramic cap on 3.3 + twisted pair on SCL, SDA fixed it - not sure which one fixed it more, but maybe I'll circle back later and figure that out.