I2C freeze/fail problems

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

I2C freeze/fail problems

Postby Greg Corson » Tue Jul 03, 2018 10:12 pm

I'm working on a 2-wheel balancing robot using an Adafruit feather ESP32 and I'm having very odd problems with I2C.

I have a BNO055 connected up to I2C using the Adafruit sensor APIs. I also have a couple of DRV8871 motor drivers connected to GPIO 14, 15, 32 and 33 using LEDC channels 0, 1, 2 and 3.

The Adafruit BNO055 board has 10k pullups installed, and that didn't work at all. The board would not be detected. To get reliable operation I had to put a 2.2k resistor in parallel which should bring the total value to 1.8k or so.

Then comes the weird part, when I connect the DRV8871 boards to GPIO 14,15,32 and 33 the I2C bus stops working, usually freezing up before the BNO055 can be detected or soon after I start reading from the BNO055.

The motor driver boards WORK, but when they are plugged into the GPIOs the BNO055 I2C has problems.

Any ideas on why or how to debug this?

This is all in Arduino IDE because I originally started with an Arduino board then switched to ESP32. I've been thinking about porting to the native ESP32 development environment but not sure if that would help with this problem.

madlan
Posts: 2
Joined: Wed Jul 04, 2018 10:26 pm

Re: I2C freeze/fail problems

Postby madlan » Wed Jul 04, 2018 10:29 pm

Could you try the latest Arduino ESP build? A rewrite of I2C was merged recently that is significantly better.

It can now be installed via the board manager if you are using Arduino IDE:
https://dl.espressif.com/dl/package_esp ... index.json

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: I2C freeze/fail problems

Postby Greg Corson » Thu Jul 05, 2018 2:20 pm

I updated on July 2 from the github, would this update be newer?

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: I2C freeze/fail problems

Postby Archibald » Thu Jul 05, 2018 6:32 pm

There is an alternative 'Wire' library here which is supposed to avoid some of the issues with using I²C:
https://github.com/stickbreaker/arduino ... aries/Wire

I don't know how that compares with the latest official Arduino ESP32 build.

Capacitance within connecting cables can cause trouble with I²C, even over a few metres.

Do you have an oscilloscope available to check I²C waveforms and whether there is any interference from the motor circuit? (It may help to use another GPIO to provide a pulse to trigger the oscilloscope)

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: I2C freeze/fail problems

Postby Greg Corson » Fri Jul 06, 2018 5:13 pm

I probably should have mentioned I have been looking at the problem with a Saleae Logic Analyzer/scope.

With or without the motor wires there does not appear to be any interference on the I2C bus, the signals look the same.
The I2C wires from the ESP32 to the BNO055 are about an inch long and have 2.2k pullups on them.

Sometimes the BNO055 fails to initialize on startup. When this happens I usually see a single pulse on I2C or one short exchange and then nothing else.

When the BNO055 does initialize and then fails, sometimes I see a situation where the I2C bus just goes dead, no traffic at all. Other times there is still traffic but all the BNO055 driver gets back is zeros.

I'm running 1.0.0-RC2 of ESP32 arduino from July 3. I heard people mention the "stickbreaker" I2C but thought it had been included in the RC2, do you know one way or another?

One person claimed to have tried a BNO055/ESP32 setup the same as mine and had similar problems, but when using a bit-banging I2C implementation he said it worked fine.

The suspicion is that ESP32-Arduino does not support CLOCK STRETCHING which the BNO055 sometimes uses. Do you know the status of clock stretching and if there is a way to set how much stretching is allowed?

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: I2C freeze/fail problems

Postby Greg Corson » Sun Jul 08, 2018 4:33 am

Right now I use gpio 14,15,32 and 33 as pwm outputs, via ledc

I use a0, a1, a2 and a3 as inputs.

It seems like when I start connecting these to external hardware my i2c becomes unstable. I’ve used pinMode to set these as input or output, am I missing something else that needs to be done?

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: I2C freeze/fail problems

Postby Greg Corson » Sun Jul 08, 2018 8:23 pm

I'm testing this morning and finding that my I2C from ESP32 to BNO055 seems to be stable when I disconnect the 4 pwm outputs and 4 encoder inputs. I'm gradually adding back functionality to see if I can figure out when it becomes unstable.

Just to be clear, this is how these pins are setup 14, 15, 32 and 33 are setup with
pinMode(14,OUTPUT);
ledcSetup( 0, 20000, 8);
ledcAttachPin(14, 0);

And pins 25, 26, 34 and 39 are setup for digitalRead with
pinMode(25, INPUT);

The pins appear to be functional, that is, I can read values from the input pins and PWM the output pins. But something about having them connected causes my I2C to be very unstable.

Is there anything special about these pins that has to be configured? Can't see why having them hooked up would cause I2C problems.

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: I2C freeze/fail problems

Postby Greg Corson » Tue Jul 31, 2018 7:04 pm

For the benefit of others, I found out what was causing the I2C errors. To clean up my encoder signals I was running them through a Schmidt trigger IC. I was only using 4 of the 6 schmidt triggers on the chip. It turned out that the unused triggers were occasionally breaking into very high frequency oscillation (25mhz or more) which was leaking out the other signal and power lines connected to the chip. This was messing up all sorts of things including causing a lot of unwanted interrupts and I2C errors.

The fix was to simply ground the unused inputs on the schmidt trigger IC.

It took awhile to find because the frequency and amplitude of the noise signal was so high it wasn't showing up on the logic analyzer I was using unless you set things up for maximum speed.

Hope this helps others.

Who is online

Users browsing this forum: lbernstone, pipi61 and 60 guests