Hi All,
Am trying to read the 16-bit register value from the opt3001 ALS sensor from the code posted below. Am getting the MSB 8-bit
data properly but LSB value always 0xFF. Can anyone help me out in this issue weather am i reading register value properly?
void opt3001_read(void) { // create an instance of MsgObj named msg uint8_t als_register_read[2] = {0x00,0x00}; int lux; while(1){ I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false); I2CMasterDataPut(I2C6_BASE, 0x00); I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_START); while(I2CMasterBusy(I2C6_BASE)); I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true);// true indicates that master is initiating the receive. I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); while(I2CMasterBusy(I2C6_BASE)); als_register_read[0] = I2CMasterDataGet(I2C6_BASE) ; //Receives a byte that has been sent to the I2C Master I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); while(I2CMasterBusy(I2C6_BASE)); als_register_read[1] = I2CMasterDataGet(I2C6_BASE); lux = 0x0FFF & (uint16_t)als_register_read[0] << 8 | (uint16_t)als_register_read[1]; int8_t exp = als_register_read[0]>> 4; //exponent is top four bits lux = 0.01 * pow(2,exp) * lux; } }