Shop OBEX P1 Docs P2 Docs Learn Events
multi byte i2c with current interface, is it possible? — Parallax Forums

multi byte i2c with current interface, is it possible?

ypapelisypapelis Posts: 99
edited 2012-10-14 09:20 in Propeller 1
I am trying to read a pololum 9 DOF imu (http://www.pololu.com/catalog/product/1264/resources) using the i2c driver in propgcc.

One problem I run into, is that if I use the simple_i2cOpen call, I can't get any devices to respond. The same setup can talk to all three sensors using SPIN so I know that from a hardware standpoint things are intact.

I used instead the i2cOpen, but when the magnetometer requires that six bytes be read in a multi-byte sequence, without resending the start bit. I can't see how I can do this since the i2c interface does not expose the low level start/stop bit functionality (except for specifying if the ack-bit should be set or not).

I have SPIN code that will read the mag fine but I am trying to avoid bit-banging the i2c bus and want to use the built-in driver. Is it possible to do so?

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2012-09-07 20:20
    ypapelis wrote: »
    I am trying to read a pololum 9 DOF imu (http://www.pololu.com/catalog/product/1264/resources) using the i2c driver in propgcc.

    One problem I run into, is that if I use the simple_i2cOpen call, I can't get any devices to respond. The same setup can talk to all three sensors using SPIN so I know that from a hardware standpoint things are intact.

    I used instead the i2cOpen, but when the magnetometer requires that six bytes be read in a multi-byte sequence, without resending the start bit. I can't see how I can do this since the i2c interface does not expose the low level start/stop bit functionality (except for specifying if the ack-bit should be set or not).

    I have SPIN code that will read the mag fine but I am trying to avoid bit-banging the i2c bus and want to use the built-in driver. Is it possible to do so?
    I'm not sure what's happening with the simple i2c driver but both of them should only set the start condition at the beginning of a byte sequence. If you specify a byte count of greater than one and supply the right size buffer you should get a sequence of bytes with no start or stop conditions in the middle.
    I2C *dev;
    uint8_t buffer[4];
    int address;
    
    i2cRead(dev, address, buffer, sizeof(buffer), TRUE);
    
  • ypapelisypapelis Posts: 99
    edited 2012-09-07 20:35
    David Betz wrote: »
    I'm not sure what's happening with the simple i2c driver but both of them should only set the start condition at the beginning of a byte sequence. If you specify a byte count of greater than one and supply the right size buffer you should get a sequence of bytes with no start or stop conditions in the middle.
    I2C *dev;
    uint8_t buffer[4];
    int address;
    
    i2cRead(dev, address, buffer, sizeof(buffer), TRUE);
    

    Thanks Dave, that makes sense; after I posted I realized that I can just stick more bytes in the buffer, specify the size and it should work.

    I think the multi-byte works now but I am still not getting correct data from the sensors. Data comes out, but it's not correct.

    I was also wondering about the last argument to the i2copen() function, is it the actual data rate (i.e., 400000) or a symbolic constant? It would be great to have some functioning examples with actual devices so some of these things become clear, but i guess all in due time ...

    Thanks again !
  • David BetzDavid Betz Posts: 14,516
    edited 2012-09-07 21:07
    ypapelis wrote: »
    Thanks Dave, that makes sense; after I posted I realized that I can just stick more bytes in the buffer, specify the size and it should work.

    I think the multi-byte works now but I am still not getting correct data from the sensors. Data comes out, but it's not correct.

    I was also wondering about the last argument to the i2copen() function, is it the actual data rate (i.e., 400000) or a symbolic constant? It would be great to have some functioning examples with actual devices so some of these things become clear, but i guess all in due time ...

    Thanks again !
    The last parameter is supposed to be the actual data rate although it may not be exact. 400000 is the maximum that it supports at the moment.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-09-07 21:11
    ypapelis wrote: »
    Thanks Dave, that makes sense; after I posted I realized that I can just stick more bytes in the buffer, specify the size and it should work.

    I think the multi-byte works now but I am still not getting correct data from the sensors. Data comes out, but it's not correct.

    I was also wondering about the last argument to the i2copen() function, is it the actual data rate (i.e., 400000) or a symbolic constant? It would be great to have some functioning examples with actual devices so some of these things become clear, but i guess all in due time ...

    Thanks again !

    Here is an example that talks to an ADC chip.
  • tlperrinetlperrine Posts: 2
    edited 2012-10-13 16:23
    David,

    Is it possible to post or point me to examples of c code that uses the i2copen, i2cread, and i2cwrite application program interfaces. I am trying to communicate with the altimeter module MS5607 and compass module 3 axis HMC5883L.

    Thanks,
    Terry
  • David BetzDavid Betz Posts: 14,516
    edited 2012-10-13 19:32
    tlperrine wrote: »
    David,

    Is it possible to post or point me to examples of c code that uses the i2copen, i2cread, and i2cwrite application program interfaces. I am trying to communicate with the altimeter module MS5607 and compass module 3 axis HMC5883L.

    Thanks,
    Terry
    I'm afraid that I rewrote my i2c sample code for the PropBOE ADC to use my new ADC driver so I don't have the old code that used the i2c driver directly anymore. I'll try to dig through my archives and find it. Sorry for the delay.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-10-13 19:53
    tlperrine wrote: »
    David,

    Is it possible to post or point me to examples of c code that uses the i2copen, i2cread, and i2cwrite application program interfaces. I am trying to communicate with the altimeter module MS5607 and compass module 3 axis HMC5883L.

    Thanks,
    Terry
    Here is some code I wrote a while back that uses the i2c library functions. Unfortunately, It talks to the Parallax compass sensor.
  • tlperrinetlperrine Posts: 2
    edited 2012-10-14 08:15
    David,

    Thanks alot. With a couple of minor tweeks, that did the trick.

    Terry
  • David BetzDavid Betz Posts: 14,516
    edited 2012-10-14 09:20
    tlperrine wrote: »
    David,

    Thanks alot. With a couple of minor tweeks, that did the trick.

    Terry
    Great! I'm glad it was helpful.
Sign In or Register to comment.