energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
795 stars 671 forks source link

Enhance Wire to allow for multiple instances #830

Open robertinant opened 8 years ago

robertinant commented 8 years ago

With the current implementation of Wire (I2C) only one instance is possible due to some none instance based variables in the I2C state machine.

itiserik commented 8 years ago

These multiple instances are only needed when the hardware supports multiple i2c interfaces. It is only for devices with both USCI_B0 and USCI_B1. Just because a software i2c interface is integrated in twi.c/h, I assume a need to have multiple instances. But I think we better go with a true software Wire lib.

And before inventing something new on this lib please apply some pull requests (otherwise they can't be applied anymore), fix master repeated start and cleanup the code. Please test before releasing a new energia version.

rei-vilo commented 8 years ago

Feel free to join the team! You're welcome!

altineller commented 6 years ago

I am looking for ways to use multiple i2c ports on the TM4C123. I read the Wire.h and Wire.cpp that belongs to the TivaC hardware. And I noticed at the end of Wire.cpp

void TwoWire::setModule(unsigned long _i2cModule) { i2cModule = _i2cModule; if(slaveAddress != 0) begin(slaveAddress); else begin(); }

//Preinstantiate Object TwoWire Wire;

  1. that every time we setModule, it will start that module again with begin()
  2. object is preinstantiated

There is this structure: pin and device configuration is laid out in arrays. every time a function executes it executes according to i2cModule number.

So it should work without the begin in setModule statement? Maybe there is a reason why it is made like this?