Shop OBEX P1 Docs P2 Docs Learn Events
Sample I2C code — Parallax Forums

Sample I2C code

bdickensbdickens Posts: 110
edited 2010-06-08 17:05 in Propeller 1
I am looking at a project that could use I2C and the posting of the new I2C driver peaked my interest. But I have to confess that I'm not seeing how I could call two different I2C devices without rewriting some of the interface. Does someone have a code sample that shows how to access two different sensors (compass, temperature , whatever etc) across the same code ? I was thinking that this would take one cogs worth of code, but we could use one routine to call multiple sensors.

I could of course run two copies of the code in two different cogs using 2 different sets of pins, but that seems like it defeats the point.

To be quite fair, I have the same question around any of the bus based communications protocols. So if someone has a chunk of code that hits two different sensors/devices I would appreciate it.

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2010-06-06 23:31
    You may be referring to the Pasm I2C Driver I posted in the OBEX a few hours ago.· This is a PASM version of Mike Green's Basic I2C Driver.· I needed a higher speed I2C driver, and I couldn't find any assembly drivers in OBEX, so I converted some of the low level routines in the Basic I2C Driver to assembly.· I know there are other assembly drivers around, but they are part of a larger set of objects, and I thought it would be useful to have a stand-alone object in the OBEX.

    You can drive multiple I2C chips with the same clock and data lines.· Different types of devices will have a different device select code.· Most devices also have external address pins that can be typed high or low to respond to the lower bits in the device select byte.· There are typically two different I2C bus speeds -- 100 KHz and 400 KHz.· I don't think it's a good idea to hang a 100 KHz device on the same clock/data lines as a 400 KHz device clocked at full speed.· It will violate timing specs on the 100 KHz device.

    Use "I2C" in the search box for OBEX and you will see examples of various devices that have been interfaced.

    Dave
  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-07 00:39
    The I2C drivers in the Object Exchange can handle a variety of I2C sensors. obex.parallax.com/objects/251/ can handle several different devices.

    The I2C driver (sdspiFemto.spin) that's part of FemtoBasic is written in PASM, can be used completely separately, and can handle any kind of I2C device. There's one example of this in BoeBotBasic where this driver handles an I2C I/O Expander in addition to I2C EEPROMs.
  • bdickensbdickens Posts: 110
    edited 2010-06-08 17:05
    Mike - I downloaded that set and I'll take a look. That may be what I'm asking although it will take me some time to absorb.
    Dave - Yes, it was your driver that re-caught my attention. But if I search on OBEX, I find lots of objects that support a single device. I was looking for code that supports two devices in the same program across a common bus.

    I'll take the examples and probably come back with a follow up note once I have a better grip.

    Thanks
Sign In or Register to comment.