Sample I2C code
bdickens
Posts: 110
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.
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
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
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.
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