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 can I use the other I2C Channel of MSP432 Launchpad?

Other Parts Discussed in Thread: ENERGIA, MSPWARE

Hi,

Just want to ask if there is a way to use other channels of I2C for the MSP432.

I plan to read multiple BH1750FVI Light Sensor without and I2C multiplexer.

Below is my code and can't get the expected results using the driverlib functions.

    #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 400khz
        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);
 delay(1000);
  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);
  I2C_masterSendMultiByteFinish(EUSCI_B1_MODULE, 0x11);

//  Wire.begin();

//  Wire.beginTransmission(addr);      Initialization of Sensor Resolution
//  Wire.write(0x10);                               "Working"
//  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);    Working Code using Wire library
//  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 = (float)x/1.2;
  Serial.print("Light Intensity is ");
  Serial.println(z,3);
  delay(1000);
}

Good Day,

Leo

  • Leo,
    Are you using Energia or CCS?

    Have you tried following our code examples for i2c? That would be a better first step, and then modify it for B1.

    Does this code work with EUSCI_B0?
  • Hi Leo!

    Leo Pestanas said:
    I plan to read multiple BH1750FVI Light Sensor

    You can use two of those sensors on one I²C bus. A high level at the ADDR pin selects 1011100 and a low level 0100011 as device address. I don't know what multiple means in your case, but if it was 2, then you're done.

    Dennis

  • Hi Mr. Cameron,

    Sorry to reply late. I just arrived from a business trip.
    I'm using Energia and tried to use the "i2c.h" which I saw it can set/disable channels of I2c.
    By default without changing anything, the "Wire Library" points to P6.5 and P6.4 of MSP432 which is EUSCI_B1.
    The code indicated does not work, in "Wire library" it works fine.
    I want to know where it did go wrong. I followed the comments on the "i2c.h" and "i2c.cpp" on the Energia folder.

    Best Regards,
    Leo
  • Hi Mr. Dennis,

    Yes, it can be (2) of this light sensor on the same bus.

    But I want to utilize the Multitasking properties of MSP432,

    by putting the other sensor network on the other sketch with the same code.

    If I were to poll this along the I2C multiplexer like the PCA9545, there can be a slight delay in processing since I need to switch from one channel to another.

    Given that I'm required to catch the flash of camera strobe light in different location in a fast manner.

    Sketch 1 is for controls, Sketch 2 is for I2C LCD Display, Sketch 3 is the Light Sensors1(2addresses) Readout, Sketch 4 is the Light Sensors2(2addresses).

    Best Regards,

    Leo

  • Leo,
    Sorry for the delay. What result are you getting? Are you seeing any communications?

    Best regards,
    Cameron
  • Hi Mr. Cameron,

    I plan to continue this on Saturday,
    As you viewed my code, do you find something wrong why it does not work on Energia?
    These are the instructions inside the "I2C.h" of Energia and have some brief description of how the I2C was performed.
    Like if it is doing the start, data and end in the I2C transaction.
    I will try to capture the waveforms on that day and forward to this thread. Thanks.

    Best Regards,
    Leo
  • Leo,
    The current release of Energia does not support multiple instances of Wire. Also, Wire only supports EUSCI_B1. This is why you are having problems. 

  • Good Morning,

    So this is clear that in Energia it is not possible to MSP432 then.
    Because there is a book where the TivaC microcontroller is able to use the other channels of I2C,
    by invoking the "Wire.setModule(x)", x pertains to the defined I2C ports. And it is done on older version of Energia.
    But in CCS this is possible to have multiple I2C channels enabled?
    Can you give me a link where I can see a basic code snippet of doing I2C transaction from scratch?
    Like single byte write, multiple byte write, repeated start(reading and writing), single byte read and multiple byte read.
    I find the example on MSPWare difficult to understand for people like me and still trying to learn CCS coding.
    Hope you can extend your patience asking some questions that looks basic to experts like you.
    Thanks for the usual support.

    Best Regards,
    Leo
  • Leo,
    The examples in MSPWare would be the best place to start. Maybe I can help here, what parts of the example do you not understand?

    Best regards,
    Cameron

**Attention** This is a public forum