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