Author Topic: I2C drops out after variable amount of time  (Read 24147 times)

scottmahr

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
I2C drops out after variable amount of time
« on: February 25, 2014, 01:00:00 PM »
Hi all,

I have been using the RFduino with a MPU6050 over i2c. This has seemed to work very well; we are able to sample from it at around 500hz. Now that I am using it more I have an issue where I stop communicating with the device after a time (usually 10 seconds to 2 minutes). If I reset the RFduino it works again every time. I have just connected the 6050 to an Arduino Pro Mini and it has been running for awhile now with no issues (using the same code). Has anyone else experienced anything similar?

I tried separating the power supplies for the RFduino and the 6050, but that didn't do anything.

My next step is to get a scope on the SDA and SCL pins and see what is going on. Any other ideas for good troubleshooting steps?

Thanks,

Scott 

edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #1 on: February 25, 2014, 04:56:20 PM »
I am curious how you are changing the I2C frequency of the RFduino.

I would be glad to test out my MPU/DMP code on my MPU6050 and get back to you with my results if you could advise me on how to change the two wire baud rate!

I've been hesitant to use the RFduino with my quad copter because I would not be able to pull data from the I2C bus fast enough. My control loop is at 100 Hz.

Thanks in advance

scottmahr

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #2 on: February 26, 2014, 07:20:32 PM »
Ok, I tried commenting out RFduinoBLE.begin(); and everything works. During this testing I am not sending or receiving anything over the BTLE, it seems that the fact that it is turned on is causing the i2c to lock up occasionally.

Anyone have any ideas on what to try next?

Thanks,

Scott

thoriqsalafi

  • RFduino Newbie
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #3 on: March 05, 2014, 08:06:00 PM »
hi, i have the same problem as you? anyone has a solution for this? thank you

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #4 on: March 06, 2014, 08:50:33 AM »
If the BLE is on, it takes priority over all other tasks in order to maintain the connection. You could be seeing BLE activity during the middle of your communication with the I2C device and that can cause strange things to happen. Have you tried using while (RFduinoBLE.radioActive) to avoid running timing critical code when the radio is active?

I would try something like this......
while (!RFduinoBLE.radioActive)
while (RFduinoBLE.radioActive)
then run your timing critical code here.

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: I2C drops out after variable amount of time
« Reply #5 on: March 07, 2014, 01:24:30 AM »
With the BLE not on, I've run my RFduino / MPU6050 for hours without any crashes.
However, turning on the BLE doesn't seem to return to the main loop when the radio gets priority.

It is like when the BLE radio gets priority, it doesn't return back to the program that was interrupted by
the radio?

To the extreme, I've placed the
while(RFduinoBLE.radioActive);
before every command that calls a mpu class function which inevably uses the i2c. And still doesn't return
control back.
For example..
Code: [Select]
    // reset interrupt flag and get INT_STATUS byte
    mpuInterrupt = false;
    while(RFduinoBLE.radioActive);
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    while(RFduinoBLE.radioActive);
    fifoCount = mpu.getFIFOCount();


Instead the RFduino appears to reset and runs the setup() function again over and over.

Code: [Select]
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Enabling DMP...
Enabling interrupt detection...
DMP ready! Waiting for first interrupt...
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Enabling DMP...
Enabling interrupt detection...
DMP ready! Waiting for first interrupt...

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #6 on: March 07, 2014, 09:45:22 AM »
Hi tolson, I ordered one of these MPU6050 sensors to try this out and see what is happening. Can you post a link to the library/sketch you are using?

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: I2C drops out after variable amount of time
« Reply #7 on: March 08, 2014, 12:46:04 AM »
The rebooting seems to be caused by this line.

    RFduinoBLE.advertisementData = "myDMP_MPU";

That string is 9 characters plus maybe a null if it is a true C string.
Doesn't matter. That and the default ID of "RFduino" add up
to more than 15 characters which seems to be what is causing
the reboot.

I had mentioned in an earlier post that the documents state these
two values should be < =18 characters, but I have found it to be 15.

http://forum.rfduino.com/index.php?topic=324

So looks like that issue still exists in the 1.7.1. I forgot and it bit me.
Changing the string to "myDMP_MP" was enough to keep it from rebooting.

However, now I am having the problem others are referring to in this thread
in that my RFduino now locks up within a few seconds to a couple minutes
with BLE turned on and DMP running.

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #8 on: March 11, 2014, 04:55:08 PM »
Checked out the MPU6050 with the BLE running and I'm not having a drop out issue. Using this:
http://playground.arduino.cc/Main/MPU-6050

If you get error 'pstr" was not declared, add this:

#define F(X) (X)

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: I2C drops out after variable amount of time
« Reply #9 on: March 12, 2014, 02:51:15 AM »
That version reads registers directly, but does no 6 axis fusion.
 Check out the MPU6050_DMP6 sketch instead.
Without BLE active the MPU DMP FIFO runs smoothly. With the radio on, the FIFO
eventually gets overflow and lost. The MPU6060_DMP library isn't prepared to
deal with the delays caused by the radio having priority. Not really a RFduino
problem as much as the MPU built-in DMP processor has no way to know
what the radio is doing as written. What we really need to do is stop the DMP
during radio priority.

thoriqsalafi

  • RFduino Newbie
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #10 on: March 14, 2014, 12:55:16 AM »
yes you can use this library from jrowberg http://www.i2cdevlib.com/devices/mpu6050#source and try for the euler angle and send it to your phone, may be you can figure how to make the mpu6050 stop. thanks

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: I2C drops out after variable amount of time
« Reply #11 on: March 14, 2014, 11:21:27 PM »
Yes, that is that the library we are talking about already.
 We aren't interested in Euler. Only Quaternions as fused by the DMP.

scottmahr

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #12 on: March 16, 2014, 03:21:40 PM »
I am not trying to use the DMP, and it still crashes after a while of running. Please try the code copied below. It will run fine, sometimes for hours, but every once in a while the i2c will drop out and it will return the same values over and over again. I can see this on a scope, the clock line is a nice square wave, then flat lines at around .1 volts. If I just restart the RFduino it doesn't fix it all of the time. I have to power cycle the MPU6050 as well.

Code: [Select]

#include <RFduinoBLE.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

//Stuff for the MPU6050
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;


void setup() {
  RFduinoBLE.begin();
  //Setting up wire
  Wire.begin();
  Serial.begin(9600);
  Serial.println("Initializing I2C devices...");
  accelgyro.setSleepEnabled(false);
  delay(10);
  accelgyro.initialize();
  // verify connection
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}



void loop() {
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    delay(10); 
        Serial.print("a/g:\t");
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
 

}



tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: I2C drops out after variable amount of time
« Reply #13 on: March 16, 2014, 04:19:11 PM »
Hi scottmahr,

Yep, it is starting to look like there is something odd about the Wire Library
loosing itself when the radio is on. There seems to be several threads using
different kinds of parts on the i2c bus experiencing this odd lock up of the i2c
service.

I don't know how the Arduino wire library behaves when it gets interrupted for
extended periods of a time. Certainly would be nice to pin it down though.


scottmahr

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: I2C drops out after variable amount of time
« Reply #14 on: March 16, 2014, 04:40:55 PM »
Just tried putting
while (RFduinoBLE.radioActive)
right above my call to
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
and it didn't change anything.