Quantcast

i2c Communication Errors

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

i2c Communication Errors

Evan
Hi all,

I am trying to communicate with a brushless DC motor controller (BL-ctrl
V2.0) via i2c on a Gumstix Overo AirStorm. The motor controller is at slave
address 0x29. I have made a simplified code that opens the i2c device, then
repeatedly sends a speed of 20 to the motor controller. I am using the
following c code:

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>

int main()
{
    int fi2c, io, ew;
    uint8_t thr;

    printf("Opening i2c port...");
    fi2c = open("/dev/i2c-3", O_RDWR);
    if(fi2c<0)
        printf("Error opening i2c port.\n");
    else
        printf("The i2c port is open.\n");

    thr = 20;
    if(ioctl(fi2c,I2C_SLAVE,0x29)<0)
    {
        printf("ERROR: ioctl\n");// no errors here yet
    }

    while(1)
    {
        ew = write(fi2c,&thr,1);
        if(ew!=1)
        {
            printf("ERROR: write error is %d.\n",ew);
        }
        usleep(10000);// 10 ms delay
    }
}

I can control the average speed this way, but the issue is that the motor
speed shoots up and down and occasionally stops, then restarts. When
troubleshooting I found that the 'write' command is only successful about
93% of the time.

I have been stuck on this problem for quite some time, so any help would be
greatly appreciated. Do you have any suggestions about 'write()' or another
command used to communicate via i2c?

Thanks,
Evan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

S.A. Ridley
Do you have any i2c debugging hardware like the Beagle to see if the data on the bus coming
out of the Gumstix is actually correct?

On Mar 24, 2013, at 1:18 PM, Evan wrote:

> Hi all,
>
> I am trying to communicate with a brushless DC motor controller (BL-ctrl
> V2.0) via i2c on a Gumstix Overo AirStorm. The motor controller is at slave
> address 0x29. I have made a simplified code that opens the i2c device, then
> repeatedly sends a speed of 20 to the motor controller. I am using the
> following c code:
>
> #include <stdio.h>
> #include <string.h>
> #include <fcntl.h>
> #include <linux/i2c-dev.h>
> #include <sys/ioctl.h>
> #include <unistd.h>
> #include <errno.h>
> #include <stdint.h>
>
> int main()
> {
>    int fi2c, io, ew;
>    uint8_t thr;
>
>    printf("Opening i2c port...");
>    fi2c = open("/dev/i2c-3", O_RDWR);
>    if(fi2c<0)
>        printf("Error opening i2c port.\n");
>    else
>        printf("The i2c port is open.\n");
>
>    thr = 20;
>    if(ioctl(fi2c,I2C_SLAVE,0x29)<0)
>    {
>        printf("ERROR: ioctl\n");// no errors here yet
>    }
>
>    while(1)
>    {
>        ew = write(fi2c,&thr,1);
>        if(ew!=1)
>        {
>            printf("ERROR: write error is %d.\n",ew);
>        }
>        usleep(10000);// 10 ms delay
>    }
> }
>
> I can control the average speed this way, but the issue is that the motor
> speed shoots up and down and occasionally stops, then restarts. When
> troubleshooting I found that the 'write' command is only successful about
> 93% of the time.
>
> I have been stuck on this problem for quite some time, so any help would be
> greatly appreciated. Do you have any suggestions about 'write()' or another
> command used to communicate via i2c?
>
> Thanks,
> Evan
>
>
>
>
> --
> View this message in context: http://gumstix.8.n6.nabble.com/i2c-Communication-Errors-tp4967049.html
> Sent from the Gumstix mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> gumstix-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gumstix-users


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

acsmith
This post was updated on .
In reply to this post by Evan
Hi Evan,

I've implemented the same thing on an Overo FireStorm with Summit and Robovero boards with a BL-CTRL.  Your code looks identical to mine.  Are you doing voltage level conversion on the I2C?  The BL-CTRL uses 5V but the Overo uses 1.8V.  Plus you'll need pull-up resistors on the buses.


Andrew
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

Kaufman, Evan
Thanks for the responses.

S.A. Ridley,

Thanks for your suggestion; I have not used a debugger but I will look into that. I have some intuition that the i2c communication is the reason for my problems; I put in an error comment whenever my write command != 1, which aligns with the slowdown or speedup of the motor. This is easier to see, of course, when I increase the delay through the 'while' loop.


Andrew,

That's interesting. I've tried this code with two different voltage level converters, unfortunately yielding the same results. I also tried this code on both Overo AirStorm and Earth models. If you called any variables or functions differently I would be very interested in how you did this.


Thanks,
Evan

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

acsmith
I'll post my code below but it's basically the same (except I'm writing two bytes for each motor, v2 of the BL-CTRL uses 11 bit motor command resolution).  I was successful using a Maxim 3373 with the Summit board (not with the Robovero though).  The Maxim chip has internal 10K pullup resistors so it was super simple to get it working, just connect the wires with some capacitors as shown in the Maxim datasheet and I was up and running.  Maybe a good thing to do is like Ridley said, try and look at the signal going through the bus.  I debugged my Robovero setup with a scope, I could watch the bits go across the bus.

I'm pretty sure the BL-CTRL will work anywhere from 100KHz to 400KHz.  I'm currently running it at 400KHz and I think the Overo by default boots up with the I2C bus at 400KHz, so that should be good.  The code is basically the same as yours, hopefully you can figure out your problem.  I wasn't running this in a traditional main() loop so I had to cut and paste it from sections of the code, I've tried to structure it like you've got.

Andrew

            #define BL_Motor(motor)   (0x29+motor)

            uint16_t tempInput;
            uint16_t motor_cmd[1];
            // buffer holds the two bytes that make up the 11 bit command
            uint8_t buffer[2];
            int_t motor_index = 0;
            int_t fh = open("/dev/i2c-3", O_RDWR);
            motor_cmd[motor_index] = 100;
            while(1)
            {
                // only take least significant 11 bits
                tempInput = 0x07FF & motor_cmd[motor_index];
                // set motor index
                ioctl(fh, I2C_SLAVE, BL_Motor(motor_index));
                // grab the 8 MSB
                buffer[0] = (tempInput & 0x7F8) >> 3;
                // grab the 3 LSB
                buffer[1] = tempInput & 0x07;
                // write the data to the I2C bus        
                write(fh,buffer,2);
            }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

Evan
In reply to this post by Evan
Andrew,

You were a huge help. It turns out that when I reexamined the wiring of the voltage level converter, the two ground levels were not identical, leading to issues with communication. It's working great now.

Thanks again,
Evan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

acsmith
Awesome, glad you got it up and running.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c Communication Errors

S.A. Ridley
Nice! Glad it worked. You probably don't need it now, but if you
ever want to take a look at the i2C debugger I was telling you about, this one
is great:
http://www.totalphase.com/products/beagle_ism/

On Mar 24, 2013, at 3:11 PM, acsmith wrote:

> Awesome, glad you got it up and running.
>
>
>
> --
> View this message in context: http://gumstix.8.n6.nabble.com/i2c-Communication-Errors-tp4967049p4967055.html
> Sent from the Gumstix mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> gumstix-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gumstix-users


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Loading...