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