This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to enable multiple I2C on Energia?

Other Parts Discussed in Thread: ENERGIA

Hi,

I'm trying to read a BH-1750FVI light sensor using the "i2c.h" of Energia.

I'm planning to select the I2C channels instead of using an i2c Multiplexer to reduce the design.

I'm using the code below but cannot get the results working.

   #include <Wire.h>
    #include "eusci.h"
    #include "i2c.h"
    int x;
    float z;
    int addr = 0x23;
    
    const eUSCI_I2C_MasterConfig i2cConfig =
{
        EUSCI_B_I2C_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
        3000000,                                // SMCLK = 3MHz
        EUSCI_B_I2C_SET_DATA_RATE_400KBPS,      // Desired I2C Clock of 100khz
        0,                                      // No byte counter threshold
        EUSCI_B_I2C_NO_AUTO_STOP                // No Autostop
};

void Wiresetup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  I2C_enableModule(EUSCI_B1_MODULE);
  I2C_setSlaveAddress(EUSCI_B1_MODULE, addr);
  I2C_setMode(EUSCI_B1_MODULE, EUSCI_B_I2C_TRANSMIT_MODE);
  I2C_initMaster(EUSCI_B1_MODULE, &i2cConfig);
  I2C_masterSendMultiByteStart(EUSCI_B1_MODULE, 0x10); // it stops here, but bypasses this if with timeout.
  I2C_masterSendMultiByteFinish(EUSCI_B1_MODULE, 0x11);
//  Wire.begin();
  //Wire.setModule(3);
 // Wire.beginTransmission(addr);
 // Wire.write(0x10);
 // Wire.write(0x11);
  I2C_setMode(EUSCI_B1_MODULE, EUSCI_B_I2C_RECEIVE_MODE);
  
}

void Wireloop()
{
  // put your main code here, to run repeatedly:
//  Wire.requestFrom(addr,2);
//  while(Wire.available()){
//     x = Wire.read() << 8;
//     x |= Wire.read();
//  }
  I2C_masterReceiveStart(EUSCI_B1_MODULE);
  x = I2C_masterReceiveMultiByteNext(EUSCI_B1_MODULE) << 8;
  x |= I2C_masterReceiveMultiByteNext(EUSCI_B1_MODULE);
  I2C_masterReceiveMultiByteFinish(EUSCI_B1_MODULE);
  
  z = x/1.2;
  Serial.print("Light Intensity is ");
  Serial.println(z,3);
  delay(1000);
}

Good Day,

Leo

  • You might get better results asking in an Energia forum.

    Robert
  • Along w/a more "focused" forum - might you, "Speed, Ease & Enhance" your understanding & confidence w/I2C by starting w/a far more "standard" - and vastly simpler - I2C device?

    Small (low capacity, 8 pin) I2C memories are plentiful - far more documented than your (obscure) chosen device - and substantially easier to, "get working."  

    As always - climbing a TALL mountain is eased by (first) climbing a small one.   (except for here - where such reality rarely dawns...)

  • Hi Mr. cb1_mobile,

    With all due respect, I'm just a new comer on this Energia and TI Microcontrollers.
    I have this device working already before on Arduino. I just don't know how to code it on CCS or Energia.
    In this IDE(CCS and Energia), i'm still exploring how to do it. Like how to initialize, how to send and how to write.
    Because on some forums also they claim that there are some bugs on the examples itself on MSPware I2C Examples.
    And I find it also not so easy to understand.

    Interfacing I2C Hardware to me is not a new thing, the new variable is to try coding it on these softwares.
    I do not find your comment encouraging to learn, I expect something like a link that will show some literature to be read, not criticism. I do not find it rational for an expert to scold a new comer that is somewhat lost in a new website looking for answers as a welcome. I just posted on the wrong forum. I'm not here also to argue. I'm here to learn from somebody who is knowledgeable and with patience in sharing ideas.
    Thanks for your friendly advice.

    Leo
  • I'm sorry that you do not find my (oft expressed) recommendation to employ "KISS" encouraging.   I can tell you that many, many do - and have benefitted greatly from such advice. 

    Your writing gave "NO clue" that you had prior I2C experience - we "helpers" can only operate with what's presented.  

    You may note that the recommendation to, "employ a small, simpler I2C memory" is exactly what's "SOP" @ my small tech firm - and has (long) proven the fastest & easiest method to meet bigger challenges - downstream.  

    Your expectation of a "link" - especially w/so rare & unusual a device - may not meet your definition of "encouraging."  

    I believe any fair "re-read" will reveal my post to be not (quite) as bad as you've implied...   I continue to "root for your success" & believe my methods "encourage" it...