uint16_t ReadI2CRegister(uint8_t i2cAdress, uint8_t registerName) { uint8_t read[2]; // read content (2x8 bit) of selected register I2CMasterSlaveAddrSet(I2C0_BASE, 0x44, true); // receive the data back (first byte) I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); SysCtlDelay(500); // wait 500 while(I2CMasterBusy(I2C0_BASE)) { while(1) { SysCtlDelay(ui32SysClock / (3*10)); // Wait 100ms for LED to be recognized GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x00); // switch off LEDs // polling the register 1, wait for bit 7 to be set, then move on and data register (0) while(1) // exit with break { SysCtlDelay(ui32SysClock / (3*10)); // wait 200ms // Set register address to config register (single send) I2CMasterSlaveAddrSet(I2C0_BASE, 0x44, false); I2CMasterDataPut(I2C0_BASE, 0x01); // configurate register I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND); SysCtlDelay(500); // wait 500 SysCtlDelay(100000); // Read content (2x8 bit) of selected register I2CMasterSlaveAddrSet(I2C0_BASE, 0x44, true); // receive the data back (first byte) I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); SysCtlDelay(500); // wait 500 /*buffer[0] = I2CMasterDataGet(I2C0_BASE); // read out first data byte*/ // last data byte I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); SysCtlDelay(500); // wait 500 while(I2CMasterBusy(I2C0_BASE)){} // check if I2C is still busy //buffer[1] = I2CMasterDataGet(I2C0_BASE); // read out second data byte /*if ( buffer[1] & 0b10000000) // check if bit 7 has been set { break; }*/ } } } // bit 7 is set I2CMasterSlaveAddrSet(I2C0_BASE, 0x44, false); I2CMasterDataPut(I2C0_BASE, 0x00); // result register I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND); SysCtlDelay(500); // wait 500 while (I2CMasterBusy(I2C0_BASE)) {} // check if I2C is still busy SysCtlDelay(100000); // wait >20ms before read I2CMasterSlaveAddrSet(I2C0_BASE, 0x44, true); // Read content (2x8bit) of selected register I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); // Receive the first data back (first byte) SysCtlDelay(500); while (I2CMasterBusy(I2C0_BASE)) {} /*buffer[0] = I2CMasterDataGet(I2C0_BASE); // Read out first data byte */ I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); SysCtlDelay(500); // wait 500 while (I2CMasterBusy(I2C0_BASE)) {} // check if I2C is still busy //buffer[1] = I2CMasterDataGet(I2C0_BASE); // Read out second data byte GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x1); // Combine 2x8 bit data into 16 bit value /*ui16Result = buffer[0]; ui16Result <<=8; ui16result |= buffer[1]; ui16Exponent = (ui16Result >> 12) & 0x000F; ui16Result = ui16Result & 0x0FFF; // convert raw readings to LUX switch(ui16Exponent) { case 0: ui16Result = ui16Result>>6; break; case 1: ui16Result = ui16Result>>5; break; case 2: ui16Result = ui16Result>>4; break; case 3: ui16Result = ui16Result>>3; break; case 4: ui16Result = ui16Result>>2; break; case 5: ui16Result = ui16Result>>1; break; case 6: ui16Result = ui16Result; break; case 7: ui16Result = ui16Result<<1; break; case 8: ui16Result = ui16Result<<2; break; case 9: ui16Result = ui16Result<<3; break; case 10: ui16Result = ui16Result<<4; break; case 11: ui16Result = ui16Result<<5; break; } */ }